@U05A7KLNALC the following code , modify it ot get posts from a particular subreddit:
the following code :
import { axios } from “@pipedream/platform”;
export default defineComponent({
name: “velora-github-issues-source-GET”,
description:
“This is a custom source for Velora AI, which fetches user credentials from an external source, and then uses the GET API to fetch GitHub issues for a user repo, with 15-minute timer intervals.”,
props: {
github: {
type: “app”,
app: “github”,
},
timer: {
type: “$.interface.timer”,
default: {
intervalSeconds: 15 * 60,
},
},
repo_full_name: {
type: “string”,
label: “Repository Full Name”,
description:
“Enter the name of the GitHub repository in the format ‘owner/repo’”,
},
nango_connection_id: {
type: “string”,
label: “Nango Connection ID”,
description: “Enter the Nango Connection ID”,
},
nango_integration_id: {
type: “string”,
label: “Nango Integration ID”,
description: “Enter the Nango Integration ID”,
},
workflow_id: {
type: “string”,
label: “Workspace ID”,
description: “Enter the Workspace ID”,
},
},
dedupe: “greatest”,
async run({ steps, $ }) {
try {
// Step 1: Retrieve the GitHub token from Nango
const nangoResponse = await axios($, {
method: “GET”,
headers: {
Authorization: Bearer ${process.env.VELORA_NANGO_SECRET_KEY}
,
},
url: https://api.nango.dev/connection/${this.nango_connection_id}?provider_config_key=${this.nango_integration_id}
,
});
// Extract the GitHub access token from the response
const github_token = nangoResponse.credentials.access_token;
// Step 2: Use the GitHub token to make a request to the GitHub API
const data = await axios($, {
method: "get",
headers: {
Authorization: `Bearer ${github_token}`,
},
url: `https://api.github.com/repos/${this.repo_full_name}/issues`,
});
// Step 3: Emit each issue as an event
data.forEach((issue) => {
this.$emit(issue, {
id: issue.id,
summary: `ISSUE ${issue.number}: ${issue.title}`,
body: issue.body,
ts: issue.created_at && +new Date(issue.created_at),
workflow_id: this.workflow_id,
});
});
} catch (error) {
// Handle errors gracefully
$.error(`Failed to fetch issues: ${error.message}`);
}
},
})