This topic was automatically generated from Slack. You can find the original thread here.
is it possible to update a slack message posted by the Pipedream bot within a node step? If so, how?
This topic was automatically generated from Slack. You can find the original thread here.
is it possible to update a slack message posted by the Pipedream bot within a node step? If so, how?
Yes, you can update a Slack message posted by the Pipedream bot within a Node.js step. However, I recommend using the pre-built “Update Message” action in the Pipedream UI. Here’s how: 1. Search for the Slack app from the step menu 2. Select the Update Message action 3. Connect your Slack account 4. Select a Channel or pass a string from a previous step 5. Select a Text or pass a string from a previous step 6. At the bottom of the step, click Test to run the action and test the configuration For more details, visit the documentation at https://pipedream.com/apps/slack/actions/update-message.
How can I do it within node? I need to update a message on a short loop, which I can’t do with the built-in action.
can you answer the question above?
fwiw i think i found what i need in the docs
just need to write and test it a bit later
Apologies for the delay. To update a Slack message within a Node.js step, you can use the Slack API’s chat.update
method. First, you’ll need the ts
(timestamp) of the message you want to update and the channel ID. Here’s an example of how to update a Slack message using the Slack Web API: import { axios } from "@pipedream/platform"; export default defineComponent({ props: { slackBotToken: { type: "string", label: "Slack Bot Token", secret: true, }, channelId: { type: "string", label: "Channel ID", }, messageTs: { type: "string", label: "Message Timestamp", }, updatedText: { type: "string", label: "Updated Message Text", }, }, async run({ $ }) { const url = "https://slack.com/api/chat.update"; const headers = { Authorization: `Bearer ${this.slackBotToken}`, "Content-Type": "application/json", }; const data = { channel: this.channelId, ts: this.messageTs, text: this.updatedText, }; const response = await axios($, { method: "POST", url, headers, data, }); if (!response.ok) { console.error("Error updating Slack message:", response.error); } return response; }, });
Replace the slackBotToken
, channelId
, messageTs
, and updatedText
props with the appropriate values. This code uses the Slack Web API to update the message with the new text.
Btw native looping in the UI is coming soon! You’ll be able to loop over any array and run pre-built actions
please rewrite the code above to use the slack app prop and native auth using this.slack.$auth
Here’s the updated code using the Slack app prop and native auth with this.slack.$auth
: import { axios } from "@pipedream/platform"; export default defineComponent({ props: { slack: { type: "app", app: "slack", }, channelId: { type: "string", label: "Channel ID", }, messageTs: { type: "string", label: "Message Timestamp", }, updatedText: { type: "string", label: "Updated Message Text", }, }, async run({ $ }) { const url = "https://slack.com/api/chat.update"; const headers = { Authorization: `Bearer ${this.slack.$auth.oauth_access_token}`, "Content-Type": "application/json", }; const data = { channel: this.channelId, ts: this.messageTs, text: this.updatedText, }; const response = await axios($, { method: "POST", url, headers, data, }); if (!response.ok) { console.error("Error updating Slack message:", response.error); } return response; }, });
This code uses the Slack app prop and the native auth provided by this.slack.$auth.oauth_access_token
to update the Slack message.
great to know - my case still (probably) wont fall under that, its more so an ongoing progress update for a longer process that runs in a node block
but definitely some other areas that’ll be useful