How can I trigger a default event if none of the event Regexp defined in "botkit.hears" is triggered?
You can do a catch all handler in a few ways.
capture every mention that didn't get otherwise heard:
controller.on('direct_mention', function(bot, message) {
// .. do default action
});
or, hear a wildcard:
controller.hears('.*', 'direct_mention', function(bot, message) {
// .. do default action
});
@benbrown Thank you for the suggestions 馃憤 . I tried both your suggestions, but it does not work as expected. The requirement is that if none of the predefined "controller.hear" is triggered then the default action should trigger.
1) controller.on('direct_mention') : Calls the default action every time a request is made, regardless of other existing actions. For e.g. I have an action defined for the keyword "help", controller.on('direct_mention') is called first every time, then the 'help' is also triggered.
2) controller.hears('.*') : overrides all other keywords. for e.g. When I trigger the keyword "help", only default action is triggered and "help" is not triggered.
@tejzpr a key factor I neglected to mention: you have to define these catch-all handlers _at the end of your code_. Botkit fires handlers in the order they are specified, and will stop handling once a hears pattern is matched.
@benbrown Thank you! That worked. 馃挴
Just to be sure: It has to be the last loaded skill for the bot ? I am also facing weird effects
@simonfranzen yes, hears are processed in order.
Most helpful comment
@tejzpr a key factor I neglected to mention: you have to define these catch-all handlers _at the end of your code_. Botkit fires handlers in the order they are specified, and will stop handling once a
hearspattern is matched.