chat.postEphemeral
method
We're still building and not all features are available quite yet. Enjoy this peek into the future!
Not ready for the future? Return to the past at api.slack.com.
Usage info
This method posts an ephemeral message, which is visible only to the assigned user in a specific public channel, private channel, or private conversation.
Ephemeral message delivery is not guaranteed — the user must be currently active in Slack and a member of the specified channel
. By nature, ephemeral messages do not persist across reloads, desktop and mobile apps, or sessions. Once the session is closed, ephemeral messages will disappear and cannot be recovered.
Use ephemeral messages to send users context-sensitive messages, relevant to the channel they're detectably participating in. Avoid sending unexpected or unsolicited ephemeral messages.
Text usage: text
, blocks
or attachments
The usage of the text
field changes depending on whether you're using blocks
. If you're using blocks
, this is used as a fallback string to display in notifications. If you aren't, this is the main body text of the message. It can be formatted as plain text, or with mrkdwn
.
The text
field is not enforced as required when using blocks
or attachments
. However, we highly recommended that you include text
to provide a fallback when using blocks
, as described above.
Formatting
Messages are formatted as described in the formatting spec. You can specify values for parse
and link_names
to change formatting behavior.
The optional attachments
argument should contain a JSON-encoded array of attachments.
For more information, see the attachments spec. If you're using a Slack app, you can also use this method to attach message buttons.
For best results, limit the number of characters in the text
field to a few thousand bytes at most. Ideally, messages should be short and human-readable, if you need to post longer messages, please consider uploading a snippet instead. (A single message should be no larger than 4,000 bytes.)
Consider reviewing our message guidelines, especially if you're using attachments or message buttons.
Authorship
How message authorship is attributed varies by a few factors, with some behaviors varying depending on the kinds of tokens you're using to post a message.
Legacy concerns
Legacy authorship
Classic apps using the umbrella bot
scope can't request additional scopes to adjust message authorship.
For classic apps, the best way to control the authorship of a message is to be explicit with the as_user
parameter.
If you don't use the as_user
parameter, chat.postEphemeral
will guess the most appropriate as_user
interpretation based on the kind of token you're using.
If as_user
is not provided at all, then the value is inferred, based on the scopes granted to the caller: If the caller could post with as_user
passed as false
, then that is how the method behaves; otherwise, the method behaves as if as_user
were passed as true
.
When as_user
is false
When the as_user
parameter is set to false
, messages are posted as "bot_messages
", with message authorship attributed to the user name and icons associated with theSlack app.
When as_user
is true
Set as_user
to true
and the authenticated user will appear as the author of the message. Posting as the authenticated user requires the client
or the more preferred chat:write:user
scopes.
Target channels and users
You must specify a conversation container (public channel, private channel, or an IM channel) by providing its ID to the channel
argument. You also must specify a target user
.
Each type of channel behaves slightly differently based on the authenticated user's permissions and additional arguments. If the target user
is not in the given channel, the ephemeral message will not be delivered, and we'll return a user_not_in_channel
error.
Workspace apps will receive a no_permission
error when they are not a member of the specified channel
.
Note that the user
parameter expects a user's id
, and not a username or display name.
Post to a public channel
You can either pass the channel's name (#general
) or encoded ID (C024BE91L
), and the message will be posted to that channel. The channel's ID can be retrieved through the conversations.list API method.
Post to a private group
As long as the authenticated user is a member of the private group, you can either pass the group's name (secret-group
) or encoded ID (G012AC86C
), and the message will be posted to that group. The private group's ID can be retrieved through the conversations.list API method.
Post to an IM channel
Posting to an IM channel is a little more complex depending on the value of as_user
.
- If
as_user
is false:- Pass a username (
@chris
) as the value ofchannel
to post to that user's @slackbot channel as the bot. - Pass the IM channel's ID (
D023BB3L2
) as the value ofchannel
to post to that IM channel as the bot. The IM channel's ID can be retrieved through the conversations.list API method.
- Pass a username (
- If
as_user
is true:- Pass the IM channel's ID (
D023BB3L2
) as the value ofchannel
to post to that IM channel as the authenticated user. The IM channel's ID can be retrieved through the conversations.list API method.
- Pass the IM channel's ID (
To send a direct message to the user owning the token used in the request, provide the channel
field with the a conversation/IM ID value found in a method like converstions.list
.
Response
The message_ts
included with the response cannot be used with chat.update
, as it does not represent an actual message written to the database like it does with other api methods.