From HTTP to IRC #275

Closed
jk opened this Issue Apr 17, 2012 · 12 comments

Comments

Projects
None yet
4 participants
@jk

jk commented Apr 17, 2012

Hi there,

I'm a novice when it comes to CoffeeScript. But I found out that hubot comes with an integrated HTTP listener. What I want to is to write a script which allows me to post something via HTTP POST that hubot says in a specific room on IRC. The background of this use case is, that we want to interfeace hubot from our svn and git hooks to announce new commits / push's.

Is this even possible?

@tombell

This comment has been minimized.

Show comment Hide comment
@tombell

tombell Apr 17, 2012

Contributor

If I understand this correctly, you want to say post some data to a URL in Hubot, and have the data be echoed into an IRC channel?

Contributor

tombell commented Apr 17, 2012

If I understand this correctly, you want to say post some data to a URL in Hubot, and have the data be echoed into an IRC channel?

@jk

This comment has been minimized.

Show comment Hide comment
@jk

jk Apr 17, 2012

Yeah, perhaps even specify the channels/rooms where the message will be echoed.

jk commented Apr 17, 2012

Yeah, perhaps even specify the channels/rooms where the message will be echoed.

@tombell

This comment has been minimized.

Show comment Hide comment
@tombell

tombell Apr 17, 2012

Contributor

I'll work on an example script as an example starting point and put it on the wiki as soon as possible. I'm also working on an ebook that will details everything about hubot. An outline can be found here https://github.com/tombell/learnhubotthehardway/blob/master/TODO.md and you can sign up for notifications here http://leanpub.com/learnhubotthehardway

Contributor

tombell commented Apr 17, 2012

I'll work on an example script as an example starting point and put it on the wiki as soon as possible. I'm also working on an ebook that will details everything about hubot. An outline can be found here https://github.com/tombell/learnhubotthehardway/blob/master/TODO.md and you can sign up for notifications here http://leanpub.com/learnhubotthehardway

@ejfinneran

This comment has been minimized.

Show comment Hide comment
@ejfinneran

ejfinneran Apr 17, 2012

Contributor

This is a custom script I wrote to do the same with XMPP.

module.exports = (robot) ->
  robot.router.get "/message/create", (req, res) ->
    params = require('url').parse(req.url, true)
    message = params["query"]["text"]
    room = params["query"]["room"]
    robot.messageRoom room, message
    res.end "Message Sent"

Then use something like this: curl http://hubot_host:8080/message/create?room=room@chat.server&text=hello

Contributor

ejfinneran commented Apr 17, 2012

This is a custom script I wrote to do the same with XMPP.

module.exports = (robot) ->
  robot.router.get "/message/create", (req, res) ->
    params = require('url').parse(req.url, true)
    message = params["query"]["text"]
    room = params["query"]["room"]
    robot.messageRoom room, message
    res.end "Message Sent"

Then use something like this: curl http://hubot_host:8080/message/create?room=room@chat.server&text=hello

@tombell tombell closed this Apr 17, 2012

@jk

This comment has been minimized.

Show comment Hide comment
@jk

jk Apr 18, 2012

@ejfinneran have you tested it with the irc adapter. I get a undefined hello message inside the hubot stdout. From what I can see the implementation of the irc adapter looks correct.

Any ideas? Perhaps a problem with @userForId in messageRoom and the irc adapter?

jk commented Apr 18, 2012

@ejfinneran have you tested it with the irc adapter. I get a undefined hello message inside the hubot stdout. From what I can see the implementation of the irc adapter looks correct.

Any ideas? Perhaps a problem with @userForId in messageRoom and the irc adapter?

@ejfinneran

This comment has been minimized.

Show comment Hide comment
@ejfinneran

ejfinneran Apr 19, 2012

Contributor

I haven't tried it with IRC before. I wrote that messageRoom function so I'll try to debug it with the IRC adapter this weekend.

Contributor

ejfinneran commented Apr 19, 2012

I haven't tried it with IRC before. I wrote that messageRoom function so I'll try to debug it with the IRC adapter this weekend.

@tombell

This comment has been minimized.

Show comment Hide comment
@tombell

tombell Apr 19, 2012

Contributor

The messageRoom function requires @id to be set, and this isn't set by hubot.

Contributor

tombell commented Apr 19, 2012

The messageRoom function requires @id to be set, and this isn't set by hubot.

@jk

This comment has been minimized.

Show comment Hide comment
@jk

jk Apr 20, 2012

