I am pretty new in Javascript and through some Google help I have written below function in index.js to send push message to my app when the Firestore table will be update.
Index.js
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.sendNotificationToFCMToken = functions.firestore.document('REQ/{mId}/Req/{bId}').onWrite(async (event) => {
//const uid = event.after.get('userUid');
const title = event.after.get('personName');
const content = event.after.get('content');
const fcmToken = event.after.get('token');
//let userDoc = await admin.firestore().doc(`users/${uid}`).get();
//let fcmToken = userDoc.get('token');
var message = {
notification: {
title: title,
body: content,
},
token: fcmToken,
}
let response = await admin.messaging().send(message);
console.log(response);
});
The above function is properly working and sending push message to the app and showing the notification. But the problem is it should come to the app inside FirebaseMessagingService class through which I can able to customize it.