Search code examples
node.jsbotframeworkslackslack-api

Getting the name of the sender of the message in slack using Microsoft Bot Framewok


I have created a slackbot using microsoft bot framework. Is there any way of getting the name of the sender of the message?

For example, I have the following code.

`

bot.dialog('/raiseTask', 
  function (session, args, next) {
    session.send('Hi');
  }
);

`

I know the information is stored inside the session about the type of the text and actual message that is sent by the sender on slack to the bot. After looking at the docs and reading thoroughly, I was unsuccessful in finding any relevant information regarding finding the name of the sender.

To be more precise, the functionality that I want to achieve is:

Saif: Hi @slackbot slackbot: Hi Saif

David: Hi @slackbot slackbot: Hi David

Thanks!


Solution

  • In Node.js, you can retrieve the user name or name of the sender of the message using session.message.user.name , find the code snippet below:

    bot.dialog('/raiseTask', function (session, args, next) {
          session.send("Hi " + session.message.user.name);
    });