-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotifications.js
More file actions
57 lines (45 loc) · 1.62 KB
/
Copy pathnotifications.js
File metadata and controls
57 lines (45 loc) · 1.62 KB
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
var https = require('https');
class Notifications {
/* Set Content of the message as Array */
setMessage(app_id,messageHeadings,messageContents,playerIds,segments) {
return {
app_id: app_id,
headings: messageHeadings,
contents: messageContents,
include_player_ids: playerIds,
included_segments: segments,
priority:"high",
send_after:"now"
};
}
/* Send Push Notifications */
sendNotification(messageHeadings,messageContents,playerIds=false,app_id="YOUR-APP-ID",rest_key="YOUR-APP-KEY") {
var send = function(data) {
var headers = {
"Content-Type": "application/json; charset=utf-8",
"Authorization": rest_key,
};
var options = {
host: "onesignal.com",
port: 443,
path: "/api/v1/notifications",
method: "POST",
headers: headers
};
var req = https.request(options, function(res) {
res.on('data', function(data) {
console.log("Response:");
console.log(JSON.parse(data));
});
});
req.on('error', function(e) {
console.log("Error:");
console.log(e);
});
req.write(JSON.stringify(data));
req.end();
};
send(this.setMessage(app_id,messageHeadings,messageContents,playerIds!=false ?playerIds:[null],playerIds==false?["All"]:[null]));
}
}
module.exports = Notifications;