javascript - 当消息不匹配时让hubot响应
问题描述
我正在用javascript为hubot编写一个松弛接口,我希望在输入无效命令时有一个默认消息。我目前在我的代码中有这个:
robot.respond(!(/command1/, /command2/, /command3/, etc.) function (msg) {
msg.reply('Returned message')
})
虽然这确实会响应所有无效消息,但它也会在我输入任何有效命令时发送我的响应。有没有办法来解决这个问题?
解决方案
我发现有一种更简单的方法可以做我想做的事。在以下父亲处使用 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)
})
}
推荐阅读
- android - 如何防止 onDataChange() 在 Firebase 中多次运行
- javascript - 可观察的
不可分配给 Observable<{}>。它缺少以下属性,例如 name、email、isAdmin - php - 使用 cron 作业或从 stripe 订阅 recurring web hook 进行定期付款?
- ios - 如何在 Swift 中检查 SDK 中是否存在互斥方法?
- unity3d - 如何在 Unity Editor 中安装推荐的 SDK 和 JDK
- java - Kotlin 中的克隆对象
- highcharts - Highcharts点击功能显示多个值
- c++ - 可变参数模板中的求和类型
- oracle - 在 SELECT 中使用变量并像普通 SELECT 一样输出结果
- java - 在两个坐标之间绘制路线