我在创建一种让机器人在松弛频道中正确收听而不回复频道中所说的所有内容的方式时遇到问题。
所以,这是我目前处理这个问题的方式:
controller.hears(['You\'re awesome','Help',"What would Jeremy say?", "Hello","Top 5", "Hi", "I love you", /^.{0,}jirabot.{0,}$/], ['direct_message','direct_mention','mention','ambient'],function(bot,message) {
console.log(message);
// This will show the last 5 created tickets in Zendesk
if(message.text === "Top 5"){
try{
Do this thing
});
}catch(err){
bot.reply(message, 'I\'m sorry I did not get that. Please try again.');
}
}
else if (message.text === "You're Awesome"){
bot.reply(message, 'Nah, You\'re Awesome <@'+message.user+'>');
}
else {
bot.reply(message, 'I\'m sorry I don\'t understand');
}
这种方式有效,但如果有人说别的东西,它会一直说对不起,我不明白。我如何让机器人不每次都这么说?
我也尝试过这种方式,但机器人终止并且在其中一项操作完成后不会做任何其他事情:
var hi = 'HI';
var love = 'I LOVE YOU';
controller.hears([hi, /^.{0,}jirabot.{0,}$/],['direct_message','direct_mention','mention','ambient'],function(bot,message) {
// start a conversation to handle this response.
bot.startConversation(message,function(err,convo) {
if (message.text.toLowerCase() === hi.toLowerCase()){
bot.reply(message, 'What can I do for you? <@'+message.user+'>');
convo.next();
}else{
bot.reply(message, 'Sorry, I don\'t understand');
convo.next();
}
});
});
controller.hears([love, /^.{0,}jirabot.{0,}$/],['direct_message','direct_mention','mention','ambient'],function(bot,message) {
// start a conversation to handle this response.
bot.startConversation(message,function(err,convo) {
if (message.text.toLowerCase() === love.toLowerCase()){
bot.reply(message, 'No, I love you more <@'+message.user+'>');
convo.next();
}else{
bot.reply(message, 'Sorry, I don\'t understand');
convo.next();
}
});
});
任何想法或反馈都会很棒!