Created
December 18, 2011 17:39
-
-
Save DazWorrall/1494013 to your computer and use it in GitHub Desktop.
A hubot http listening server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
Sorry, we run our own hubot internally so haven't tried it on Heroku.
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
You got it to work hosted in Heroku?