Search code examples
slackslack-api

Slack bot getting information from threads and messages?


Slack bots can get information about messages that have just been posted with the "messages" event. So why can't they get information about all the messages in a thread?

So for example when someone makes a reply to a message in a thread a message event is fired with the subtype of "message_replied" however the text fields of all of the messages in the result are out of scope for the bot.

Is there a way to access this information? I have tried using things like channels.replies and conversations.replies but the results of those are out of scope for the bot too. Requiring the channels:history scope.

I would settle for the bot being able to read the content of its own messages only.


Solution

  • You can access threads with your bot via API method conversations.replies (or the pendant methods) by using the user token from your Slack app. A Slack app with bot users always has both a user token (with rights inherited from the original installer) and a bot token.

    As the documentation says in section Threading messages:

    While Slack app-based bot users can't access these methods directly, user tokens granted with the correlating scope can.