💎 ChatSDK Ruby

Ephemeral Messages

Send messages visible only to a specific user for confirmations, hints, and error messages.

Ephemeral messages are visible only to a specific user and disappear when they navigate away. They are useful for confirmations, hints, and error messages that should not clutter the conversation for everyone.

Sending Ephemeral Messages

Use thread.post_ephemeral with the target user's ID:

bot.on_new_mention do |thread, message|
  thread.post_ephemeral(
    "Only you can see this!",
    user_id: message.author.id
  )
end

You can also send cards as ephemeral messages:

card = ChatSDK.card(title: "Hint") do
  text "Try using the /deploy command"
end

thread.post_ephemeral(card, user_id: message.author.id)

Platform Support

PlatformEphemeral SupportNotes
SlackYesUses chat.postEphemeral
TeamsNoRaises NotSupportedError
Google ChatYesUses private_message_viewer
MattermostYesUses create_post_ephemeral
DiscordNoRaises NotSupportedError
TelegramNoRaises NotSupportedError
TwilioNoRaises NotSupportedError
MessengerNoRaises NotSupportedError
WhatsAppNoRaises NotSupportedError

Handling Unsupported Platforms

Check capabilities before sending, or rescue the error:

bot.on_new_mention do |thread, message|
  if thread.adapter.supports?(:ephemeral_messages)
    thread.post_ephemeral("Secret hint!", user_id: message.author.id)
  else
    thread.post("Hint: #{message.author.name}, try /deploy")
  end
end

Or use a rescue:

bot.on_new_mention do |thread, message|
  begin
    thread.post_ephemeral("Secret!", user_id: message.author.id)
  rescue ChatSDK::NotSupportedError
    thread.post("Public fallback message")
  end
end

Use Cases

  • Confirmations -- "Your action was recorded" without notifying the whole channel
  • Validation errors -- "Invalid input, please try again" shown only to the user
  • Help text -- Show command usage only to the person who asked
  • Onboarding -- Welcome messages visible only to the new user

On this page