Search code examples
hubot

How to trigger an event from hubot console?


I am trying to debug and play with hubot from the hubot console.

Hubot scripts react to messages written in the hubot console.

So if I have a script like this:

module.exports = (robot) ->
  robot.respond /hi/, (msg) ->
    msg.send "hi guy"

And within my hubot console I write "hubot hi", then hubot will repond like so:

$hubot> hubot hi
$hubot> hi guy

My question is how can I do the same with events (robot.on).

As in if I have code like this:

module.exports = (robot) ->
  robot.on "github-repo-event", (event) ->
    console.log "grrrr, I'm triggered"

Then how would I trigger this event from the hubot console?

Is there something like this ....?

$hubot> hubot trigger-event:github-repo-event

Solution

  • The easiest thing I found I can do is add a script that emits the event I want.

    So add something like this:

    # debug-script.coffee
    
    module.exports = (robot) ->
      robot.respond /debug-github-repo-event/, (msg) ->
      robot.emit 'github-repo-event', eventData
    

    Then from the console you can achieve this

    $hubot> hubot debug-github-repo-event
    $hubot> grrrr, I'm triggered
    

    I don't like this but it works.

    I didn't want to create an adapter that adds events to the shell adapter.