Skip to content

Instantly share code, notes, and snippets.

@luxflux
Forked from insom/listener.coffee
Last active December 11, 2015 18:39
Show Gist options
  • Save luxflux/4643449 to your computer and use it in GitHub Desktop.
Save luxflux/4643449 to your computer and use it in GitHub Desktop.
# Description:
# "Accepts POST data and broadcasts it"
#
# Dependencies:
# None
#
# Configuration:
# None
#
# Commands:
# None
#
# URLs:
# POST /hubot/say
# message = <message>
# room = <room>
#
# curl -X POST http://localhost:8080/hubot/say -d message=lala
#
# 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'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment