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