This is reference content about building functions and workflows. Learn more if you're not yet familiar with this new Slack platform paradigm.

send_message

Send a message

Facts

Schema ID

Schema.slack.functions.SendMessage

Schema reference

slack#/functions/send_message

Related methods

Input parameters

Required parameters
The conversation ID for the channel you are sending the message to
  • C123456
  • D123ABC456
The textual message to send to channel
Optional parameters
Additional metadata about the message, which can then be used an workflow event trigger.
Buttons to send with the message. Must be wrapped in a block. Accepts either button or workflow_button elements only.

Output parameters

Required parameters
An individual instance of the message you sent
The channel-specific unique identifier for this message, also serves as a confirmation that the message was sent.
Permalink URL of the message that was sent
Optional parameters
If interactive_blocks was provided, the action object contains the button properties (see action payload below)
If interactive_blocks is provided as an input parameter, the interactivity context becomes available

Usage guide

Sends a message to a specific channel. The message input only supports non-interactive rich_text.

This function returns a timestamp of the new message, which also serves as a confirmation that the message was sent.

Direct messages
The send_message function does not allow for direct messages to users β€” use the send_dm function instead.

Adding interactivity with buttons

The interactive_blocks input only supports the button and workflow_button interactive blocks.

Ensure that you do not use non-interactive elements via the interactive_blocks input, as this could cause unintended behavior.

If you include a button in the message, the function execution will not continue until a user clicks on that button.

Example

To collect a formatted message from your end users and send it as-is, you can use a form to collect the formatted text, and a Slack function to send it:

import { DefineWorkflow, Schema } from "deno-slack-sdk/mod.ts";

export const RichTextWorkflow = DefineWorkflow({
  callback_id: "rich_text_workflow",
  title: "rich-text input workflow",
  input_parameters: {
    properties: {
      interactivity: { type: Schema.slack.types.interactivity },
      channel: { type: Schema.slack.types.channel_id },
    },
    required: ["interactivity", "channel"],
  },
});

const inputForm = RichTextWorkflow.addStep(
  Schema.slack.functions.OpenForm,
  {
    title: "Send formatted message",
    interactivity: RichTextWorkflow.inputs.interactivity,
    submit_label: "Send formatted message",
    fields: {
      elements: [
        {
          name: "formattedInput",
          title: "Formatted input",
          type: Schema.slack.types.rich_text,
        },
        {
          name: "channel",
          title: "Post in:",
          type: Schema.slack.types.channel_id,
          default: RichTextWorkflow.inputs.channel,
        },
      ],
      required: ["channel", "formattedInput"],
    },
  },
);

RichTextWorkflow.addStep(Schema.slack.functions.SendMessage, {
  channel_id: inputForm.outputs.fields.channel,
  message: inputForm.outputs.fields.formattedInput,
  interactive_blocks: [{
    "type": "actions",
    "elements": [
      {
        "type": "button",
        "text": { "type": "plain_text", "text": "Approve" },
        "style": "primary",
        "value": "approve",
        "action_id": "approve_button",
      },
    ],
  }],
});

Here's an example with just regular text:

import { DefineWorkflow, Schema } from "deno-slack-sdk/mod.ts";

export const createAnnouncement = DefineWorkflow({
  callback_id: "create-announcement",
  title: "Workflow for creating announcements",
  input_parameters: { properties: {}, required: [] },
});

const sendPreview = createAnnouncement.addStep(
  Schema.slack.functions.SendMessage,
  {
    channel_id: "CTLC2K3JS",
    message: "Good to see you here!",
  },
);

Action payload

Example action payload:

{
  "action_id": "WaXA",
  "block_id": "=qXel",
  "text": {
    "type": "plain_text",
    "text": "View",
    "emoji": true
  },
  "value": "click_me_123",
  "type": "button",
  "action_ts": "1548426417.840180"
}