Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can a slack bot find out its own id?

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.

like image 924
BobK Avatar asked Jan 31 '19 18:01

BobK


People also ask

How do I find my Slack bot ID?

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".

Is Slack ID unique?

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.

Can Slack bot read private messages?

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.

How do I get a bot user?

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.


1 Answers

Got it. The API method to use is auth.test, it returns user id (plus some extra fields).

like image 158
BobK Avatar answered Oct 16 '22 15:10

BobK