Sending push notification with Firebase, Firestore & Cloud Functions
Varun Raj, Co-founder and CTO
I hope that you’ve already read my article on sending Slack notifications with Firestore and cloud functions - if not, please check it out here
In our previous articles, we saw how to create a simple Todo application with Firebase’s Firestore and also to create cloud functions that will send a Slack notification when we create a todo or check a todo as complete. Here we’ll be using the same base and build a push notification architecture.
Code from previous article
With the above reference, we can see that the sendMessage function is been called when the triggers are executed. Let’s create another function for pushing notification and call it as pushMessage
Now make your client subscribe to the notifications topic of your Firebase app and they’ll receive notifications whenever these triggers are executed.
And if you need to send push notifications to specific users, get the client’s registration token and push to the corresponding token with sendToDevice and pass the registration token as the parameter.
Putting everything together looks like
Now with above code, you’ll be sending both Slack as well as push notifications. Later if you think you want to send a message to anything like Twilio or Discord, we can also do that. Just the creativity and the use case defines them.
Also do checkout our other articles on Firebase here: