Search code examples
coffeescripthubot

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


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..."?


Solution

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