I am writing a slack bot that listens to all messages in a channel. His response should be vary based on whether the message mentions him or not. The problem is that I can not figure out how to "properly" find out bot's id. The bot is subscribed to message.channels
event and when someone posts message mentioning the bot, I get this:
{"client_msg_id":"b94dcc57-d640-4815-9eeb-23c048564bf0",
"type":"message",
"text":"<@UFT98YYYY> how are you?",
"user":"UD45QXXXX",
"ts":"1548958008.003400",
"channel":"CFK3AZZZZ",
"event_ts":"1548958008.003400",
"channel_type":"channel"}
What is the proper way of knowing that UFT98YYYY
is bot's id? There are certainly ways of getting around this (look in the logs, set bot's id in the config), but they seem ugly, fragile and need some extra steps when installing the bot. Is there a Slack API call the bot can use to find out its id?
Btw, I know that I can subscribe to mentions only, but I need to listen&react to non-mentioning messages too.
Click on a user name within Slack. Click on "View full profile" in the menu that appears. Click the ellipses (three dots). Click on "Copy Member ID".
User IDs are now globally unique. Unless you are on an Enterprise Grid plan, the same user on two unrelated workspaces will have different user IDs. See the Sign in with Slack docs for even more information on these responses.
A user (or bot user) still needs to be member of a private / direct message channel in order to have access to it. It does also not matter what permission or role you have. Even the primary owner has no access to private channels he is not a member of.
A bot user is added to a workspace by installing the app that the bot is associated with. Once you do, you'll get a bot token that is imbued with the bot scope.
Got it. The API method to use is auth.test
, it returns user id (plus some extra fields).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With