app-notify
Send Twilio SMS and SMTP email notifications from within your node.js app
install
npm install app-notify
const Notify = require('app-notify');
const cfg = {...};
const notify = new Notify(cfg);
usage (promises)
Send an email message:
const cfg = {};
cfg.smtp = {
host: xxx,
user: user,
pass: pass,
port: port
};
cfg.email = {
to: 'user@example.com',
from: 'sender@example.com'
};
const Notify = require('app-notify');
const notify = new Notify(cfg);
notify.email({
subject: 'This is a test',
message: 'Hello world!'
})
.then(function(data){
console.log(data);
})
.catch(function(err){
console.error(err);
});
Send an SMS message
const cfg = {};
cfg.sms = {
sid: 'twilio-sid-id',
auth: 'twilio-auth-id',
to: 'xxx-xxx-xxxx',
from: 'yyy-yyy-yyyy'
};
const Notify = require('app-notify');
const notify = new Notify(cfg);
notify.sms({
message: 'Hello world'
})
.then(function(data){
console.log(data);
})
.catch(function(err){
console.error(err);
});
Send to whichever services we have enabled (both sms and email):
const cfg = {};
cfg.smtp = {
host: xxx,
user: user,
pass: pass,
port: port
};
cfg.email = {
to: 'user@example.com',
from: 'sender@example.com'
};
const Notify = require('app-notify');
const notify = new Notify(cfg);
notify.send({
subject: 'This is a test',
message: 'Hello world'
});
notify.cfg.email.disabled = true;
notify.send({
message: 'Hello world',
});
usage (callbacks)
app-notify can be used with callbacks too!
run tests
gulp test