Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamic Push Notifications

Tags:

firebase

I know that Firebase has recently added support for Push Notifications and while this is a great thing, I only seem to be able to send push notifications manually via the Notifications Panel.

What I'd like to do is to send push notifications within a user scope...Let me explain that. Each User in my App has an account and then each user can join a group. Within this group the user can perform tasks and has a list of chores to do. Now when certain tasks are due for example I want to remind the user of doing it with a push notification. For 1-10 I might be able to pull this off manually, but is there a way to dynamically based on the data in the Database send out Push Notifications?

I know that certain Push Notifications can be created using the Analytics tool such as "Hey you have not visited for 3 days, please come back whatever"... but I'd like to register push notifications such as "I just created a task, this task needs to be done within 3 days. Remind me in 3 days if the task is still not done".

Is this possible with Firebase or do I need to have my own server connecting to Firebase and handling those events?

-xCoder

like image 374
Janosch Hübner Avatar asked May 20 '16 08:05

Janosch Hübner


2 Answers

You need to implement FCM in your client and in a server. Let me put this straight:

First, you need that your client, or app, to register into FCM and get a FCM token that will be used to identify that device uniquely.

Then, store that token wherever you like. It can be into firebase database or other server you may like. I recommend you to store it into firebase if you are using it as a database for your users; that's my case.

Also, you need to implement a http or xmpp server in order to send FCM messages to your registered devices containing the data you are interested in. For example, you can implement a Google App Engine endpoint (can be done with Android Studio and Java) that is quite simple or a NodeJS module, depending on your preferred language.

If you are using Firebase as database you can connect from your server with the appropriate SDK and get the FCM tokens you want from your users, and then send the message to those with data. Don't forget to secure your serve.

The way you implement your server algorithm to send FCM messages depends on your app purposes.

Hope it is clear enough for you. Also you can find all the documentation with a short video that explains the general structure here: https://firebase.google.com/docs/cloud-messaging

like image 52
MrBrightside Avatar answered Sep 30 '22 13:09

MrBrightside


You can use cloud functions to trigger on any create, update or delete operation in your database and in the trigger event, you can choose to send in FCM push notifications to the devices of your choice.

Here is the documentation regarding the use and structure of a cloud function: https://firebase.google.com/docs/firestore/extend-with-functions

Hope this helps!

like image 22
Kuldip Bhutoria Avatar answered Sep 30 '22 11:09

Kuldip Bhutoria