Skip to content
This repository was archived by the owner on Sep 22, 2025. It is now read-only.
This repository was archived by the owner on Sep 22, 2025. It is now read-only.

Loops with ephemeral messages #226

@sihu

Description

@sihu

I noticed that my Bot had problems with ephemeral messages, in particular with unfolding URLs.

How it can be reproduced

  1. bot posts an URL to a channel
  2. slackbot unfolds it
  3. bot posts the same URL to the channel
  4. slackbot sends message: "Pssst! I didn\u2019t unfurl <https:\/\/example.com> because it was already shared in this channel quite recently (within the last hour) and I didn\u2019t want to clutter things up."
  5. my bot responds with a Sorry @slackbot, I don't understand that command!
  6. now slackbot responds that he didn't understand
  7. ...there is a pingpong

Possible solution

The message hook should filter out those ephemeral messages. I think it will be something like:

lib/slack-ruby-bot/hooks/message.rb:

module SlackRubyBot
  module Hooks
    class Message
      def call(client, data)
        return if message_to_self_not_allowed? && message_to_self?(client, data)
        return if ephemeral_message?(data) # this would be new
        data.text = data.text.strip if data.text
        result = child_command_classes.detect { |d| d.invoke(client, data) }
        result ||= built_in_command_classes.detect { |d| d.invoke(client, data) }
        result ||= SlackRubyBot::Commands::Unknown.tap { |d| d.invoke(client, data) }
        result
      end

      ...

      private

      def  ephemeral_message?(data)
          data.is_ephemeral
          # and you could also check for the data.subtype == 'bot_message'
      end

I would be willing to contribute this fix if you like the solution.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions