From a9fe8d18fbc358ada947bbc43acce40d8e1aba99 Mon Sep 17 00:00:00 2001 From: pdgit Date: Tue, 31 Mar 2026 23:45:36 +0000 Subject: [PATCH] initial commit --- README.md | 1 + expenses-pipeline-p_13CN51K/.workflow.state | 5 ++ .../fetch_message/entry.js | 31 ++++++++++++ .../get_permalink/entry.js | 26 ++++++++++ .../post_to_next_channel/entry.js | 47 +++++++++++++++++++ .../reply_on_original/entry.js | 27 +++++++++++ .../route_check/entry.js | 32 +++++++++++++ expenses-pipeline-p_13CN51K/workflow.yaml | 35 ++++++++++++++ 8 files changed, 204 insertions(+) create mode 100644 README.md create mode 100644 expenses-pipeline-p_13CN51K/.workflow.state create mode 100644 expenses-pipeline-p_13CN51K/fetch_message/entry.js create mode 100644 expenses-pipeline-p_13CN51K/get_permalink/entry.js create mode 100644 expenses-pipeline-p_13CN51K/post_to_next_channel/entry.js create mode 100644 expenses-pipeline-p_13CN51K/reply_on_original/entry.js create mode 100644 expenses-pipeline-p_13CN51K/route_check/entry.js create mode 100644 expenses-pipeline-p_13CN51K/workflow.yaml diff --git a/README.md b/README.md new file mode 100644 index 0000000..9b499e4 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +Project repo_7kT73R diff --git a/expenses-pipeline-p_13CN51K/.workflow.state b/expenses-pipeline-p_13CN51K/.workflow.state new file mode 100644 index 0000000..ba693a3 --- /dev/null +++ b/expenses-pipeline-p_13CN51K/.workflow.state @@ -0,0 +1,5 @@ +# DO NOT EDIT THIS FILE +--- +schema: workflow.state/2022.04 +id: p_13CN51K + diff --git a/expenses-pipeline-p_13CN51K/fetch_message/entry.js b/expenses-pipeline-p_13CN51K/fetch_message/entry.js new file mode 100644 index 0000000..ff7c897 --- /dev/null +++ b/expenses-pipeline-p_13CN51K/fetch_message/entry.js @@ -0,0 +1,31 @@ +import { axios } from "@pipedream/platform"; +export default defineComponent({ + props: { + slack: { + type: "app", + app: "slack_bot", + } + }, + async run({ steps, $ }) { + console.log("Auth:", JSON.stringify(this.slack.$auth)); // ← moved here + + const response = await axios($, { + method: "GET", + url: "https://slack.com/api/conversations.history", + headers: { + Authorization: `Bearer ${this.slack.$auth.bot_token}`, + }, + params: { + channel: steps.route_check.$return_value.fromChannel, + latest: steps.route_check.$return_value.messageTs, + limit: 1, + inclusive: true, + }, + }); + console.log("Response:", JSON.stringify(response)); + if (!response.ok) throw new Error(response.error); + return { + text: response.messages[0].text, + }; + } +}); \ No newline at end of file diff --git a/expenses-pipeline-p_13CN51K/get_permalink/entry.js b/expenses-pipeline-p_13CN51K/get_permalink/entry.js new file mode 100644 index 0000000..ec53a6d --- /dev/null +++ b/expenses-pipeline-p_13CN51K/get_permalink/entry.js @@ -0,0 +1,26 @@ +import { axios } from "@pipedream/platform"; +export default defineComponent({ + props: { + slack: { + type: "app", + app: "slack_bot", + } + }, + async run({ steps, $ }) { + const response = await axios($, { + method: "GET", + url: "https://slack.com/api/chat.getPermalink", + headers: { + Authorization: `Bearer ${this.slack.$auth.bot_token}`, + }, + params: { + channel: steps.route_check.$return_value.fromChannel, + message_ts: steps.route_check.$return_value.messageTs, + }, + }); + if (!response.ok) throw new Error(response.error); + return { + permalink: response.permalink, + }; + } +}); \ No newline at end of file diff --git a/expenses-pipeline-p_13CN51K/post_to_next_channel/entry.js b/expenses-pipeline-p_13CN51K/post_to_next_channel/entry.js new file mode 100644 index 0000000..994c05f --- /dev/null +++ b/expenses-pipeline-p_13CN51K/post_to_next_channel/entry.js @@ -0,0 +1,47 @@ +import { axios } from "@pipedream/platform"; +export default defineComponent({ + props: { + slack: { + type: "app", + app: "slack_bot", + } + }, + async run({ steps, $ }) { + const { toChannel, label } = steps.route_check.$return_value; + const { permalink } = steps.get_permalink.$return_value; + // Strip old React instruction from copied text + let text = steps.fetch_message.$return_value.text; + text = text.replace(/_React_ :white_check_mark: _to advance to \w+_/g, '').trim(); + // Determine next stage label for the React instruction + const nextStageMap = { + 'C0APLSGABAB': 'Authorized', + 'C0AQ09CDJH4': 'Matched', + 'C0APYUM1JFP': null, // Final stage — no next instruction + }; + const nextLabel = nextStageMap[toChannel]; + const reactLine = nextLabel + ? `\n\n_React_ :white_check_mark: _to advance to ${nextLabel}_` + : ''; + const permalinkLine = toChannel === 'C0APLSGABAB' + ? `\n\nšŸ“Ž *Original Submission:* <${permalink}|View Original Message>` + : ''; + const fullText = `${text}${permalinkLine}${reactLine}`; + const response = await axios($, { + method: "POST", + url: "https://slack.com/api/chat.postMessage", + headers: { + Authorization: `Bearer ${this.slack.$auth.bot_token}`, + "Content-Type": "application/json", + }, + data: { + channel: toChannel, + text: fullText, + mrkdwn: true, + unfurl_links: false, + unfurl_media: false, + }, + }); + if (!response.ok) throw new Error(response.error); + return { messageTs: response.ts }; + } +}); \ No newline at end of file diff --git a/expenses-pipeline-p_13CN51K/reply_on_original/entry.js b/expenses-pipeline-p_13CN51K/reply_on_original/entry.js new file mode 100644 index 0000000..f37964d --- /dev/null +++ b/expenses-pipeline-p_13CN51K/reply_on_original/entry.js @@ -0,0 +1,27 @@ +import { axios } from "@pipedream/platform"; +export default defineComponent({ + props: { + slack: { + type: "app", + app: "slack_bot", + } + }, + async run({ steps, $ }) { + const { fromChannel, messageTs, label } = steps.route_check.$return_value; + const response = await axios($, { + method: "POST", + url: "https://slack.com/api/chat.postMessage", + headers: { + Authorization: `Bearer ${this.slack.$auth.bot_token}`, + "Content-Type": "application/json", + }, + data: { + channel: fromChannel, + thread_ts: messageTs, + text: `āž”ļø Advanced to ${label}`, + }, + }); + if (!response.ok) throw new Error(response.error); + return { success: true }; + } +}); \ No newline at end of file diff --git a/expenses-pipeline-p_13CN51K/route_check/entry.js b/expenses-pipeline-p_13CN51K/route_check/entry.js new file mode 100644 index 0000000..bbbd99c --- /dev/null +++ b/expenses-pipeline-p_13CN51K/route_check/entry.js @@ -0,0 +1,32 @@ +export default defineComponent({ + async run({ steps }) { + const reaction = steps.trigger.event.reaction; + const fromChannel = steps.trigger.event.item.channel; + const messageTs = steps.trigger.event.item.ts; + + // Only proceed for āœ… reactions + if (reaction !== 'white_check_mark') { + return $end('Not a white_check_mark reaction — skipping'); + } + + // Map source channel to destination channel and label + const channelMap = { + 'C0AQ2AWLNEN': { next: 'C0APLSGABAB', label: 'Processed' }, + 'C0APLSGABAB': { next: 'C0AQ09CDJH4', label: 'Authorized' }, + 'C0AQ09CDJH4': { next: 'C0APYUM1JFP', label: 'Matched' }, + }; + + const route = channelMap[fromChannel]; + + if (!route) { + return $end('Reaction not in an expense channel — skipping'); + } + + return { + fromChannel, + toChannel: route.next, + label: route.label, + messageTs, + }; + } +}); \ No newline at end of file diff --git a/expenses-pipeline-p_13CN51K/workflow.yaml b/expenses-pipeline-p_13CN51K/workflow.yaml new file mode 100644 index 0000000..634c5a6 --- /dev/null +++ b/expenses-pipeline-p_13CN51K/workflow.yaml @@ -0,0 +1,35 @@ +schema: workflow/2022.04 +name: Expenses Pipeline +settings: + error_notification: true +triggers: +- id: dc_DvudRW4 +steps: +- namespace: route_check + runtime: nodejs20.x + uses: "./route_check/entry.js" +- namespace: fetch_message + runtime: nodejs20.x + uses: "./fetch_message/entry.js" + props: + slack: + authProvisionId: apn_86hW0ZZ +- namespace: get_permalink + runtime: nodejs20.x + uses: "./get_permalink/entry.js" + props: + slack: + authProvisionId: apn_86hW0ZZ +- namespace: post_to_next_channel + runtime: nodejs20.x + uses: "./post_to_next_channel/entry.js" + props: + slack: + authProvisionId: apn_86hW0ZZ +- namespace: reply_on_original + runtime: nodejs20.x + uses: "./reply_on_original/entry.js" + props: + slack: + authProvisionId: apn_86hW0ZZ +