我正在尝试在nodejs中创建一个基于其输入回复用户的松散bot。但就目前机器人不断回复自己的邮件Slack Bot在Node js中回复自己的消息
这是我的机器人
let Bot = require('slackbots');
// create a bot
let settings = {
token: 'xoxb-10584202949',
name: 'BotHelp'};
let bot = new Bot(settings);
bot.on('start', function() {
bot.postMessageToChannel('general', 'At your service');
});
bot.on('message',function (data) {
console.log(data);
if (data.username != "BotHelp" && data.subtype != 'bot_message'){
bot.postMessageToChannel('general', 'Yoooo');
}
});
控制台日志中的数据打印
{ type: 'hello' }
{ text: 'At your service',
username: 'BotHelp',
bot_id: 'B336WGVSM',
type: 'message',
subtype: 'bot_message',
team: 'T2ZAW44P3',
user_team: 'T2ZAW44P3',
channel: 'C303W2D4M',
ts: '1479877794.000266' }
{ type: 'presence_change',
presence: 'active',
user: 'U33QS0VEF' }
那么为什么代码我的验证无法检查消息是否已从机器人本身发送?
谢谢您的时间
什么让你觉得验证失败? –
@MathewJibin,因为它在我的一般聊天室中不断发帖Yooo在无限循环中 – Alexander
你确定'data.username'和'data.subtype'是否如预期的那样?发送消息中发送它们或在控制台中打印它们。 –