-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpush.js
33 lines (29 loc) · 997 Bytes
/
push.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
let webPush = require('web-push');
const vapidKeys = {
"publicKey": "BIfnd2TKnrPWEshPq-XbQh_lLmDVGA5tTHc9dOHlNj1Uo6lLJmgpQSWqiKQItJQ1et-pvGJDvvRyxn3H0tBizxo",
"privateKey": "HK51x75E2NJMniOjaJiVdhCuGkPtgbOkE1BixzNQp24"
};
webPush.setVapidDetails(
'mailto:[email protected]',
vapidKeys.publicKey,
vapidKeys.privateKey
)
let pushSubscription = {
"endpoint": "https://fcm.googleapis.com/fcm/send/c-1KXqq5SFo:APA91bEJ_2z9YQNbrYwyYA9qG0HYfmPsuvNPBRs06nohNtsRslW2OBgNW9kGOs7ecUU2kPUgSEU7D0bJWe_ha0TZvYNL6_6TVjGQdTeq0nndul6O--YuzxYtF4CvXweSeMoqjyuPqE8t",
"keys": {
"p256dh": "BEQ7rzMScSvijQxfJF7mIjsGEd2qIOSTILccZviVp7Uk7uneH/zabMYSwZ4WB214OsubMmz9APTyolnoD6mHEjA=",
"auth": "Okd6PR49F3TeXmVz2gEgzQ=="
}
};
let payload = 'Selamat! Aplikasi Anda sudah dapat menerima push notifikasi!';
let options = {
gcmAPIKey: '772472312233',
TTL: 60
};
webPush.sendNotification(
pushSubscription,
payload,
options
).catch(err => {
console.log(err)
})