简体   繁体   English

当消息不匹配时让Hubot响应

[英]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. 我正在用javascript编程供Hubot使用的松弛接口,当输入无效命令时,我希望显示默认消息。 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. 使用以下父亲的Hubot支持包,它将为您提供机器人。 reply all 全部回复

https://www.npmjs.com/package/hubot-suggest 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)
})

} }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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