/
notification_client.js
44 lines (41 loc) · 1.18 KB
/
notification_client.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
var q = require('q'),
NotifyClient = require('notifications-node-client').NotifyClient,
notifyClient = !!process.env.NOTIFICATIONS_ENABLED && new NotifyClient(
process.env.NOTIFY_BASE_URL,
process.env.NOTIFY_SERVICE_ID,
process.env.NOTIFY_SECRET
);
module.exports = {
/**
* @param {String} templateId
* @param {String} emailAddress
* @param {Object} personalisation
*
* @returns {Promise}
*/
sendEmail: function(templateId, emailAddress, personalisation) {
var deferred = q.defer();
if (!!notifyClient) {
return notifyClient.sendEmail(templateId, emailAddress, personalisation);
} else {
deferred.reject('Notification sending not enabled');
return deferred.promise;
}
},
/**
* @param {String} templateId
* @param {String} phoneNumber
* @param {Object} personalisation
*
* @returns {Promise}
*/
sendSms: function(templateId, phoneNumber, personalisation) {
var deferred = q.defer();
if (!!notifyClient) {
return notifyClient.sendSms(templateId, phoneNumber, personalisation);
} else {
deferred.reject('Notification sending not enabled');
return deferred.promise;
}
}
};