I am able to send notifications to android and apple devices using the "Compose notification" on firebase.
I am trying to send a message using cloud functions but I am having a hard time.
I can see all the data I want from the following code snip (cloud function)
const functions = require("firebase-functions");
const admin = require("firebase-admin");
admin.initializeApp();
exports.onUpdate = functions.firestore
.document("chat messages/{docId}")
.onCreate((snapshot, context) => {
console.log("1");
console.log(snapshot.data());
console.log("2");
console.log(snapshot.data()["User id"] );
console.log(snapshot.data()["Chat message"] );
console.log("3");
});
now I need to target the phone to send the notification.
How do I do this?
2
Answers
here is the solution that worked for me
Did you see the FCM documentation on sending messages, specifically on sending to a specific device?
I also recommend having a look at the Cloud Functions sample on notifying the user when something interesting happens. While it triggers on the Realtime Database instead of Firestore, the approach will be very similar to what you need.