Flutter FCM Push Notification Delivery Status - firebase

I wonder if there is a way I could track fcm push notifications delivery in flutter so I can set a callback and be notified when notification is received by device?

Please upload a bit of your code/ detailed code flow as to how you are achieving push notifications .i.e, from webserver/cloud functions/flutter package. In any of the methods, you receive information on the about failed/delivered msgs as well a Message-ID used as a reference when looking up particular messaging operation
If you rely on a web server, then in order to set callbacks on your web server, you can use the feature of Firebase Cloud messaging Data export to BigQuery and apply cloud functions to listen to the undelivered messages in bulk automatically. This however may turn a bit costly on a larger scale.

Related

Firebase push notification device to device

I am coding a React Native app and I using Firebase push notification service.
In my app, users can send message for each other and I want to notify them when they get message.
I found one way for native android I can code for react native it is not problem just I want to know if there is better way. I can make post to directly to Firebase service with using Http post.
This is the link which way I found: https://blog.usejournal.com/send-device-to-device-push-notifications-without-server-side-code-238611c143
I want to push notification to specific device without server, is there another way to do this?
Sending a message to a device with Firebase Cloud Messaging requires that you specify the FCM server key. As its name implies, this key is supposed to only be used in trusted environments, as knowing it allows one to send any message they want to all users of the app. For this reason it is not possible to secure send messages directly from one device to another device with FCM.
Instead you will have to run code in a trusted environment, such as your development machine, a server you control, or Cloud Functions. Your client-side application code invokes the server-side code, that ensures the call is authorized, and then calls the FCM API.
For more on this see:
How to send one to one message using Firebase Messaging
How to send device to device messages using Firebase Cloud Messaging?

Firebase: How to send push notifications in batches to avoid problem with backend overload?

We have an app (iOS, Android) where we send push notifications to from the Firebase web interface to all the registered users.
The backend system cannot handle the peak load that occurs when all the users are pulled into the app calling the REST API from the push notifications.
Is there a way to split the registered users to send the push notifications little by little at an appropriate rate?
I suspect that this has to be done programmatically. C#?
Question with workarounds handling peak times when sending push notifications
The web console for sending notifications with Firebase Cloud Messaging does not have a way to throttle message delivery. It's an interesting concern though, so I'd recommend filing a feature request.
For the moment though, I can think of two options:
Create multiple audiences that cover your entire user base, and then send to each audience at a different time.
Use the FCM API to send out the messages to your users in batches.

Is it possible to send messages through Firebase Cloud Messaging (FCM) to offline users?

I'm working on a Progressive Web App (PWA) and I need to send important reminders through push messages. Users should receive them even if they are offline.
Is it possible to use Firebase Cloud Messaging (FCM) for that (maybe preload the messages or something like that?) or do I need to get a different route for offline?
Adapted after AL's comments below and Frank's comment above
It is possible to send "push messages" via Firebase Cloud Messaging (FCM) to a device that is offline, BUT the user will only see the message when the device is online again. If the device is offline it cannot receive immediately any (push) message from the "external world". If you want to trigger some reminders that are immediately visible for a device which is offline, you will have to do it locally, on the device, and not by relying on a push from the "external world".
So, having said that, if you want to use Firebase Cloud Messaging to send messages, you can do it by using Cloud Functions, i.e. from a "trusted environment". Have a look at this official Firebase Cloud Function sample: https://github.com/firebase/functions-samples/tree/master/fcm-notifications
You could trigger this Cloud Function when e.g. a new item is saved in the database (Real Time Database or Firestore), or an existing one is modified/deleted, or a file is uploaded to Storage, etc.

Firebase Messaging in Flutter Upstream messages

I'm trying to configure Firebase Messaging in Flutter, but it seems that there is no implementation yet for the Upstream messages.
https://firebase.google.com/docs/cloud-messaging/android/upstream
What I want to do is to add a reminder and notify the user after x time with a push notification.
Let me know if you guys have any other solution, or we should simply wait for Flutter and Firebase for Flutter to became stable.
Thanks
Alvin
You are correct that there is no implementation for upstream messaging in FlutterFire yet, we are working on filling out these features. However given your use case you may be able to do something like write the user's reminder to Firestore or Firebase Realtime Database then when you are ready to send push notifications you can use Cloud Functions for Firebase to send the messages to the required devices.

Dynamic Push Notifications

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
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
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!

Resources