scrapinghub / slackbot

A chat bot for Slack (https://slack.com).
MIT License
1.26k stars 394 forks source link

Slackbot doesn't recognize another bot text. #100

Closed hujuu closed 3 years ago

hujuu commented 8 years ago

Slackbot is set a word.

example... @listen_to('hoge')

Another bot writes 'hoge', but slackbot silence.

Please Tell me how to slackbot react another bot.

ghostsquad commented 8 years ago

@hujuu was your slackbot invited to the same channel?

lovato commented 7 years ago

Hi. I am trying to to that right now, and its not working.

I created a SlackBot, and another SlackApp to make use of IncomingWebhooks.

Then, my slack bot is listening, but it only replies to me, not to the SlackApp. In fact, the message isnt even triggered on my code. Cant tell if it actually cannot be achieved (which is odd), or if SlackBot core is filtering it.

image

On console, there is only one message...

image

Both bots are on the channel:

image

@lins05, any idea?

lovato commented 7 years ago

Its being filtered... not dispatched.

Sent via WebHook, I got this on _on_new_message:

{u'text': u'<@UXXXXXXXX>: Ol\xe1!', u'ts': u'1491565958.545033', u'user': u'UYYYYYYYY', u'reply_to': 0, u'type': u'message', u'channel': u'CXXXXXXXX'} {u'event_ts': u'1491566793.675882', u'text': u'<@yasmin> oi', u'ts': u'1491566793.675882', u'subtype': u'bot_message', u'team': u'TXXXXXXXX', u'type': u'message', u'channel': u'CXXXXXXXX', u'bot_id': u'BXXXXXXXX'}

And then via me saying "hi":

{u'source_team': u'TXXXXXXXX', u'text': u'<@UXXXXXXXX> oi', u'ts': u'1491566824.680886', u'user': u'UYYYYYYYY', u'team': u'TXXXXXXXX', u'type': u'message', u'channel': u'CXXXXXXXX'} <slackbot.dispatcher.Message object at 0x7f5d2da6d510>

lovato commented 7 years ago

I sort of figured it out... Made some changes on core code to test.

image

You cannot reply to a bot user_code as a user... Slack does this:

image

But to make it actualy work, I did:

`#

    except (KeyError, TypeError):

        if 'username' in msg:

            username = msg['username']

        if 'bot_id' in msg:

            username = msg['bot_id']

`

`#

def _get_user_id(self):

    if 'user' in self._body:

        return self._body['user']

    if 'bot_id' in self._body:

        return self._body['bot_id']

`

`#

@unicode_compact

def _gen_at_message(self, text):

    id = self._get_user_id()

    if id[0] == 'B':

        text = u'{}'.format(text)

    else:

        text = u'<@{}>: {}'.format(id, text)

    return text

`

It kind of solves my problem, but its not a good implementation to be merged. I dont know if it has some side-effects yet.

Hope this helps someone.

jtatum commented 7 years ago

There's two ways for bots to send messages. The message-with-bot-id is for messages sent by RTM-based bots. Messages sent from other integrations get a different message subtype, bot_message. In general though, this behavior is undesirable - you don't want bots to reply to other bots so feedback loops are avoided 😄 It might make an interesting feature toggle though.