-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathexample.js
51 lines (42 loc) · 1.31 KB
/
example.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
const process = require('process');
const Constants = require("./google/Constants");
const { Sender, Message, Notification } = require("./index");
const SenderID = "";
const ServerKey = "";
const xcs = new Sender(SenderID, ServerKey, Constants.FCM_DEVELOPMENT_IDX, true);
function sendMessage(xcs) {
const notification = new Notification("ic_launcher")
.title("Hello buddy!")
.body("node-xcs is awesome.")
.build();
const message = new Message("messageId_1047")
.priority("high")
.dryRun(false)
.addData("node-xcs", true)
.addData("anything_else", false)
.addData("awesomeness", 100)
// .deliveryReceiptRequested(true)
.notification(notification)
.build();
//
xcs.start();
const to = '';
xcs.sendNoRetry(message, to, function (result) {
if (result.getError()) {
console.error(result.getErrorDescription());
} else {
console.log("message sent: #" + result.getMessageId());
}
});
xcs.stop();
}
(async function () {
xcs.on('message', function (messageId, from, data, category) {
console.log('received message', arguments);
});
xcs.on('connected', (connectionType) => {
sendMessage(xcs);
});
await xcs.start();
})();
process.stdin.resume();