首页 > 解决方案 > 当消息不匹配时让hubot响应

问题描述

我正在用javascript为hubot编写一个松弛接口,我希望在输入无效命令时有一个默认消息。我目前在我的代码中有这个:

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

虽然这确实会响应所有无效消息,但它也会在我输入任何有效命令时发送我的响应。有没有办法来解决这个问题?

标签: javascripthubot

解决方案


我发现有一种更简单的方法可以做我想做的事。在以下父亲处使用 hubot 支持包,它为您提供了一个机器人。全部回复

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

然后我写了以下代码:

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)
})

}


推荐阅读