How to get username/userID in slack bot

可紊 提交于 2020-01-14 09:57:08

问题


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);

回答1:


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);


来源:https://stackoverflow.com/questions/36147001/how-to-get-username-userid-in-slack-bot

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!