Search code examples
slack-apihubot

Hubot. Get the mentioned user's email in Slack


I'm writing a Script for Hubot using the Slack API

How can I get the mentioned user's email (@ben for example) from a message?

I've figured out I can do something like:

user.profile.email

To get the current user, but I'm not sure about searching for others or getting a profile based on a mention


Solution

  • In order to get the email for a Slack user you need to

    1. Retrieve list of all users from the Slack API with users.list
    2. Browse through the list and match by user name or user ID

    Note that your access token needs both the users:read and users:read.email scopes in order to retrieve that information. See also here for more info about scopes and here for detail on email address access.