From d90903a8348507acc7dbcc36631af3919b1bfcd2 Mon Sep 17 00:00:00 2001 From: Raffael Schmid Date: Sat, 26 Jan 2013 18:59:22 +0100 Subject: [PATCH] add http post say listener --- src/scripts/http-post-say.coffee | 40 ++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/scripts/http-post-say.coffee diff --git a/src/scripts/http-post-say.coffee b/src/scripts/http-post-say.coffee new file mode 100644 index 000000000..f52bd85c2 --- /dev/null +++ b/src/scripts/http-post-say.coffee @@ -0,0 +1,40 @@ +# Description: +# "Accepts POST data and broadcasts it" +# +# Dependencies: +# None +# +# Configuration: +# None +# +# Commands: +# None +# +# URLs: +# POST /hubot/say +# message = +# room = +# +# curl -X POST http://localhost:8080/hubot/say -d message=lala -d room='#dev' +# +# Author: +# insom +# luxflux + +module.exports = (robot) -> + robot.router.post "/hubot/say", (req, res) -> + + room = req.body.room + message = req.body.message + + robot.logger.info "Message '#{message}' received for room #{room}" + + user = robot.adapter.userForId 'broadcast' + user.room = room + user.type = 'groupchat' + + if message + robot.send user, "#{message}" + + res.writeHead 200, {'Content-Type': 'text/plain'} + res.end 'Thanks\n'