Botkit: How to know user's full name who pinged the bot?

Created on 10 Sep 2016  路  2Comments  路  Source: howdyai/botkit

I was wondering how can I find out the user's full name from Slack, who pinged the bot such that I can take the conversation forward?

Slack-related help wanted

Most helpful comment

Because message.user is just the userid, I ended up dropping down to the Slack api and used /users/info to do something like:

// Within context where you have a message object
var currentUser; 
bot.api.users.info({user:message.user},function(err,response) {
  if(err) {
    bot.say("ERROR :(");
  }
  else {
    currentUser = response["user"];

    bot.say(
      {
        text: 'Hi ' + currentUser["name"],
        channel: whateverChannelId
      }
    );
  }
});

Here, the response["user"] object matches what you get back from the Slack API here: https://api.slack.com/methods/users.info

There may be other ways, but that way is currently working for me.

All 2 comments

Because message.user is just the userid, I ended up dropping down to the Slack api and used /users/info to do something like:

// Within context where you have a message object
var currentUser; 
bot.api.users.info({user:message.user},function(err,response) {
  if(err) {
    bot.say("ERROR :(");
  }
  else {
    currentUser = response["user"];

    bot.say(
      {
        text: 'Hi ' + currentUser["name"],
        channel: whateverChannelId
      }
    );
  }
});

Here, the response["user"] object matches what you get back from the Slack API here: https://api.slack.com/methods/users.info

There may be other ways, but that way is currently working for me.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

RafaelCosman picture RafaelCosman  路  4Comments

imjul1an picture imjul1an  路  3Comments

GautierT picture GautierT  路  3Comments

koubenecn picture koubenecn  路  3Comments

HannanShaik picture HannanShaik  路  3Comments