Skip to content

Instantly share code, notes, and snippets.

@DazWorrall
Created December 18, 2011 17:39
Show Gist options
  • Save DazWorrall/1494013 to your computer and use it in GitHub Desktop.
Save DazWorrall/1494013 to your computer and use it in GitHub Desktop.
A hubot http listening server
# Inspired by http://tomb.io/posts/hubot-ci-and-deploying/
# Its probably tightly bound to the xmpp adapter, and incorrect
# in loads of ways, but its a start.
# POST a json document to /message containing 'room' (the JID of the room
# you want to talk to) and 'message' (the message you want to send)
http = require "http"
Robot = require '../src/robot'
module.exports = (robot) ->
server = http.createServer (req, res) ->
if req.url is "/message"
data = ""
req.setEncoding "utf8"
req.on "data", (chunk) ->
data += chunk
req.on "end", ->
json = JSON.parse data
room = json.room
message = json.message
robot.logger.info "Message '#{message}' received for room #{room}"
user = robot.userForId 'broadcast'
user.room = room
user.type = 'groupchat'
robot.receive new Robot.TextMessage user, "http message #{message}"
res.writeHead 200, {'Content-Type': 'text/plain'}
res.end 'Thanks\n'
server.listen 9292, "0.0.0.0"
robot.hear /http message (.*)/i, (msg) ->
text = msg.match[1]
msg.send text
@felipecsl
Copy link

You got it to work hosted in Heroku?

@DazWorrall
Copy link
Author

Sorry, we run our own hubot internally so haven't tried it on Heroku.

@insom
Copy link

insom commented Jan 18, 2012

But this works on Heroku :D — https://gist.github.com/1633778

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