-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
63 lines (61 loc) · 2.48 KB
/
app.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
var request = require('request');
var Promise = require('bluebird');
module.exports.sendPush = function sendPush(config) {
if (!config.deepLinks) config.deepLinks = {};
return new Promise(function (resolve, reject) {
request({
url: 'https://api.appboy.com/messages/send',
method: 'POST',
json: {
"app_group_id": config.groupId,
"external_user_ids": config.recipients,
"segment_id": config.segmentId,
"campaign_id": config.campaignId,
"override_frequency_capping": config.freqCap,
"recipient_subscription_state": config.subState,
"messages": {
"apple_push": config.silent ?
{
"content-available": config.contentAvailable,
"badge": config.badge
} : {
"content-available": config.contentAvailable,
"alert": config.text,
"title": config.title,
"badge": config.badge,
"sound": config.alert,
"custom_uri": config.deepLinks["ios"]
},
"android_push": config.silent ?
{
"send_to_sync": config.contentAvailable
} : {
"alert": config.text,
"title": config.title,
"sound": config.alert,
"custom_uri": config.deepLinks["android"]
},
"kindle_push": {
"alert": config.text,
"title": config.title,
"sound": config.alert,
"custom_uri": config.deepLinks["kindle"],
},
"web_push": {
"alert": config.text,
"title": config.title,
"custom_uri": config.deepLinks["web"],
}
}
}
}, function (error, response, body) {
if (error) {
console.log(error, config);
reject(error);
} else {
console.log(response.statusCode, body, config);
resolve(body);
}
});
});
}