Skip to content

Instantly share code, notes, and snippets.

@jeff-hager-dev
Created May 7, 2015 18:41
Show Gist options
  • Save jeff-hager-dev/1e193b7bed39f0042a2c to your computer and use it in GitHub Desktop.
Save jeff-hager-dev/1e193b7bed39f0042a2c to your computer and use it in GitHub Desktop.
Hipchat Cron Notifier
var HipChatClient = require('hipchat-client'),
CronJob = require('cron').CronJob;
var cfg = {
APIKey: '',
Host: '',
Schedule: '',
FromID: '',
Rooms: [],
notifierSchedule: '',
notifierTimeZone: ''
};
var hipchat = new HipChatClient(cfg.APIKey);
hipchat.host = cfg.Host;
var alertRooms = function (message) {
for (var idx in cfg.Rooms) {
hipchat.api.rooms.message({
room_id: cfg.Rooms[idx],
from: cfg.FromID,
message: message,
}, function (err, res) {
console.log(err || res);
});
}
};
var notifier = function (message) {
return new CronJob({
cronTime: cfg.notifierSchedule,
startNow: true,
timeZone: cfg.notifierTimeZone,
onTick: function () {
var msg = message;
if (typeof (message) == 'function') {
msg = message();
}
alertRooms(msg);
}
});
};
module.exports = {
notifier: notifier,
alertRooms: alertRooms
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment