Skip to content
This repository has been archived by the owner on Jun 8, 2023. It is now read-only.

Commit

Permalink
http-post-say and http-say support hubot-xmpp
Browse files Browse the repository at this point in the history
  • Loading branch information
bolasblack committed Sep 8, 2014
1 parent 0d6897d commit b6328f5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
14 changes: 8 additions & 6 deletions src/scripts/http-post-say.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# POST /hubot/say
# message = <message>
# room = <room>
# type = <type>
#
# curl -X POST http://localhost:8080/hubot/say -d message=lala -d room='#dev'
#
Expand All @@ -23,15 +24,16 @@

module.exports = (robot) ->
robot.router.post "/hubot/say", (req, res) ->

room = req.body.room
message = req.body.message
body = req.body
room = body.room
message = body.message

robot.logger.info "Message '#{message}' received for room #{room}"

user = robot.brain.userForId 'broadcast'
user.room = room
user.type = 'groupchat'
envelope = robot.brain.userForId 'broadcast'
envelope.user = {}
envelope.user.room = envelope.room = room if room
envelope.user.type = body.type or 'groupchat'

if message
robot.send user, "#{message}"
Expand Down
11 changes: 6 additions & 5 deletions src/scripts/http-say.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# None
#
# URLs:
# GET /hubot/say?message=<message>[&room=<room>&type=<type]
# GET /hubot/say?message=<message>[&room=<room>&type=<type>]
#
# Author:
# ajacksified
Expand All @@ -22,10 +22,11 @@ module.exports = (robot) ->
robot.router.get "/hubot/say", (req, res) ->
query = querystring.parse(req._parsedUrl.query)

user = {}
user.room = query.room if query.room
user.type = query.type if query.type
envelope = {}
envelope.user = {}
envelope.user.room = envelope.room = query.room if query.room
envelope.user.type = query.type or 'groupchat'

robot.send(user, query.message)
robot.send envelope, query.message

res.end "Said #{query.message}"

0 comments on commit b6328f5

Please sign in to comment.