Created
May 7, 2015 18:41
-
-
Save jeff-hager-dev/1e193b7bed39f0042a2c to your computer and use it in GitHub Desktop.
Hipchat Cron Notifier
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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