Firebase Cloud Messaging to send notification for set of users - firebase

I'm developing an app using Firebase, in the app there are groups and for groups there are multiple members. I want to send notifications to members in a particular group based on one of the users activity. As an example in a chat app, notification to others informing there is a new message.
I referred this blog post. As it seems best way to do this is Firebase Topic Messaging, all members can be subscribed to the group id as a topic.
My matter is how to avoid receiving notification to the member who's action causes to the notification.
I tried Firebase message sending to multiple topics but it only allows for two logical operations (&&, ||)

Firebase Cloud Messaging has two types of messages: notification messages and data messages.
The default behavior of Firebase is that notification messages will automatically be displayed if the app is in the background or not running. This behavior cannot be modified. If the app is in the foreground, the notification message will not be automatically shown, it will instead be delivered to your app's code.
Data messages on the other hand will always be delivered to your app's code.
Since the user sending the message will typically have the app open, the default behavior will automatically ensure the notification is not shown on the sending user's device.
But in the blog post you refer to there is a race condition for this. If the user closes the app between the time they send the notification to the server and the time the server sends out the notification, the notification may show on their device too.
If this is a concern for your app, you should not use a notification message. Use a data message instead and include enough information in the message to detect which user has sent it (e.g. the user's uid).

Related

Flutter push notification using FCM by topic

hello I'm new to flutter and trying to get push notification in flutter , I have successfully subscribed the user to a topic and sent a notification through the firebase console by topic , what I'm trying to do is to have a button for admins in the app and when they post for a particular topic the users with that topic get the notification I have heard about cloud functions but I don't know exactly where to start ! i hope I made my point ! I have seen some videos that talks about type script but is there is any workaround this ?
The Firebase documentation names notifying the user when something interesting happens as an example use-case. From there:
Developers can use Cloud Functions to keep users engaged and up to date with relevant information about an app. Consider, for example, an app that allows users to follow one another's activities in the app. Each time a user adds themselves as a follower of another user, a write occurs in the Realtime Database. Then this write event could trigger a function to create Firebase Cloud Messaging (FCM) notifications to let the appropriate users know that they have gained new followers.
The function triggers on writes to the Realtime Database path where followers are stored.
The function composes a message to send via FCM.
FCM sends the notification message to the user's device.
To review working code, see Send FCM notifications.

How to send a push notification from the Firebase console to a specific GCM/FCM device token ID

In Urban Airship, when I am composing a notification, I can target specific users by searching for a Urban Airship channel_id (device ID):
I sent from Urban Airship the push notification that I am showing above, and I received it successfully. Now I want to do the same thing, send a push notification to a specific device, but now using the Firebase console. The problem is that in Firebase, in the step where I need to specify the target, it only allows me to choose User segment or topic. I was expecting to see a third option: Target specific users (for sending notifications to one or many specific GCM/FCM device token IDs. So my alternative is to add a GCM/FCM device token ID to a topic and then send the push notification to that topic, which is something that I have successfully done before. Nonetheless, that would be a workaround and not the way I would prefer to do this. Is it possible to send push notifications to specific users (by defining the target GCM/FCM device token IDs) from the Firebase console? Thank you.
UPDATE 1: See how the Firebase console (https://console.firebase.google.com/) only shows User segment and Topic as the Target:
First Step:
Second Step:
Third Step:
By design, the notification feature in the console is for sending out broadcast-type events. Sending user-specific alerts would be more of a programmatic operation done through the API.
For sending test messages, there is a console tool for this, explained here.
Note that it is possible to send a notification to one device by subscribing a device to any topic and sending the notification to that topic in the console (keep in mind topics are public and you can't prevent users from signing up to them; fine for testing most likely).
Another alternative is to send a message via HTTP or curl. Perhaps the best resource for this is the quickstart/messaging example.

Not Seeing "Opened" Firebase Notification Stats

I'm manually handling firebase notifications by overriding the onHandle intent of the FirebaseMessagingService.
And using the intent I generate a notification.
Is there a way to manually report the notification opened to the Firebase at all because I'm not getting opened statistics reported back to the firebase console.
As above, even when letting firebase notifications get handled per normal, these open notifications are not being reported either.
Thanks!
The stats shown in the notifications panel of the Firebase console are only for messages sent from that notification panel. There is currently no way to trigger the stats for messages sent through the Firebase Cloud Messaging API directly.
Update: since late 2018 the Firebase now also reports messages sent through called to the Firebase Cloud Messaging API.
According to https://firebase.google.com/docs/cloud-messaging/understand-delivery only "Sends" work for data-only messages:
Sends — The data message or notification message has been enqueued for delivery or has been successfully passed to a third-party service like APNs for delivery. See lifetime of a message for more information.
Impressions (available only for notification messages on Android devices) — The display notification has been displayed on the device.
Opens — The user opened the notification message.
For those curious to know my workaround at this time.
We run push campaigns.
For each campaign we created a distinct, reusable event.
We register the event "campaign_received" and "campaign_opened"
When a message is received, we trigger the event.
When the notification is opened, we trigger the event.
Then, under each event, we just select the event, and file their stats per day, week, month, etc.
One needs to select the event to get to the event dashboard area, since the event list view shows the total amount of events sent and or received.
For bespoke notifications the 500 event limit might be reached quite quickly, so be sure to bundle your notifications into reusable event categories if possible.

firebase - when user dismiss a notification

Im using inoic with cordova-plugin-fcm
There's any way to handle when user dismiss a notification, because I need to do store some data when a notification arrives.
tks for any help.
There are two types of messages that you can send with FCM:
notification messages, which are primarily meant to be displayed to the user.
data messages, which are handled by your application code.
If you send a notification messages, then your code can handle the message while the app is active. But if your app is not active, the message is handled by the system and displayed to the user. Your code is not invoked in this case.
If you send a data message, it is always handled by your code. For your use-case, these sound like the better match.

Firebase notifications security / console activity log

i'm thinking about using Firebase for the notification service that my app needs. However, its important that the process of sending notifications is secure. I want to avoid a notification being sent from any member of the team without permission.
One way could be assigning restricted roles and permissions for the team members. However it also would be good to have any kind of activity log in the console, or have a log of all notifications sent including the name of the user. The console currently allows you to see all notifications sent, but i cannot see who sent it, and also the notification can be deleted from the log.
Any ideas on how to manage this? Which specific roles would you recommend me to use? Is it possible with Firebase?
You could write a function in Firebase which sends notifications, and you have logs on that function. Here is how to write a function which send notifications

Resources