Skip to content

[Components] slack #8858

Open
Open
@pipedream-component-development

Description

slack

URLs

Actions

send-approval-request

Prompt

Using Pipedream's $.flow.suspend function, I want to send a Slack message with 2 buttons for the resume_url and cancel_url, respectively. I want to send the buttons as block elements, and they should be appended to end of whatever text or blocks the user inputs in addition.

Below is some starter code, but I want you to reference the existing common files and slack.app.mjs file, to reuse existing props and methods.

So the user should define the text, blocks, channel, etc, then we will append the below blocks automatically onto their message. There is a similar method in send-message.mjs.

import { axios } from "@pipedream/platform"
export default defineComponent({
  props: {
    slack: {
      type: "app",
      app: "slack",
    },
    resumeExecutionButtonText: {
      type: "string",
      label: "Appoval Button Text",
      description: "Text to display on the approval button",
      default: "Yes",
    },
    cancelExecutionButtonText: {
      type: "string",
      label: "Cancelation Button Text",
      description: "Text to display on the cancelation button",
      default: "No",
    },
    approvalRequestTimeout: {
      type: "integer",
      label: "Approval Request Timeout",
      description: "Time in minutes to wait for approval. After the request times out, workflow execution will cancel.",
      default: 60,
      optional: true,
    },
  },
  async run({steps, $}) {
    const timeout = 1000 * 60 * 24
    const { resume_url, cancel_url } = $.flow.suspend(timeout)
    
    const blocks = [
      {
        "type": "actions",
        "elements": [
          {
            "type": "button",
            "text": {
              "type": "plain_text",
              "text": this.resumeExecutionButtonText,
              "emoji": true,
            },
            "url": resume_url,
            "action_id": `${process.env.PIPEDREAM_WORKFLOW_ID}-resume-execution`,
            "style": "primary",
          },
          {
            "type": "button",
            "text": {
              "type": "plain_text",
              "text": this.cancelExecutionButtonText,
              "emoji": true,
            },
            "url": cancel_url,
            "action_id": `${process.env.PIPEDREAM_WORKFLOW_ID}-cancel-execution`,
            "style": "danger",
          },
        ],
      }
    ]

    return await axios($, {
      url: `https://slack.com/api/chat.postMessage`,
      headers: {
        Authorization: `Bearer ${this.slack.$auth.oauth_access_token}`,
      },
      method: 'post',
      data: {
        channel: steps.send_block_kit_message.$return_value.channel,
        text: 'Approval message',
        blocks: blocks,
        thread_ts: steps.send_block_kit_message.$return_value.ts,
      }
    })
  },
})

URLs

Metadata

Metadata

Assignees

No one assigned

    Labels

    actionNew Action Requestai-templatetriagedFor maintainers: This issue has been triaged by a Pipedream employee

    Type

    No type

    Projects

    Status

    To Do

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions