8

https://github.com/DeronLee/starbot.git

I created a slack bot and it worked fine. But when somebody sends message to the bot, I'm not able to tell who sent it.

I tried msg.user msg.username, but all of them are undefined.

I just want my output to look like this

abc: @starbot hello
starbot: hello. abc 

finally. I got it.

    slack.users.info({
    token: config('SLACK_TOKEN'),
    user: msg.user
  }, (err, data) => {
    if (err) throw err
    var text = makeMessage.makeMessage(msg.text, data.user.name);
    sendMessage.send(msg, text, slack);
Deron Lee
  • 379
  • 1
  • 3
  • 8

1 Answers1

6
slack.users.info({
  token: config('SLACK_TOKEN'),
  user: msg.user
}, (err, data) => {
  if (err) throw err

  var text = makeMessage.makeMessage(msg.text, data.user.name);
  sendMessage.send(msg, text, slack);
Deron Lee
  • 379
  • 1
  • 3
  • 8
  • 1
    I had a similar problem and I've been working and searching on a fix for more days than I care to admit and this worked perfectly! Thanks for posting! – dannyk Apr 04 '16 at 16:35