Sends an ephemeral message to a user in a channel.

Facts

Method access

HTTP
JavaScript
Python
Java
HTTP
POSThttps://slack-gov.com/api/chat.postEphemeral
Bolt for Java
app.client().chatPostEphemeral
Powered by Bolt
Bolt for Python
app.client.chat_postEphemeral
Powered by Bolt
Bolt for JavaScript
app.client.chat.postEphemeral
Powered by Bolt

Content types

application/x-www-form-urlencodedapplication/json
  • Rate limits

    Tier 4
  • Arguments

    Required arguments

    Authentication token bearing required scopes. Tokens should be passed as an HTTP Authorization header or alternatively, as a POST parameter.

    Example
    xxxx-xxxxxxxxx-xxxx

    Channel, private group, or IM channel to send message to. Can be an encoded ID, or a name.

    Example
    C1234567890

    id of the user who will receive the ephemeral message. The user should be in the channel specified by the channel argument.

    Example
    U0BPQUNTA

    One of these arguments in addition to text is required to describe the content of the message. When attachments or blocks are included, text will be used as fallback text for notifications only.

    A JSON-based array of structured attachments, presented as a URL-encoded string.

    Example
    [{"pretext": "pre-hello", "text": "text-world"}]

    A JSON-based array of structured blocks, presented as a URL-encoded string.

    Example
    [{"type": "section", "text": {"type": "plain_text", "text": "Hello world"}}]

    How this field works and whether it is required depends on other fields you use in your API call. See below for more detail.

    Example
    Hello world
    Optional arguments

    (Legacy) Pass true to post the message as the authed user. Defaults to true if the chat:write:bot scope is not included. Otherwise, defaults to false.

    Example
    true

    Emoji to use as the icon for this message. Overrides icon_url.

    Example
    :chart_with_upwards_trend:

    URL to an image to use as the icon for this message.

    Example
    http://lorempixel.com/48/48

    Find and link channel names and usernames.

    Example
    true

    Change how messages are treated. Defaults to none. See below.

    Example
    full

    Provide another message's ts value to post this message in a thread. Avoid using a reply's ts value; use its parent's value instead. Ephemeral messages in threads are only shown if there is already an active thread.

    Example
    1234567890.123456

    Set your bot's user name.

    Example
    My Bot

    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, 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

    Information in the section below applies only to classic apps.

    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 the Slack 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 channels.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 of channel to post to that user's @slackbot channel as the bot.
      • Pass the IM channel's ID (D023BB3L2) as the value of channel to post to that IM channel as the bot. The IM channel's ID can be retrieved through the im.list API method.
    • If as_user is true:
      • Pass the IM channel's ID (D023BB3L2) as the value of channel to post to that IM channel as the authenticated user. The IM channel's ID can be retrieved through the im.list API method.

    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 im.list.

    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.

    Example responses

    Common successful response

    Typical success response

    {
        "ok": true,
        "message_ts": "1502210682.580145"
    }

    Common error response

    Typical error response

    {
        "ok": false,
        "error": "user_not_in_channel"
    }

    Errors

    This table lists the expected errors that this method could return. However, other errors can be returned in the case where the service is down or other unexpected factors affect processing. Callers should always check the value of the ok params in the response.

    ErrorDescription
    channel_not_found

    Value passed for channel was invalid.

    invalid_blocks

    Blocks submitted with this message are not valid

    invalid_blocks_format

    The blocks is not a valid JSON object or doesn't match the Block Kit syntax.

    is_archived

    Channel has been archived.

    message_limit_exceeded

    Members on this team are sending too many messages. For more details, see https://slack.com/help/articles/115002422943-Usage-limits-for-free-workspaces

    messages_tab_disabled

    Messages tab for the app is disabled.

    msg_too_long

    Message text is too long

    no_text

    No message text provided

    restricted_action

    A workspace preference prevents the authenticated user from posting.

    too_many_attachments

    Too many attachments were provided with this message. A maximum of 100 attachments are allowed on a message.

    user_not_in_channel

    Intended recipient is not in the specified channel.

    access_denied

    Access to a resource specified in the request is denied.

    account_inactive

    Authentication token is for a deleted user or workspace when using a bot token.

    deprecated_endpoint

    The endpoint has been deprecated.

    ekm_access_denied

    Administrators have suspended the ability to post a message.

    enterprise_is_restricted

    The method cannot be called from an Enterprise.

    invalid_auth

    Some aspect of authentication cannot be validated. Either the provided token is invalid or the request originates from an IP address disallowed from making the request.

    method_deprecated

    The method has been deprecated.

    missing_scope

    The token used is not granted the specific scope permissions required to complete this request.

    not_allowed_token_type

    The token type used in this request is not allowed.

    not_authed

    No authentication token provided.

    no_permission

    The workspace token used in this request does not have the permissions necessary to complete the request. Make sure your app is a member of the conversation it's attempting to post a message to.

    org_login_required

    The workspace is undergoing an enterprise migration and will not be available until migration is complete.

    token_expired

    Authentication token has expired

    token_revoked

    Authentication token is for a deleted user or workspace or the app has been removed when using a user token.

    two_factor_setup_required

    Two factor setup is required.

    team_access_not_granted

    The token used is not granted the specific workspace access required to complete this request.

    accesslimited

    Access to this method is limited on the current network

    fatal_error

    The server could not complete your operation(s) without encountering a catastrophic error. It's possible some aspect of the operation succeeded before the error was raised.

    internal_error

    The server could not complete your operation(s) without encountering an error, likely due to a transient issue on our end. It's possible some aspect of the operation succeeded before the error was raised.

    invalid_arg_name

    The method was passed an argument whose name falls outside the bounds of accepted or expected values. This includes very long names and names with non-alphanumeric characters other than _. If you get this error, it is typically an indication that you have made a very malformed API call.

    invalid_arguments

    The method was either called with invalid arguments or some detail about the arguments passed is invalid, which is more likely when using complex arguments like blocks or attachments.

    invalid_array_arg

    The method was passed an array as an argument. Please only input valid strings.

    invalid_charset

    The method was called via a POST request, but the charset specified in the Content-Type header was invalid. Valid charset names are: utf-8 iso-8859-1.

    invalid_form_data

    The method was called via a POST request with Content-Type application/x-www-form-urlencoded or multipart/form-data, but the form data was either missing or syntactically invalid.

    invalid_post_type

    The method was called via a POST request, but the specified Content-Type was invalid. Valid types are: application/json application/x-www-form-urlencoded multipart/form-data text/plain.

    missing_post_type

    The method was called via a POST request and included a data payload, but the request did not include a Content-Type header.

    ratelimited

    The request has been ratelimited. Refer to the Retry-After header for when to retry the request.

    request_timeout

    The method was called via a POST request, but the POST data was either missing or truncated.

    service_unavailable

    The service is temporarily unavailable

    team_added_to_org

    The workspace associated with your request is currently undergoing migration to an Enterprise Organization. Web API and other platform operations will be intermittently unavailable until the transition is complete.

    Warnings

    This table lists the expected warnings that this method will return. However, other warnings can be returned in the case where the service is experiencing unexpected trouble.

    WarningDescription
    missing_charset

    The method was called via a POST request, and recommended practice for the specified Content-Type is to include a charset parameter. However, no charset was present. Specifically, non-form-data content types (e.g. text/plain) are the ones for which charset is recommended.

    superfluous_charset

    The method was called via a POST request, and the specified Content-Type is not defined to understand the charset parameter. However, charset was in fact present. Specifically, form-data content types (e.g. multipart/form-data) are the ones for which charset is superfluous.

    Arguments

    Need a token? Create and install a Slack app to begin.
    This will make a real API request. Beware of using it with live workspaces.

    API response


    Submit your arguments to see the API response
    Calling chat.postEphemeral
    Java
    JavaScript
    Java
    import com.slack.api.bolt.App; import com.slack.api.bolt.AppConfig; import com.slack.api.bolt.jetty.SlackAppServer; import com.slack.api.methods.SlackApiException; import java.io.IOException; public class ChatPostEphemeral { public static void main(String[] args) throws Exception { var config = new AppConfig(); config.setSingleTeamBotToken(System.getenv("SLACK_BOT_TOKEN")); config.setSigningSecret(System.getenv("SLACK_SIGNING_SECRET")); var app = new App(config); // `new App()` does the same app.message("secret", (req, ctx) -> { var logger = ctx.logger; try { var event = req.getEvent(); // Call the chat.postEphemeral method using the built-in WebClient var result = ctx.client().chatPostEphemeral(r -> r // The token you used to initialize your app is stored in the `context` object .token(ctx.getBotToken()) // Payload message should be posted in the channel where original message was heard .channel(event.getChannel()) // The user the message should appear for .user(event.getUser()) .text("Shhhh only you can see this :shushing_face:") ); logger.info("result: {}", result); } catch (IOException | SlackApiException e) { logger.error("error: {}", e.getMessage(), e); } return ctx.ack(); }); var server = new SlackAppServer(app); server.start(); } }
    JavaScript
    Code to initialize Bolt app
    // Require the Node Slack SDK package (github.com/slackapi/node-slack-sdk) const { WebClient, LogLevel } = require("@slack/web-api"); // WebClient instantiates a client that can call API methods // When using Bolt, you can use either `app.client` or the `client` passed to listeners. const client = new WebClient("xoxb-your-token", { // LogLevel can be imported and used to make debugging simpler logLevel: LogLevel.DEBUG });
    // ID of the channel you want to send the message to const channelId = "C12345"; // ID of the user you want to show the ephemeral message to const userId = "U12345"; try { // Call the chat.postEphemeral method using the WebClient const result = await client.chat.postEphemeral({ channel: channelId, user: userId, text: "Shhhh only you can see this :shushing_face:" }); console.log(result); } catch (error) { console.error(error); }