简体   繁体   中英

Having hubot respond when a message does not match

I am programming a slack interface for hubot in javascript, and I want to have a default message when an invalid command is input. I currently have this in my code:

robot.respond(!(/command1/, /command2/, /command3/, etc.) function (msg) {
   msg.reply('Returned message')
})

While this does respond to all invalid messages, it also sends my response whenever I put in any valid command as well. Is there a way to fix this?

I found there is an easier way to do what I want. Use the hubot support package at the following sire, which gives you a robot. reply all

https://www.npmjs.com/package/hubot-suggest

I then wrote the following code:

module.exports = function (robot) {
const text = dedent`
Command does not exist
Did you want one of the following commands?
'handel-codepipeline help'
'handel-codepipeline [deploy|delete]'
'canvas-update <sis_section_id> <curriculum_id> <title_code>'
'new repo' - creates a new githib repository
For more commands, type 'help'
`
robot.catchAll((msg) => {
    msg.reply(text)
})

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM