Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically send notification to all the users whenever there is any change in firebase [closed]

How do I notify all users when a change is made in firebase? I do not wish to do this manually.

like image 866
benruty Avatar asked Jun 02 '18 10:06

benruty


People also ask

Can Firebase send push notification?

Firebase Cloud Messaging (FCM) provides a reliable and battery-efficient connection between your server and devices that allows you to deliver and receive messages and notifications on iOS, Android, and the web at no cost.


1 Answers

You should use a Firebase Cloud Function tiggered by a Realtime Database trigger, see doc here. Have a look at one of the official Firebase samples for Cloud Functions:

This sample demonstrates how to send a Firebase Cloud Messaging (FCM) notification from a Realtime Database triggered Function. The sample also features a Web UI to experience the FCM notification.

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


If you prefer to send an email, look at the following sample:

https://github.com/firebase/functions-samples/tree/master/email-confirmation

This samples "shows how to send a confirmation emails to users who are subscribing/un-subscribing to a newsletter". It is triggered when a user write some data under as specific Real Time Database node. So it is very similar to your case: when new data is written under a given DB node, the mail is sent.

You can also adapt it in order to use Sengrid, with their library for node.js https://github.com/sendgrid/sendgrid-nodejs. It works very well and is also a recommended solution by Firebase.

In case you encounter difficulties when adapting one of these samples to your case, do not hesitate to share your code and ask for help.

like image 161
Renaud Tarnec Avatar answered Oct 03 '22 00:10

Renaud Tarnec