This topic was automatically generated from Slack. You can find the original thread here.
in the following code add another prop for workspace id and emit it too:
import { axios } from “@pipedream/platform”;
export default defineComponent({
name: “velora-github-team-discussions-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 team discussions, with 15-minute timer intervals.”,
props: {
github: {
type: “app”,
app: “github”,
},
timer: {
type: “$.interface.timer”,
default: {
intervalSeconds: 15 * 60,
},
},
org: {
type: “string”,
label: “Organization Name”,
description: “Enter the name of the GitHub organization.”,
},
team_slug: {
type: “string”,
label: “Team Slug”,
description: “Enter the slug of the GitHub team.”,
},
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”,
},
},
dedupe: “greatest”,
async run({ steps, $ }) {
try {
// 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}
,
});
const github_token = nangoResponse.credentials.access_token;
// Use the GitHub token to make a request to the GitHub API for team discussions
const data = await axios($, {
method: "get",
headers: {
Authorization: `Bearer ${github_token}`,
accept: "application/vnd.github+json",
},
url: `https://api.github.com/orgs/${this.org}/teams/${this.team_slug}/discussions`,
params: {
per_page: 100, // Adjust this value as needed
page: 1, // Adjust this value as needed
},
});
data.forEach((discussion) => {
this.$emit(discussion, {
id: discussion.id,
summary: `DISCUSSION ${discussion.number}: ${discussion.title}`,
body: discussion.body,
ts: discussion.created_at && +new Date(discussion.created_at),
});
});
} catch (error) {
// Handle errors gracefully
$.error(`Failed to fetch discussions: ${error.message}`);
}
},
});