Skip to content

Commit

Permalink
Get Slack Profile (#279)
Browse files Browse the repository at this point in the history
  • Loading branch information
bassamtantawi-botpress authored Apr 19, 2024
1 parent ffb784a commit 34aa811
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions pages/cloud/channels/slack.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,37 @@ In Studio, add the **Sync Members** card to your flow.
### Reaction Added trigger

You can use the **Reaction Added** trigger to make actions when a reaction is added to a Slack message.

### Get Slack Profile
You can add the below code in an Execute Code card to allow the bot to retrieve the sender's Display Name or E-mail. You can add other properties as per your needs, all you need is to pass your bot's token in the first line. This can add more personalization and customization to your bot.

```javascript
const botToken = ''

const userInfoUrl = 'https://slack.com/api/users.profile.get?user=' + event.tags.user['slack:id']
// Query Slack API
await axios({ method: 'get', url: userInfoUrl, headers: { Authorization: 'Bearer ' + botToken } })
.then((response) => {
console.log(response.data)
user.userFullName = response.data.profile.display_name
user.email = response.data.profile.email
})
.catch(function (error) {
if (error.response) {
// The request was made and the server responded with a status code
// that falls out of the range of 2xx
console.log(error.response.data)
console.log(error.response.status)
console.log(error.response.headers)
} else if (error.request) {
// The request was made but no response was received
// `error.request` is an instance of XMLHttpRequest in the browser and an instance of
// http.ClientRequest in node.js
console.log(error.request)
} else {
// Something happened in setting up the request that triggered an Error
console.log('Error', error.message)
}
console.log(error.config)
})
```

0 comments on commit 34aa811

Please sign in to comment.