I am working on a project there i need to implement notifications one day before the expiry of the documents , hour before the pickup etc. And the dates for the expiry and pickup are stored in the database I have to fetch it and send a notification to the user.
I need to implement something that could fetch the data when the expiry is near can i use firebase cloud messaging for the same? or any other ways to do it more efficiently.
Thanks in advance.
If data stored in remote database then there is two possible way.
First, all logic have to implement in remote side and server will send payload for notification, which you have to triggered through FCM.
And secondly, you can call api and implement notification on app side.
Implement a custom Firebase Cloud function that would run on a certain schedule (1h or 5 mins, based on your usecase) and would check if any documents expire within a given timeframe. If you find such documents, issue a FCM to notify the owners of the document.
It is not a good idea to implement this behavior in the app itself because nobody can guarantee that the application will be live at the time when the check should be performed. This is primarily due to android battery optimizations introduced in the latest OS versions.
For more info and examples, look at the following documentation:
Cloud Functions - https://firebase.google.com/docs/functions
Scheduled functions - https://firebase.google.com/docs/functions/schedule-functions
Related
I need some ideas on how I can approach for a feature in a firebase based multi vendor e-commerce app. I want to send a notification to the store owner when the estimated delivery time is over.
When users place a order from a store, an estimated time like 50 minutes will be added to the order info. Now I have to schedule a notification for the owner if it's over 50 minutes and the order status is still pending, the owner will get a notification.
I don't have any code to attach because I am still thinking the approach. My idea is that every store owner will be subscribed to a topic as the storeId or I can send notification using the token of the owner. So only store owner will receive the notification.
But should I schedule the time using a cloud function for every orders or there are other ways to accomplish this?
But should I schedule the time using a cloud function for every orders
or there are other ways to accomplish this?
The notification sending should be triggered by a back-end and Cloud Functions is clearly the most convenient one. You could set up your own server to do so but using a serverless platform like Cloud Functions is much easier.
There are two possible options:
Use a scheduled Cloud Function that checks, each minute, if there are orders for which the estimated delivery time is over, and if it is the case, sends the notification(s). The drawbacks of this approach are: Each minute a Cloud Function is triggered (but there is a generous free tier of 2M invocations/month); similarly, each minute a Firestore query is executed, costing at least one read if the query returns nothing (again, there is a generous free tier of 50K reads/day); finally, you cannot run a schedule Cloud Function with a higher frequency than once a minute (but in your case this is not a real problem).
For each order, schedule a Cloud Function to run in exactly 50 minutes, as explained in this article titled "How to schedule a Cloud Function to run in the future with Cloud Tasks (to build a Firestore document TTL)". Drawback: The implementation is a bit more complex than the simple scheduled Cloud Function approach but you avoid the drawbacks of this approach, as listed above.
I want to implement functionality in the application on which user can schedule their exam on a particular date and time. and I want to generate notification before one day ago, so users will get reminded about their exam. I am using Firebase Database.Should i use Alarm Manager for that? or any background service ?
I don't have any idea about this. so can anyone help me how to implement this?
any help would be appreciated. Thank you.
One possibility would be to use Firebase Cloud Messaging (https://firebase.google.com/docs/cloud-messaging/) together with Cloud Functions.
You would write an HTTPS Cloud Function that would be triggered regularly (e.g. everyday in your case) and that checks, by querying the database, if there are some notifications to be sent, and if it is the case, sends them to the corresponding users.
You would trigger the HTTPS Cloud Function through an external service like https://cron-job.org/en/ or https://www.easycron.com/.
You will find an example of Cloud Function sending Firebase Cloud Messaging notifications in the official samples, here: https://github.com/firebase/functions-samples/tree/Node-8/fcm-notifications
In this sample, the Cloud Function is triggered by a Realtime Database event (see doc) but you can easily changed it to be triggered by an HTTP request (see doc), in order to trigger it with the cron online service.
If you are not familiar with Cloud Functions I would suggest that you watch the following official Video Series "Learning Cloud Functions for Firebase" (here in the doc), and in particular the three videos titled "Learn JavaScript Promises" which will show in details the difference between HTTPS triggered functions and Database events triggered ones.
The full doc for Cloud Functions for Firebase is here.
I'm developing an android app using firebase, this app should push notifications twice a day by hours user should set in app settings.
I saw a similar question was asked at least 2 years ago, but no answer, maybe now there is an option to do it.
Is there anyway I can achieve this using Firebase ? If no, how can I achieve it ?
You can schedule sending notifications from the Firebase console. But that is limited to notifications you manually enter. There is no way to schedule "twice a day" delivery, nor is there an API to schedule the delivery programmatically.
This means that you'll have to write code to implement this yourself. One way to do this would be to use the Firebase Cloud Messaging API to send the messages, use the Firebase Realtime Database (or Cloud Firestore) to store information on when and where to send the messages, and then invoke a Cloud Function on a schedule to read the information from the database and call the FCM API.
The latest launch of Firebase notifications feature allows to manually give the time and content of notification. Is it possible to automate it so that notification is received every time a particular variable is changed in the Firebase database?
Thanks for the reply Hamid. I didn't want to get into the technicalities of GCM therefore I implemented the notifications using a service. This service listen on the Firebase database and sends a notification whenever new data is added there.
I think you would have to setup a GCM (Switched to FCM now) server that handles all that. But I also do wish that there was a simple way of setting that up without needing to build a full server.
There is a friendlyping application that helped me set the XPMM server.
I think the current Firebase Notifications are very much in its early days. It doesn't provide many of the functionalities of Batch.com or Parse Server... yet.
For my app, I want users to schedule the time which they receive a specific notification. I was looking over the Firebase docs and could not find a method that would allow me to do this. Is there a way to allow users to schedule notifications with Firebase? My app is still using parse api but as of now parse notifications do not support scheduled pushes.
If plan to use the Firebase console to send messages, there's a simple option to define a time in which you you want the message to go out.
If you plan to send messages via SDK. at this time there is no setting to handle scheduling, you'll have to handle it on your server.