Skip to main content
Version: Next

SlackContext

Chat API

postMessage(message [, options]) - Official docs

Alias: sendText.

Sends a message to the channel.

ParamTypeDescription
messageString | ObjectThe message to be sent, can be text message or attachment message.
optionsObjectOther optional parameters.

Example:

context.postMessage({ text: 'Hello!' });
context.postMessage({ attachments: [someAttachments] });
context.postMessage('Hello!');
context.postMessage('Hello!', { asUser: 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',
callbackId: 'wopr_game',
color: '#3AA3E3',
attachmentType: 'default',
actions: [
{
name: 'game',
text: 'Chess',
type: 'button',
value: 'chess',
},
],
},
],
},
{
asUser: true,
}
);

postEphemeral(message [, options]) - Official docs

Sends an ephemeral message to the user.

ParamTypeDescription
messageString | ObjectThe message to be sent, can be text message or attachment message.
optionsObjectOther optional parameters.

Example:

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