从Slack API获取用户名

1 node.js slack-api botkit

我正在构建一个需要监听环境关键字的slackbot,但检查以确保特定用户编写了关键字.我正试图用这个来测试命令:

controller.hears(['texas'], 'ambient', function(bot, message) {
  username = users.info.name;
  bot.reply(message, username);
});
Run Code Online (Sandbox Code Playgroud)

最后,我想运行条件逻辑以确保用户名与我希望机器人响应的用户匹配.但这不起作用; 我使用API​​错了吗?如何检索用户名,如何检查以确保用户名正确?

Mat*_*ieu 5

你会做这样的事情:

controller.hears(['texas'], 'ambient', function(bot, message) {
  bot.api.users.info({user: message.user}, function(err, info){
    //check if it's the right user using info.user.name or info.user.id
    bot.reply(message, info.user.name)
  })
})
Run Code Online (Sandbox Code Playgroud)