问题
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