Sending multiple notifications using FCF

Updated 30 October 2017

Save

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

 

 

author
. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

Start a Project


    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home