SlackContext

Chat API

postMessage(message [, options]) - Official docs

Alias: sendText.

Sends a message to the channel.

Param Type Description
message String | Object The message to be sent, can be text message or attachment message.
options Object Other optional parameters.

Example:

context.postMessage({ text: 'Hello!' });
context.postMessage({ attachments: [someAttachments] });
context.postMessage('Hello!');
context.postMessage('Hello!', { as_user: true });

If you send message with attachments, messaging-api-slack will automatically stringify the attachments field for you.

context.postMessage(
  {
    text: 'Hello!',
    attachments: [
      {
        text: 'Choose a game to play',
        fallback: 'You are unable to choose a game',
        callback_id: 'wopr_game',
        color: '#3AA3E3',
        attachment_type: 'default',
        actions: [
          {
            name: 'game',
            text: 'Chess',
            type: 'button',
            value: 'chess',
          },
        ],
      },
    ],
  },
  {
    as_user: true,
  }
);

postEphemeral(message [, options]) - Official docs

Sends an ephemeral message to the user.

Param Type Description
message String | Object The message to be sent, can be text message or attachment message.
options Object Other optional parameters.

Example:

context.postEphemeral({ text: 'Hello!' });
context.postEphemeral({ attachments: [someAttachments] });
context.postEphemeral('Hello!');
context.postEphemeral('Hello!', { as_user: true });