There're already plugins in hubot-scripts which relying on messageRoom like BitBucket.coffee.

@tombell does the xmpp adapter do not need the @id?

jk commented Apr 20, 2012

There're already plugins in hubot-scripts which relying on messageRoom like BitBucket.coffee.

@tombell does the xmpp adapter do not need the @id?

@tombell

This comment has been minimized.

Show comment Hide comment
@tombell

tombell Apr 20, 2012

Contributor

I didn't write messageRoom, I don't know if it works or doesn't work. I personally don't use it in my scripts.

Contributor

tombell commented Apr 20, 2012

I didn't write messageRoom, I don't know if it works or doesn't work. I personally don't use it in my scripts.

@ejfinneran

This comment has been minimized.

Show comment Hide comment
@ejfinneran

ejfinneran Apr 20, 2012

Contributor

It works with the XMPP adapter but I'm not sure about other adapters. I'll poke around and see if there is a better way to write that function.

Contributor

ejfinneran commented Apr 20, 2012

It works with the XMPP adapter but I'm not sure about other adapters. I'll poke around and see if there is a better way to write that function.

@darkamgine

This comment has been minimized.

Show comment Hide comment
@darkamgine

darkamgine May 13, 2012

Hey all,

I was trying to do exactly what jk was trying to do for irc and finally figured out the solution.
There's nothing wrong with ejfinneran's script, but for IRC, the url needs to be in the format

http://hubot_host:8080/message/create?room=%23IRCCHANNELNAME&text=hello

with the # sign encoded as %23 so the room becomes #IRCCHANNELNAME and not IRCCHANNELNAME.

Hope that helps!

edit: hmm actually when the bot is in multiple channels it doesn't send to the right one.

as per this website:
http://blog.iweb-hosting.co.uk/blog/2012/01/21/hubot-http-daemon-support/

instead of using robot.messageroom the following workaround gets it done for irc:

user = robot.userForId 'broadcast'
user.room = room
user.type = 'groupchat'
robot.send user, "#{message}"

Hey all,

I was trying to do exactly what jk was trying to do for irc and finally figured out the solution.
There's nothing wrong with ejfinneran's script, but for IRC, the url needs to be in the format

http://hubot_host:8080/message/create?room=%23IRCCHANNELNAME&text=hello

with the # sign encoded as %23 so the room becomes #IRCCHANNELNAME and not IRCCHANNELNAME.

Hope that helps!

edit: hmm actually when the bot is in multiple channels it doesn't send to the right one.

as per this website:
http://blog.iweb-hosting.co.uk/blog/2012/01/21/hubot-http-daemon-support/

instead of using robot.messageroom the following workaround gets it done for irc:

user = robot.userForId 'broadcast'
user.room = room
user.type = 'groupchat'
robot.send user, "#{message}"
@ejfinneran

This comment has been minimized.

Show comment Hide comment
@ejfinneran

ejfinneran Jun 25, 2012

Contributor

@jk, I finally got some time to spin up an IRC server and give this shot. With hubot version 2.2.0 and the IRC adapter 0.0.8, I'm able to use the messageRoom function with the bot in multiple channels without any issues.

I did have to escape the # symbol in the URL just like in the example above but other than that, everything worked just fine. I used this curl command:
curl "http://localhost:8080/message/create?room=%23room1&message=test"

A snapshot of the setup I used is here: https://github.com/ejfinneran/example-irc-message-room

If you're still having issues using the messageRoom function, let me know. I added it so I want to make sure it's working with as many adapters as possible.

EDIT: Bah, of course as soon as I submitted this, I was able to recreate the issue where Hubot pings the wrong channel. :-/

I'll dig into that.

Contributor

ejfinneran commented Jun 25, 2012

@jk, I finally got some time to spin up an IRC server and give this shot. With hubot version 2.2.0 and the IRC adapter 0.0.8, I'm able to use the messageRoom function with the bot in multiple channels without any issues.

I did have to escape the # symbol in the URL just like in the example above but other than that, everything worked just fine. I used this curl command:
curl "http://localhost:8080/message/create?room=%23room1&message=test"

A snapshot of the setup I used is here: https://github.com/ejfinneran/example-irc-message-room

If you're still having issues using the messageRoom function, let me know. I added it so I want to make sure it's working with as many adapters as possible.

EDIT: Bah, of course as soon as I submitted this, I was able to recreate the issue where Hubot pings the wrong channel. :-/

I'll dig into that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment