-
Notifications
You must be signed in to change notification settings - Fork 1
/
fcm_send.js
34 lines (28 loc) · 870 Bytes
/
fcm_send.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
const args = process.argv
// const message = {
// tokens:
// ['dJvrnRox8U17mlQYivrh4l:APA91bHr7gHs_hAmHwVPsEitWaCygQ06xAU4gBGif3BpoozKLtcRIzqU4Y_UW5pWWfBYUwFC-ZcWwQAECthI8G1tTMyHAJKcvdnDg9Pi_O3u9SOEYvapbzV6p3ilA1CNBFRIKu_mI6HN'],
// // tokens:,
// notification: {
// title: 'title',
// body: 'body',
// },
// android: {
// priority: 'high',
// },
// }
const message = JSON.parse(args[2])
const serviceAccount = JSON.parse(args[3])
const admin = require('firebase-admin')
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
})
async function sendPushNotification() {
try {
const response = await admin.messaging().sendEachForMulticast(message)
console.log('Message sent successfully:', response)
} catch (error) {
console.error('Error sending message:', error.message)
}
}
sendPushNotification()