forked from MatthieuLemoine/push-receiver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
38 lines (34 loc) · 761 Bytes
/
index.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
const request = require('request-promise');
const argv = require('yargs').argv;
const serverKey = argv.serverKey;
const token = argv.token;
if (!serverKey) {
console.error('Missing serverKey argument');
return;
}
if (!token) {
console.error('Missing token argument');
return;
}
(async () => {
try {
const response = await request({
method : 'POST',
url : 'https://fcm.googleapis.com/fcm/send',
json : true,
body : {
to : token,
notification : {
title : 'Hello world',
body : 'Test',
},
},
headers : {
Authorization : `key=${serverKey}`,
},
});
console.log(response);
} catch (e) {
console.error(e.message);
}
})();