Sending multiple notifications using FCF

Firebase Cloud Functions are still in their Beta phase but I still think its the best Feature of Firebase, making any things easier for developers. In one of my previous blog, I presented a method to send notification message to a Firebase Notification key if there is a new message for that user. Now I am here to provide you a way to send messages to multiple notification keys or tokens whenever there is a new message for that person or group, whatever the case is for you.

For that firstly lets see our database structure first. So this is the database structure. There are two main sub-sections namely data and messages. The data part contains customer data while the message part contains the messages exchanged between people.database structureAs we can not enter single token values under tokens filed because its a json-based database, I used the one defined in Firebase sample i.e. to use token value as key and giving value true against the json value. You can provide any other value if you want.

So now lets move on to writing the event function. So all the process is same just we need a iterator to iterate through all the values in tokens so we are using method Promise.all() The final method I got is as

And here you got to send message to multiple tokens whenever a new message is added to the particular sender node.

Source: https://github.com/firebase/functions-samples/tree/master/fcm-notifications

 

 

. . .

Comment

Add Your Comment

Be the first to comment.

css.php
Hire Us!
Brief us about your requirements and we'll get back to you.
Woo! Hooy!
We have just recieved your project brief and our expert will contact you shortly.
Send Again
Close