How Can Other Components Access the Events in My Workflow When Using a Custom Source?

This topic was automatically generated from Slack. You can find the original thread here.

i created a custom source using the following code :
import { axios } from “@pipedream/platform”;

export default {
name: “Source Demo”,
description: “This is a demo source”,
props: {
github: {
type: “app”,
app: “github”,
},
timer: {
type: “$.interface.timer”,
default: {
intervalSeconds: 15 * 60,
},
},
},
dedupe: “greatest”,
async run() {
const data = await axios(this, {
method: “get”,
headers: {
Authorization: Bearer ${this.github.$auth.oauth_access_token},
},
url: https://api.github.com/repos/pddemo/demo/issues,
});
data.forEach((issue) => {
this.$emit(issue, {
id: issue.id,
summary: ISSUE ${issue.number}: ${issue.title},
ts: issue.created_at && +new Date(issue.created_at),
});
});
},
};

so when i use this in my workflow, how can my other components access the events

In your workflow, after the custom source you’ve created emits events, other components can access the data from these events using the steps object. Each step in a Pipedream workflow is given a name, and the data emitted by a step is accessible to subsequent steps under this name. For example, if your custom source is named custom_source, and it emits issues from a GitHub repository, you can access the data in the next step like so: const issues = steps.custom_source.$return_value; Each issue emitted by your source will be an element in the issues array. You can then iterate over these issues or access specific data from each issue as needed in your subsequent components. Remember, the name custom_source is just an example. You’ll use the actual name of the step as it appears in your workflow. This name is defined when you add the step to your workflow in the Pipedream UI.

in this code, will all props from the issues object be accessible to next steps, or will be limited to id, summary and ts

how will I access issue.title and issue.body in next step with the above code as custom source?

To access issue.title and issue.body in the next step of your Pipedream workflow using the custom source code provided, you would typically use the steps object to reference the output of the previous step where your custom source code runs. However, since the specific code of the custom source wasn’t provided in your question, I’ll outline a general approach on how to do this based on the standard structure of a Pipedream component. Assuming your custom source code correctly extracts and returns issue.title and issue.body as part of its output, you can access these values in the next step of your workflow like this: const issueTitle = steps.previousStepName.outputs.issue.title; const issueBody = steps.previousStepName.outputs.issue.body; In this example, previousStepName should be replaced with the actual name of the step that runs your custom source code. In Pipedream’s workflow editor, each step has a name, which you can use to reference its outputs. If you need to ensure that your custom source code returns issue.title and issue.body correctly, your component’s run method should look something like this: async run({steps, $}) { // Your code to fetch the issue details // For demonstration, let's assume you have the issue details in a variable named `issue` const issue = { title: "Example Issue Title", body: "Example issue body text", }; // Return the issue details return { issue: issue, // This object will contain issue.title and issue.body }; } In this simplified example, the issue object is hardcoded for demonstration purposes. In your actual component, you would replace this with the logic necessary to fetch or receive the issue details dynamically. Remember, the key is that the data you want to access in subsequent steps must be returned from the run method of your component. Once you’ve done that, you can reference the data in the next steps using the steps object as shown above.

how will I access issue.title and issue.body in next step int he following code as custom source?:
import { axios } from “@pipedream/platform”;

export default {
name: “Source Demo”,
description: “This is a demo source”,
props: {
github: {
type: “app”,
app: “github”,
},
timer: {
type: “$.interface.timer”,
default: {
intervalSeconds: 15 * 60,
},
},
},
dedupe: “greatest”,
async run() {
const data = await axios(this, {
method: “get”,
headers: {
Authorization: Bearer ${this.github.$auth.oauth_access_token},
},
url: https://api.github.com/repos/pddemo/demo/issues,
});
data.forEach((issue) => {
this.$emit(issue, {
id: issue.id,
summary: ISSUE ${issue.number}: ${issue.title},
ts: issue.created_at && +new Date(issue.created_at),
});
});
},
};

To access issue.title and issue.body in the next step of your Pipedream workflow after using the custom source you provided, you will utilize the outputs of this source step. When you emit data using this.$emit, the data becomes available to subsequent steps in your workflow. In your code, you’re emitting each issue with its details, including the summary which is constructed from issue.number and issue.title. However, to directly access issue.title and issue.body in the next step, you should include these explicitly in the data you emit if you need issue.body specifically, as it’s not currently included in your $emit call. Here’s how you can modify your $emit call to include issue.title and issue.body: data.forEach((issue) => { this.$emit(issue, { id: issue.id, title: issue.title, // Include issue title body: issue.body, // Include issue body summary: `ISSUE ${issue.number}: ${issue.title}`, ts: issue.created_at && +new Date(issue.created_at), }); }); In the next step of your workflow, you can access these values using the steps object, assuming the name of your source step is source_step. Here’s an example of how to access issue.title and issue.body in a Node.js code step: const issues = steps.source_step.$return_value; // Replace 'source_step' with your actual step name issues.forEach(issue => { console.log(issue.title); // Accessing issue title console.log(issue.body); // Accessing issue body }); Remember, the exact way to access these values depends on how you structure your workflow and the names of your steps. Adjust source_step to match the name of your custom source step in the Pipedream UI.

how will I access issue.title and issue.body in next step int he following code as custom source?:

import { axios } from “@pipedream/platform”;

export default {
name: “Source Demo”,
description: “This is a demo source”,
props: {
github: {
type: “app”,
app: “github”,
},
timer: {
type: “$.interface.timer”,
default: {
intervalSeconds: 15 * 60,
},
},
},
dedupe: “greatest”,
async run() {
const data = await axios(this, {
method: “get”,
headers: {
Authorization: Bearer ${this.github.$auth.oauth_access_token},
},
url: https://api.github.com/repos/pddemo/demo/issues,
});
data.forEach((issue) => {
this.$emit(issue);
});
});
},
};

To access issue.title and issue.body in the next step of your Pipedream workflow after using the custom source you’ve provided, you will use the steps object. Each step in a Pipedream workflow is accessible via the steps object in subsequent steps, using the name of the step as the key. Since your custom source emits each issue as an event, you can access these events in the next step. However, your code snippet does not assign a specific name to the step that emits the issues. In Pipedream’s workflow builder, each step can be named manually for easier reference. Assuming you name your custom source step as fetch_issues, here’s how you would access issue.title and issue.body in the next step: // This is a Node.js code step that follows the custom source step named `fetch_issues` const issues = steps.fetch_issues.$return_value; issues.forEach(issue => { console.log(issue.title, issue.body); }); In this example, steps.fetch_issues.$return_value refers to the array of issues emitted by your custom source. Since your source emits each issue individually, you might need to adjust how you accumulate these issues in your workflow, depending on your exact requirements. Remember, the name fetch_issues is just an example. You should replace it with the actual name you’ve given to your custom source step in the Pipedream workflow UI.