Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I figure out who installed a Slack App?

I'd like to be able to send a direct message to a user when they install the app, but I can't seem to find a way to tell who that is. Looking at Slack's OAuth documentation, this information simply doesn't seem to be included, only the name of the team and its ID. Any ideas on how to get the individual user?

Here's the relevant documentation: https://api.slack.com/docs/oauth.

Thanks!

like image 761
dsg42 Avatar asked Jan 07 '23 11:01

dsg42


2 Answers

Outdated

Edit: This is an outdated answer that works well for xoxp tokens, but not for modern xoxb/bot tokens, which you are most likely using when building an app for Slack. Please check out @s0urcer's answer below for a more up to date answer

You can call the auth.test method with your access token. The user_id of the user who installed your app will be in the response:

{"ok": true,
"url": "https:\/\/myteam.slack.com\/",
"team": "My Team",
"user": "cal",
"team_id": "T12345",
"user_id": "U12345"}

You can then send a message to this user by using user_id as the channel parameter in the chat.postMessage function.
This will send a direct message to the user either via Slackbot or via the bot user that is part of your app.

like image 92
Wilhelm Klopp Avatar answered Jan 16 '23 02:01

Wilhelm Klopp


When you exchange your temporary code to access token using oauth.v2.access API call, there is authed_user field in the response json. This field contains user id of the user who installed the app. Using this user id you can open direct messages channel to the user and send messages in there.

like image 22
s0urcer Avatar answered Jan 16 '23 03:01

s0urcer