Send a Slack block message formatted in previous step
@dylburger
code:
data:privatelast updated:4 years ago
today
Build integrations remarkably fast!
You're viewing a public workflow template.
Sign up to customize, add steps, modify code and more.
Join 1,000,000+ developers using the Pipedream platform
steps.
trigger
HTTP API
Deploy to generate unique URL
This workflow runs on Pipedream's servers and is triggered by HTTP / Webhook requests.
steps.
format_block_message
auth
to use OAuth tokens and API keys in code via theauths object
(auths.slack)
code
Write any Node.jscodeand use anynpm package. You can alsoexport datafor use in later steps via return or this.key = 'value', pass input data to your code viaparams, and maintain state across executions with$checkpoint.
async (event, steps, auths) => {
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
}
16
// Slack expects a URL-encoded string representing the block message
// you'd like to send. See the docs for more formatting options:
// https://api.slack.com/reference/block-kit/block-elements#button
// Slack also has a playground for formatting new block messages:
// https://app.slack.com/block-kit-builder
this.blockMessage = [
	{
		"type": "section",
		"text": {
			"type": "plain_text",
			"text": `Hello, world`
		}
	}
]
steps.
send_a_message
auth
to use OAuth tokens and API keys in code via theauths object
(auths.slack)
params
Channel

Channel, private group, or IM channel to send message to. Can be an encoded ID, or a name. See below for more details.

 
C1234567890
string ·params.channel
Blocks

A JSON-based array of structured blocks, presented as a URL-encoded string.

{{steps.format_block_message.blockMessage}}
string ·params.blocks
Optional
code
Write any Node.jscodeand use anynpm package. You can alsoexport datafor use in later steps via return or this.key = 'value', pass input data to your code viaparams, and maintain state across executions with$checkpoint.
async (event, steps, params, auths) => {
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
}
26
const { WebClient } = require('@slack/web-api')

try {
  const web = new WebClient(auths.slack.oauth_access_token)
  this.response = await web.chat.postMessage({
    attachments: params.attachments,
    unfurl_links: params.unfurl_links,
    unfurl_media: params.unfurl_media,
    parse: params.parse || 'full',
    as_user: params.as_user || false,
    mrkdwn: params.mrkdwn || true,
    channel: params.channel,
    username: params.username,
    blocks: params.blocks,
    icon_emoji: params.icon_emoji,
    link_names: params.link_names,
    reply_broadcast: params.reply_broadcast || false,
    thread_ts: params.thread_ts,
    icon_url: params.icon_url,
  })
} catch (err) {
  this.error = err
  throw err
}