Skip to content

Commit

Permalink
add to readme. fix package.json to remove fs. fix some comment typos
Browse files Browse the repository at this point in the history
  • Loading branch information
aaaschmitt committed Jan 14, 2016
1 parent f649eca commit 32313e7
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 17 deletions.
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,27 @@ Bonus: Add a notification hook to Heroku so a notification is sent to a room whe
robot.messageRoom("[email protected]", "message");
```

## hubot-hipchat specific featues

In addition to the response methods provided by the normal hubot, such as ```resp.send```, hubot-hipchat provides these hipchat specific functions:
* ```resp.sendHtml``` takes any number of strings and sticks them together as one html message post. For example, you can send a hyperlink by doing this:
```
robot.respond /send hyperlink/i, (resp)->
resp.sendHtml "<a href='https://hipchat.com'>hipchat site</a>"
```

* ```resp.sendFile``` takes an object that contains either file data or a path to a file along with other file info and posts the file to a room with an optional message:
```
robot.respond /send file/i, (resp) ->
file_info =
name : "the name people will see in the room"
path : 'path/to/file.text'
type: "text" # required
msg : "optional message to post when file is uploaded"
resp.sendFile file_info
```

## Adapter configuration

This adapter uses the following environment variables:
Expand Down Expand Up @@ -135,6 +156,10 @@ Optional. Set to `debug` to enable detailed debug logging.

Optional. Seting to `false` will prevent the HipChat adapter from auto-reconnecting if it detects a server error or disconnection.

### HUBOT\_HIPCHAT\_TOKEN

Optional. Set to the value of an API token for HipChat. Generate an API token [here](https://cs10.hipchat.com/account/api) (and give it the necessary scopes to post in rooms, the easiest way is just give it access to all scopes). This needs to be set in order to use the sendFile and sendHtml methods.

## Running locally

To run locally on OSX or Linux you'll need to set the required environment variables and run the `bin/hubot` script. An example script to run the bot might look like:
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"node": "~0.12.2"
},
"dependencies": {
"fs": "0.0.2",
"mime": "^1.3.4",
"node-xmpp-client": "^2.1.0",
"request": "^2.67.0",
Expand Down
28 changes: 14 additions & 14 deletions src/hipchat.coffee
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
{Adapter, TextMessage, EnterMessage, LeaveMessage, TopicMessage, User} = require "hubot"
fs = require "fs"
HTTPS = require "https"
{Adapter, TextMessage, EnterMessage, LeaveMessage, TopicMessage, User} = require "hubot"
{inspect} = require "util"
requestLib = require "request" # requestLib to avoid confusion with adapter's request method
mime = require "mime"
Connector = require "./connector"
promise = require "./promises"
requestLib = require "request"
fs = require 'fs'
mime = require 'mime'
HipchatResponse = require './response'
HipChatResponse = require './response'

class HipChat extends Adapter

constructor: (robot) ->
super robot
@logger = robot.logger
@room_endpoint = "http://www.hipchat.com/v2/room"
@robot.Response = HipchatResponse
@robot.Response = HipChatResponse
reconnectTimer = null

emote: (envelope, strings...) ->
Expand Down Expand Up @@ -49,7 +49,7 @@ class HipChat extends Adapter
return @logger.error "Not sure who to send html message to: envelope=#{inspect envelope}"

if not @options.token
return @logger.error "A hubot api token must be set to send html messages"
return @logger.error "Must set HUBOT_HIPCHAT_TOKEN to send html messages"

room_id = @room_map[target_jid].id
fullMsg = strings.join('')
Expand All @@ -64,10 +64,10 @@ class HipChat extends Adapter

requestLib.post params, (err,resp,body) =>
if err || resp.statusCode >= 400
return @logger.error "Hipchat API error: #{resp.statusCode}"
return @logger.error "HipChat API error: #{resp.statusCode}"

# Send a file from hubot
# options =
# file_info =
# name : the name to share the file with
# path : send file from this path (a string)
# data : send this base64 encoded data as a file
Expand All @@ -80,7 +80,7 @@ class HipChat extends Adapter
return @logger.error "Not sure who to send file to: envelope=#{inspect envelope}"

if not @options.token
return @logger.error "A hubot api token must be set to send html messages"
return @logger.error "Must set HUBOT_HIPCHAT_TOKEN to send html messages"

room_id = @room_map[target_jid].id
url = "#{@room_endpoint}/#{room_id}/share/file"
Expand Down Expand Up @@ -108,8 +108,8 @@ class HipChat extends Adapter

sendMultipart: (path, name, data, mimeType, msg) ->

# Weird stuff from the hipchat api
# Must have filename="name" etc... with double quotes not single
# Must have filename="name" etc... in double quotes not single
quotedName = '"' + name + '"'
params =
method: 'POST'
url: path
Expand All @@ -124,14 +124,14 @@ class HipChat extends Adapter
,
{
"Content-Type": "file/" + mimeType,
"Content-Disposition": 'attachment; name="file"; filename="' + name + '"',
"Content-Disposition": 'attachment; name="file"; filename=' + quotedName,
"body": data
}
]

requestLib params, (err, resp, body) =>
if resp.statusCode >= 400
return @logger.error "Hipchat API errror: #{resp.statusCode}"
return @logger.error "HipChat API errror: #{resp.statusCode}"


topic: (envelope, message) ->
Expand Down
4 changes: 2 additions & 2 deletions src/response.coffee
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{Response} = require 'hubot'

class HipchatResponse extends Response
class HipChatResponse extends Response

sendFile: (file_info) ->
@robot.adapter.sendFile(@envelope, file_info)

sendHtml: (strings...) ->
@robot.adapter.sendHtml(@envelope, strings...)

module.exports = HipchatResponse
module.exports = HipChatResponse

0 comments on commit 32313e7

Please sign in to comment.