Question

Is there a way to return the original message that Hubot hears/responds to?

Tried to access message and @message but that just seemed to error out when called.

Looking for something like:

robot.respond /test/, (msg) ->
  msg.send msg.the_message_that_the_user_typed_in

In this example it would echo back the entirety of the text that the user typed in.

In actuality I'll be playing with the text and stripping some things out, but I want an exact copy of the original text for messing around with.

Was it helpful?

Solution

Try using catchAll:

robot.catchAll (msg) ->
  msg.send msg.message.text

However it will match a message that no other matchers matched. If you want to catch absolutely everything, you'll have to do this:

robot.respond /(.*)/, (msg) ->
  msg.send msg.match[1]

Update:

Question was how to get the original message, not how to catch all messages. Answer:

robot.respond /test/, (msg) ->
  msg.send msg.message.text
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top