1

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

Yisela
  • 6,909
  • 5
  • 28
  • 51

2 Answers2

4

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

gasolin
  • 2,196
  • 1
  • 18
  • 20
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)
TonyH
  • 1,117
  • 8
  • 18
  • Awesome. Do you by any chance know where I can find a list of expressions I can use for creating more complicated matchings? For example, I'm using "()" and "|" but I don't know if there are more or how to exactly locate them: /(w|W)ho are you|(w|W)hat('s| is) your name/ – Yisela May 19 '16 at 12:32
  • 1
    There are many good regex tutorials online. Try searching Google for 'coffeescript regex' for specific code examples, but any regex should work between the the two forward slashes `/ /` – TonyH May 19 '16 at 13:25
  • 1
    BTW, check out https://regex101.com/ It's not the best tutorial, but excellent for testing out and explaining how your regexs work. – TonyH May 19 '16 at 22:35