Skip to content

Instantly share code, notes, and snippets.

@Furzel
Created November 21, 2013 22:45
Show Gist options
  • Save Furzel/7591197 to your computer and use it in GitHub Desktop.
Save Furzel/7591197 to your computer and use it in GitHub Desktop.
Quick message sender for hipchat API. There is two way to send a message : either create a new sender with new Sender() and call mySender.send() to fire messages or use sendMessage if you need to send only one message with this configuration.
var hipchat = require('hipchat-js')("*** API TOKEN HERE ****");
exports.Sender = function(roomId, senderName, messageFormat, notify) {
this.roomId = roomId;
this.senderName = senderName;
this.notify = notify;
this.messageFormat = messageFormat;
this.send = function(message, color) {
if (!color)
color = "yellow";
hipchat.apiCall('POST', '/rooms/message', {
room_id: this.roomId,
from: this.senderName,
message: message,
message_format: this.messageFormat,
notify: this.notify,
color: color
}, function(err, resp) {
if (!err)
console.log(err.message);
});
};
};
exports.sendMessage = function(roomId, senderName, message, messageFormat, notify, color) {
hipchat.apiCall('POST', '/rooms/message', {
room_id: roomId,
from: senderName,
message: message,
message_format: messageFormat,
notify: 0,
color: color
}, function (err, resp) {
if (!err) {
console.log(resp);
} else {
console.log(err.message);
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment