从Slack API获取用户名

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

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

最后,我想运行条件逻辑,以确保用户名匹配我想要机器人回应的用户。 这虽然不起作用; 我使用API​​错误? 如何检索用户名,以及如何检查以确保它是正确的用户?

你会做这样的事情:

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

users.list此方法返回组中所有用户的列表。 这包括已删除/已停用的用户。 该方法的URL为https://slack.com/api/users.list

有关Bot用户的更多信息