Created
September 4, 2022 06:06
-
-
Save vaibhavgehani/d1d87ca85090b3447a3de72d539e84dd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const FCM = require('fcm-node'); | |
| // put your server key here | |
| const serverKey = '<your-server-key>'; | |
| const fcm = new FCM(serverKey); | |
| function sendNotificationToFirebase(message) { | |
| return new Promise((resolve, reject) => { | |
| fcm.send(message, (err, response) => { | |
| if (err) { | |
| console.log('Something has gone wrong!', JSON.stringify(err)); | |
| reject(err); | |
| } else { | |
| console.log('Successfully sent with response: ', response); | |
| resolve(response); | |
| } | |
| }); | |
| }); | |
| } | |
| async function sendChatAppMessage(tokens, badgeNumber) { | |
| const message = { | |
| registration_ids: tokens, | |
| notification: { | |
| title: 'New Notification', | |
| body: 'You have received notification', | |
| badge: badgeNumber | |
| }, | |
| priority: 'high', | |
| }; | |
| const response = await sendNotificationToFirebase(message); | |
| return response; | |
| } | |
| module.exports = { | |
| sendChatAppMessage | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment