Sample - Slack Web API
POST/chat.postMessage

Send a message to a channel

Sends a message to a channel, private group, or direct message channel. Supply channel and message content through text, blocks, or attachments, and use thread_ts when replying to an existing message. Use the authorship and unfurling options to control how the message is presented.

  • RetriesRetries up to 2×, 500ms backoff, 30s timeout.

1 parameter · 15 body fields
tokenstringrequired
Authentication token with the `chat:write` scope.

The destination, content, threading, authorship, formatting, and unfurling settings for the message.

as_userstringoptional
Pass true to post the message as the authed user, instead of as a bot. Defaults to false. See [authorship](#authorship) below.
attachmentsstringoptional
A JSON-based array of structured attachments, presented as a URL-encoded string.
blocksstringoptional
A JSON-based array of structured blocks, presented as a URL-encoded string.
channelstringrequired
Channel, private group, or IM channel to send message to. Can be an encoded ID, or a name. See [below](#channels) for more details.
icon_emojistringoptional
Emoji to use as the icon for this message. Overrides `icon_url`. Must be used in conjunction with `as_user` set to `false`, otherwise ignored. See [authorship](#authorship) below.
icon_urlstringoptional
URL to an image to use as the icon for this message. Must be used in conjunction with `as_user` set to false, otherwise ignored. See [authorship](#authorship) below.
link_namesbooleanoptional
Find and link channel names and usernames.
mrkdwnbooleanoptional
Disable Slack markup parsing by setting to `false`. Enabled by default.
parsestringoptional
Change how messages are treated. Defaults to `none`. See [below](#formatting).
reply_broadcastbooleanoptional
Used in conjunction with `thread_ts` and indicates whether reply should be made visible to everyone in the channel or conversation. Defaults to `false`.
textstringoptional
How this field works and whether it is required depends on other fields you use in your API call. [See below](#text_usage) for more detail.
thread_tsstringoptional
Provide another message's `ts` value to make this message a reply. Avoid using a reply's `ts` value; use its parent instead.
unfurl_linksbooleanoptional
Pass true to enable unfurling of primarily text-based content.
unfurl_mediabooleanoptional
Pass false to disable unfurling of media content.
usernamestringoptional
Set your bot's user name. Must be used in conjunction with `as_user` set to false, otherwise ignored. See [authorship](#authorship) below.

2 status codes
200Returns the channel identifier, message timestamp, and created message object with `ok: true`.
channelstringrequired
messageobjectrequired
okbooleanrequired
Allowed:true
tsstringrequired
defaultReturns `ok: false` with an error when the channel is unavailable, the message content is invalid, authentication or permission checks fail, or attachment limits are exceeded.
callstackstringoptional
Note: PHP callstack is only visible in dev/qa
errorstringrequired
Allowed:channel_not_foundnot_in_channelis_archivedmsg_too_longno_texttoo_many_attachmentsrate_limitednot_authedinvalid_authaccount_inactiveinvalid_arg_nameinvalid_array_arg
okbooleanrequired
Allowed:false

Error handling

channel is required and must identify a supported conversation. Provide message content through text, blocks, or attachments; if you use thread_ts, it must identify the parent message for the reply.