botkit icon indicating copy to clipboard operation
botkit copied to clipboard

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

Open HannanShaik opened this issue 10 years ago • 3 comments

I am new to this botkit. I was wondering how can I find out the user's name from Slack, who pinged the bot such that I can take the conversation forward?

HannanShaik avatar Jun 01 '16 14:06 HannanShaik

You can use direct_mention and mention events to listen for bot mentions. Then in handler you will have a message argument that will have user field with user ID that you can use to write a direct message or use in message contents.

Something like this:

controller.hears('hello',['direct_mention', 'mention'],function(bot, message) {
  bot.reply(message, 'Hello <@'+message.user+'>');
});

PaulAnnekov avatar Jun 19 '16 08:06 PaulAnnekov

Issue appears resolved.

peterswimm avatar Jun 21 '16 18:06 peterswimm

@PaulAnnekov message.user is some opaque identifier, not the user's actual name. #411 gives a possible solution using the Slack API.

michaelmior avatar Sep 14 '17 17:09 michaelmior