WebGAP Notifier
README
This is the WebGAP Notifications Management module.
Handles abstraction for multiple notification mechanisms.
Dependencies
Handles logging using @webgap/logger.
Handles objects using @webgap/object-utils.
Handles date format using @webgap/format-utils.
Loads default configuration using @webgap/configuration.
Generates IDs using node-uuid.
Handles Strings using string.
Requirements
A configuration file must exist
(check @webgap/configuration documentation).
API
Installation
npm install @webgap/notifier --save
Usage
var Notifier = require('@webgap/notifier').Notifier,
Notification = Notifier.Notification,
Message = Notification.Message,
notifier = new Notifier();
function EmailSystem() {}
EmailSystem.prototype.notify = function (options, callback) {
console.log('\nEmail system send message: ' + JSON.stringify(options.notification));
return callback();
};
notifier.register('EMAIL', EmailSystem);
...
...
notifier.setDefaultNotificationSystem({notificationSystem: notifier.systems.EMAIL});
var notification = new Notification({
userId: 'id of the user to notify',
message: new Message({
key: 'messages.error.text',
data: { errorCode: 111 }
})
});
notifier.notify({notification: notification}, function callback(err) {
err && console.log(err);
});
...
notifier.notify({notificationSystems: [notifier.systems.EMAIL, notifier.systems.OTHER], notification: notification}, function callback(err) {
err && console.log(err);
});
License
Apache License, Version 2.0