hubot-scripts
Version:
Allows you to opt in to a variety of scripts
55 lines (44 loc) • 1.53 kB
text/coffeescript
querystring = require('querystring')
module.exports = (robot) ->
robot.router.get "/hubot/hipchat", (req, res) ->
https = require 'https'
query = querystring.parse(req._parsedUrl.query)
hipchat = {}
hipchat.format = 'json'
hipchat.auth_token = process.env.HUBOT_HIPCHAT_TOKEN
hipchat.room_id = query.room_id if query.room_id
hipchat.message = query.message if query.message
hipchat.from = query.from if query.from
hipchat.color = query.color if query.color
hipchat.notify = query.notify if query.notify
hipchat.message_format = query.message_format if query.message_format
params = querystring.stringify(hipchat)
path = "/v1/rooms/message/?#{params}"
data = ''
callback = ->
res.end data
https.get {host: 'api.hipchat.com', path: path}, (res) ->
res.on 'data', (chunk) ->
data += chunk.toString()
res.on 'end', () ->
json = JSON.parse(data)
console.log "Hipchat response ", data
callback()