botkit icon indicating copy to clipboard operation
botkit copied to clipboard

catching "undefined" hears() patterns of users

Open morsidi opened this issue 10 years ago • 3 comments

By that I mean that I am looking for a quick way to respond to user's input which is not defined in my hears() functions. For example, let's say I got:

controller.hears("jacket").. controller.hears("shoes").. ... a lot of other hears("...").... ....

I want that in case a user inputs anything besides of (jacket, shoes.... all the others), to get a reply from the bot, let's say: boy.reply("Sorry I can't understand. Please try again with a different input").

I thought about storing of my inputs and then validating on a global message_received event, but it's too messy and there will be problems with the regex patterns.

morsidi avatar Jun 16 '16 12:06 morsidi

Try controller.hears('.*', [ ... ]) 😃

Learn more here.

krismuniz avatar Jun 18 '16 02:06 krismuniz

Did this solve your question? If not, please reopen!

peterswimm avatar Jul 01 '16 16:07 peterswimm

You can do it checking if message is a text:

controller.on('message_received', function(bot, message) {
    if(message.seq){
        bot.reply(message, 'txt')
    }
});

carloscba avatar Nov 24 '16 15:11 carloscba