Reputation: 1
When I access my Dialogflow app thru Google Assistant or Google Home I have easy access to the (Google) user name / email, etc. How can I get the Slack user name and channel when I access the app thru Slack (Dialogflow/Slack integration)?
I know when the call originates from Slack (source). I can identify channel, team and user ID (slack-coded). I need to find what the IDs mean, i.e., the names of the users. The code below works nicely:
const src = (JSON.stringify(request.body.originalDetectIntentRequest.source));
if (src == "slack") {
const p_team = (JSON.stringify(request.body.originalDetectIntentRequest.payload.data.event.team));
const p_user = (JSON.stringify(request.body.originalDetectIntentRequest.payload.data.event.user));
const p_channel = (JSON.stringify(request.body.originalDetectIntentRequest.payload.data.event.channel));
}
if (src == "google") {
...
}
...
I get Slack-coded IDs for 'p_team", 'p_user' and 'p_channel'. How can I find out their real names?
Upvotes: 0
Views: 1315
Reputation: 91
Use "Bot User OAuth Access Token" , In "OAuth and permissions Tab" Format is xoxb-xxxxx-xxxxx-xxxx. And then add scope "conversations.list,users.list,users.read" in "Bot Token Scopes" and then reinstall your app in slack. And then try to get user details from API calling while users:read is not available in slack https://api.slack.com/methods/methodname. But you can call it from your code and your response is like : {"ok":true,"user":"id":"XXXXXX","team_id":"xxxxxxxx","name":"xxxxxxx","deleted":false,"color":"xxxxx","real_name":"XXXXXXx","tz":"", some more fields.....}}
Upvotes: 0
Reputation: 32852
To resolve the names of Slack entities from their IDs you need to call the respective API list methods. It will give you the list of all elements of that category. You can then match the ID to find its names:
users.list
conversations.list
For the team name you can call auth.test
with your respective Slack token.
Upvotes: 1