Botkit: Identifying a user

Created on 29 Dec 2015  路  12Comments  路  Source: howdyai/botkit

I want to get the friendly name of a user.

Tried: controller.storage.users.get(message.user,function(err,user) {}) which is in the bot.js file but user always come in as undefined.

Reading through source it appears that there is storage but no methods to lookup users...

Is this right?

Slack-related help wanted

Most helpful comment

@Shubhamjain112, it's late to the game but this is how I've done it:

controller.hears('hello', ['direct_mention'], (bot, message) => {
    bot.api.users.info({user: message.user}, (error, response) => {
        let {name, real_name} = response.user;
        console.log(name, real_name);
    })
})

All 12 comments

Sounds like you want to get the name of the user from Slack. Am I right?

For this, you would use bot.api.users.info()

Yep. Just thought there would be a method backed by storage that would identify the user from storage and only make the call if needed. I added one. Will look at a pull request..

How do I get the user name through bot.api.users.info() ?

@Shubhamjain112, it's late to the game but this is how I've done it:

controller.hears('hello', ['direct_mention'], (bot, message) => {
    bot.api.users.info({user: message.user}, (error, response) => {
        let {name, real_name} = response.user;
        console.log(name, real_name);
    })
})

I got

{ ok: false, error: 'not_authed' }

I added users:read to the scope... but still not_auth...

same problem here. users:read added to the scope. still getting not_authed error

same for me, did you find a fix?

(For people finding this issue via Google:)

If you just want to mention the user, you don't need to query the users API to get the handle.

Format the message like this: Hello <@${user}>. Slack will turn the ID into a proper mention.

I could not figure out how to get the user...
I used this package just for getting the list of users https://www.npmjs.com/package/slackbots

Hi,

I want the bot to hear from only specific user.

(Its drift user that I want to hear only).

(For people finding this issue via Google:)

If you just want to mention the user, you don't need to query the users API to get the handle.

Format the message like this: Hello <@${user}>. Slack will turn the ID into a proper mention.

what if I'v got user id and I don't want to get mention, just name ?

@artur79 , did you manage to solve this because i am also trying the same thing that you wanted

Was this page helpful?
0 / 5 - 0 ratings

Related issues

RafaelCosman picture RafaelCosman  路  4Comments

iworkforthem picture iworkforthem  路  3Comments

TheJimFactor picture TheJimFactor  路  4Comments

HannanShaik picture HannanShaik  路  3Comments

imjul1an picture imjul1an  路  3Comments