forked from javajuice1337/push-receiver-v2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
39 lines (34 loc) · 948 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
39
// Note: The send endpoint is deprecated and removed as of June 20, 2024: https://firebase.google.com/support/faq#fcm-depr-features
const argv = require('yargs').argv;
const { fetch } = require('../../src/utils/fetch');
const serverKey = argv.serverKey;
const token = argv.token;
if (!serverKey) {
console.error('Missing serverKey argument');
process.exit(171);
}
if (!token) {
console.error('Missing token argument');
process.exit(171);
}
(async () => {
try {
const response = await fetch('https://fcm.googleapis.com/fcm/send', {
method : 'POST',
body : JSON.stringify({
to : token,
notification : {
title : 'Hello world',
body : 'Test',
},
}),
headers : {
Authorization : `key=${serverKey}`,
'Content-Type' : 'application/json',
},
});
console.log(response);
} catch (e) {
console.error(e.message);
}
})();