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

Commit 0b3f18d

Browse files
mcdavismcdavis
authored andcommitted
Adding hipchat api route
1 parent 0a36a50 commit 0b3f18d

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

src/scripts/hipchat-api.coffee

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Description:
2+
# Send messages using the Hipchat API (which allows you to choose colors
3+
# and send html messages) instead of the plain old jabber interface
4+
#
5+
# Dependencies:
6+
# "querystring": "0.1.0"
7+
#
8+
# Configuration:
9+
# HUBOT_HIPCHAT_TOKEN - Hipchat API token
10+
#
11+
# Commands:
12+
# None
13+
#
14+
# URLs:
15+
# GET /hubot/hipchat?room_id=<room_id>&message=<message>&from=<from>[&color=<red/yellow/green/gray/purple/random>&notify=<true/false>&message_format=<html/text>]
16+
#
17+
# Author:
18+
# mcdavis
19+
20+
querystring = require('querystring')
21+
22+
module.exports = (robot) ->
23+
robot.router.get "/hubot/hipchat", (req, res) ->
24+
https = require 'https'
25+
query = querystring.parse(req._parsedUrl.query)
26+
27+
hipchat = {}
28+
hipchat.format = 'json'
29+
hipchat.auth_token = process.env.HUBOT_HIPCHAT_TOKEN
30+
31+
hipchat.room_id = query.room_id if query.room_id
32+
hipchat.message = query.message if query.message
33+
hipchat.from = query.from if query.from
34+
hipchat.color = query.color if query.color
35+
hipchat.notify = query.notify if query.notify
36+
hipchat.message_format = query.message_format if query.message_format
37+
38+
params = querystring.stringify(hipchat)
39+
40+
path = "/v1/rooms/message/?#{params}"
41+
42+
data = ''
43+
44+
callback = ->
45+
res.end data
46+
47+
https.get {host: 'api.hipchat.com', path: path}, (res) ->
48+
res.on 'data', (chunk) ->
49+
data += chunk.toString()
50+
res.on 'end', () ->
51+
json = JSON.parse(data)
52+
console.log "Hipchat response ", data
53+
callback()
54+

0 commit comments

Comments
 (0)