Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Message Event: how to distinguish messages sent to bot DM's as oppose to DM's between users. #1082

Open
FadyEndlessClouds opened this issue May 14, 2024 · 1 comment
Labels
question Further information is requested

Comments

@FadyEndlessClouds
Copy link

I have a slack-bot which subscribes to the message:im event on both the users behalf and the bots behalf. These are both needed as the bot performs an action on behalf of a user when they send a DM. A different action is needed for whenever users DM the bot from the app home. How can I differentiate between these two events, as at the moment event dictionary for both of these types of events look the same?

@seratch
Copy link
Member

seratch commented May 17, 2024

Hi @FadyEndlessClouds, thanks for asking the question!

Receiving message events with both a bot and on behalf of a user can be a bit complex.

The simplest scenario is a direct message (DM) between your app's bot user and a human user who hasn't granted your app permission to subscribe to the user's message events. In this case, you can check if body.authorizations[0].is_bot is true. If it is set to true, the message event is definitely a DM with the bot.

When it comes to a DM between a bot and a human who has granted your app permission to subscribe to the human's DM message events, you need to do extra work to confirm if a message is in a bot DM. When your app receives a message event from a channel/DM where the app has multiple sources (e.g., bot and human), only one of them can be delivered. The delivered event could be associated with a human source even if the DM is with the bot. In this case, body.authorizations[0].is_bot could be set to false. To check more details on the message event, you can call apps.event.authorizations.list API with an app-level token and the message event payload's body.event_context string. With this call, you can retrieve all sources associated with the event. If one of them is a bot installation, then the message event is in a DM with the bot.

This might sound a bit complicated, but it is what it is. I hope this clarifies things for you.

@seratch seratch added the question Further information is requested label May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants