Is there a way to make Hubot reply to all messages that are not existing commands?

岁酱吖の 提交于 2020-01-16 04:54:20

问题


I'm giving Hubot a first try, and I'm making a dialog script for basic conversation. I have completed quite a few possibilities (I have a lot of questions and keywords working,) but when the user asks or says something Hubot doesn't recognize, it's complete silence.

I want to add a default set of answers for Hubot when it can't find an existing command or words (vague replies like "That's interesting" or "Tell me more".)

Is there a way to do this via script? Something like:

robot.respond / * /, (msg) ->
    msg.send ArrayOfVagueReplies

where * is "everything else". "If commands... else..."?


回答1:


Since hubot's robot.respond method takes a regex, you should be able to just supply /.*/ as the regex, and have it match everything.

So you'd have:

module.exports = (robot) ->
        robot.respond /.*/i, (msg) ->
            doSomething(msg)



回答2:


use robot.catchAll clause to catch all non-matched dialogues, you can reference to https://www.npmjs.com/package/hubot-suggest



来源:https://stackoverflow.com/questions/36960159/is-there-a-way-to-make-hubot-reply-to-all-messages-that-are-not-existing-command

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!