How to get username / userID in slack bot

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

I created a weak bot and it worked great. But when someone sends a message to the bot, I can’t say who sent it.

I tried msg.user msg.username, but they are all undefined.

I want my output to look like this

abc: @starbot hello
starbot: hello. abc 

eventually. I understood.

    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);
+4
source share
1 answer
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);
+3
source

All Articles