I'm having issues with creating a way where the bot correctly listens within a slack channel without replying to everything being said in the channel.
So, here is the way I currently approached this:
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');
}
This way works, but it if someone says something else it keeps saying I'm sorry I don't understand. How do I make the bot not say that every time?
I also tried this way, but the bot terminates and won't do anything else after one of the actions is completed:
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();
}
});
});
Any ideas or feedback would be great!
via traveler316
No comments:
Post a Comment