Last active
November 25, 2020 11:55
-
-
Save ismummy/dcd0203aebd352934ccfe61e8f873388 to your computer and use it in GitHub Desktop.
Firbase push notification helper class
This file contains 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
require('dotenv').config(); | |
const FCM = require('fcm-node'); | |
const serverKey = process.env.GOOGLE_API_KEY; | |
const fcm = new FCM(serverKey); | |
class FCMHandler { | |
static sentToTopic(topic, flag, message) { | |
const msg = { | |
to: `/topics/${topic}`, | |
notification: { | |
title: topic, | |
body: topic | |
}, | |
data: { | |
title: topic, | |
flag: flag, | |
data: message | |
} | |
}; | |
this.send(msg); | |
} | |
static send(message) { | |
fcm.send(message, function (err, response) { | |
if (err) { | |
console.log("Something has gone wrong!"); | |
} else { | |
console.log("Successfully sent with response: ", response); | |
} | |
}); | |
} | |
} | |
module.exports = FCMHandler; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment