Created
February 25, 2023 04:23
-
-
Save benixal/259b420596127cb1e553bc56bc52808b to your computer and use it in GitHub Desktop.
firebase cloud messaging admin send push notification
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
// full project with vue: https://github.com/benixal/vue-firebase-push-notification | |
var admin = require("firebase-admin"); | |
var serviceAccount = require("./your-private-key.json"); | |
admin.initializeApp({ | |
credential: admin.credential.cert(serviceAccount) | |
}); | |
// This registration token comes from the client FCM SDKs. | |
const registrationToken = 'cJJ0pXh6KaXu33xeT7pvwD:APA91bFdbv8X6sBxCYIotAulW17OuGapviqI4y3nb4UB_9nGoYv2pE_RakTZQqcC8d99mS-vPjPJzaHmV4cIsbkN2nkTX-IJe3y0fnW2YNw3RZR72xoNhcS4FOTnDLp6gthRvWUKh9Th'; | |
const message = { | |
notification: { | |
title: "I am Admin", | |
body: "Hi client" | |
}, | |
webpush: { | |
fcmOptions: { | |
link: '/?breakingnews' | |
} | |
}, | |
token: registrationToken | |
}; | |
// Send a message to the device corresponding to the provided | |
// registration token. | |
admin.messaging().send(message) | |
.then((response) => { | |
// Response is a message ID string. | |
console.log('Successfully sent message:', response); | |
}) | |
.catch((error) => { | |
console.log('Error sending message:', error); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment