A notifications module for node.js
npm install notifier
sh
$ npm install notifier
`
or include it in package.json
NOTE: Sending emails is disabled in 'development' and 'test' environment. (instead it will log to console)
Usage
`js
var notifier = new Notifier({
service: 'postmark' // or 'sendgrid'
APN: true,
email: true,
tplType: 'ejs', // if you want to use ejs as templating system
actions: ['comment', 'like'],
tplPath: require('path').resolve(__dirname, './templates'),
key: 'SERVICE_KEY',
sendgridUser: 'SENDGRID_USER',
parseAppId: 'APP_ID',
parseApiKey: 'MASTER_KEY'
});
var comment = {
to: 'Tom',
from: 'Harry'
};
var options = {
to: 'tom@madhums.me',
subject: 'Harry says Hi to you',
from: 'harry@madhums.me',
locals: comment // should be the object containing the objects used in the templates
};
notifier.use({
parseChannels: ['USER_5093a266180b779762000005']
});
// OR
// options.parseChannels = ['USER_5093a266180b779762000005']
notifier.send('comment', options, function (err) {
if (err) return console.log(err);
console.log('Successfully sent Notifiaction!');
});
`
If you want to use a different templating engine like ejs or something else then just override the processTemplate method. And don't forget to use the tplType config option
For example
`js
Notifier.prototype.processTemplate = function (tplPath, locals) {
var ejs = require('ejs')
locals.filename = tplPath
var tpl = require('fs').readFileSync(tplPath, 'utf8')
return ejs.render(tpl, locals)
}
`
Tests
`sh
$ npm test
``