Does firebase cloud messaging allow targeting of push notifications to a specific device/user etc - firebase

I am trying out firebase cloud messaging (React-native-firebase) and it seems that I am only able to push notifications to all android/ios users, not specific users. Is there a way to target a specific user. Like if a user invites another user only send notification to that one specific user?

The flow can be this one:
User allow notifications on their device(s)
Grab the generated token and store it in the user document inside a tokens array.
(If the same user connects to your app in another device, add the new token in the tokens array)
If you want to target a specific user, get his UID and send a notification to their devices.
You can also subscribe a user to a topic and send a notification to users subscribed to that topic.

two way:
init
your client-side subscribe the topic.
subscribeToTopic("weather")
your client-side report the user property
setUserProperty("name","TOM");
Firebase Cloud Message Console
crate a notification item like this way

The flow can be this as follows:
User allow notifications on their device(s)
Grab the generated token and store it in the user document inside a tokens array.
(If the same user connects to your app in another device, add the new token in the tokens array)
If you want to target a specific user, get his UID and send a notification to their devices.
You can also subscribe a user to a topic and send a notification to users subscribed to that topic.

Related

Export Historical user data from Firebase

I have setup a firebase project to track users events and for supporting push notification in my IOS and Android apps. In my apps I was registering for notifications when user completes sign up. However I have a number of users who just opened the app and didn't complete registration. I am planning to send notifications to such users to give them a nudge.
However I don't have the notification tokens for such users in my database. So is there any option to export the details of such users from firebase where I can grab their notification tokens?
I tried using big query and audiences but that wont work with historical data.
It sounds like you're using FCM tokens to send messages. In that case you will always needs an FCM token to send a message to a specific app/device.
FCM doesn't know anything about users of your app; all it knows about are the tokens.
So if you want to send a message to an app instance where the user didn't sign in, you'll need to store the token from the app in your database as soon as the app starts - even before the user signs in. Then when the user signs in, you can associate the token with their UID.
With those steps out of the way, you can query for database for tokens without an associated UID and send them a reminder to complete the registration.

Flutter - push firebase notifications to specific users without firebase auth

I am working with Firebase to push notifications and I don't use Firebase authentication on my app (I have my own system).
I didn't find an answer to this question:
Is it possible to push notifications to a specific user with firebase without Firebase authentication (and therefore, without a UID)? How?
The push notifications are not sent based on user, they are sent based on push notification token that is received when you register for push notifications (iOS & Android).
The push notification token will change in the case of uninstall/install and has nothing to do with what user is logged in in the app, you can send push notifications to apps that don't have users at all.
In order to target a specific user with push notification, you must do something called user segmentation, that is, filter user based on particular properties of these users. In general user segmentation is done by tracking user action and user properties and depends on the push notification platform in use. For example you can track user actions in the app, like user added product to cart, user has x products in cart and then send a push notification to all users that have more than 3 products in cart.
All the push notifications platform link the push notification token to the events triggered.
If you are using firebase, the most easiest way is to track user properties, there are a lot of tutorials on this part. Although, in my opinion, firebase tracking is kind of crappy.
One thing to note, since the push notification token is not linked to the user directly, in case there are two users (two accounts) using the same device they, they will receive push notifications on the same device, so don't send sensitive information via push notifications.

Sending message to custom user using firebase

Id like to make a chat between two custom users.
I need to send an message to custom user.
scenario:
User1 get User2 ID from my server
My server get User2 ID from Firebase (probably using Firebase admin)
My server return User2 ID to User1
User1 send message to User2 via firebase
Is it possible to make? Do I have to use Firebase Admin + FCM or something else?
[Giving you a simple guideline and logic here]
One of the simplest ways to implement it is by using Cloud Firestore.
You need to create 2 tables, one for the users and one for the chat. The users will be used to store the users' info including UID, emails, friends (array, to store a list of friends), chats (array, to store a list of chats), etc. While the chat will be used to store all the chats. (You can design your own database, some guideline can be found here)
When the user signed-in with Firebase Auth, you can query the database to get the details from the Firestore. Assuming you put everything in some UI element (recyclerview), once you click on the user's friend (friends are stored in the Cloud Firestore mentioned above), a new chat document will be created in the chat database/table, and under the other user (User 2) document record in the users table/database, update the chat array with the new document ID. For the User 2 UI interface, new chat will be created/updated as Firebase has something like onChangeListener() to update your client.
You will need to design your UI for the chat allowing the user to send messages. The UI will need to fetch all the chat records from the chat document. When any party sends a new message, update the message to the chat document.
So basically that's the rough idea, you can get all those references from Firebase Doc.
For notification, you can use Firebase Cloud Messaging to notify the user!
The actual function of FCM as stated in the doc:
Using FCM, you can notify a client app that new email or other data is
available to sync. You can send notification messages to drive user
re-engagement and retention. For use cases such as instant messaging,
a message can transfer a payload of up to 4KB to a client app.
Therefore, it is not intended user to user but is for the App admin to the user for certain events.
For Admin, it is not encouraged to call Admin all the time for a production consumer app.
P/s: I don't spoon-feed with code but to encourage people to learn from their own research.
Hope it helps!

Firebase functions -get fcm token from user id

I want to send push notification to specific user,
but i dont know his fcm token.
Is it possible to get the fcm token of user from his user id?
A user may be using multiple devices. You should expect this to be the case. You'll need to store each device token for all devices that a particular user may be using in order to notify them. Typically, Firebase apps will use Realtime Database to record the token at the time of login.

Worklight send push notifications without username

I want to create an application which have 2 modes: non-logged-in and logged-in (having username).
I want to send push notifications to devices in both modes. The non-logged-in devices should receive notifications such as general announcements, new events, etc. The logged-in mode devices will also receive same notifications and few more.
Now what I want to do is to subscribe the device to receive notifications for non-logged-in mode then once the user logs in to his account from that device I want to unsubscribe the previous non-logged-in notifications.
I've read the answer to this question : Worklight: Push notification without User ID I think that I can play with onUserSubscribe callback when registering the user and unsubscribe the userId of the persistent cookie.
Is this a good idea ? Is there another suggestion ?
My thinking is that you could register an app to 2 event sources.
The first event source will handle the general notifications that an app should receive, whether a user is logged-in or not.
The second event source will handle the notifications for logged-in users.
When the app launches, subscribe to the first event source.
When the user decides to log-in, subscribe to the second event.
You should allow the user to unsubscribe from both if s/he so chooses, as well.
Additional information:
IBM Worklight 6.1 Information Center: search for "push notifications"
Push Notifications training module
So what you're trying to achieve is push notifications broadcast (send to all users). This is something that you'll be able to do with upcoming Worklight 6.2 release. You will not have to subscribe users according to username, but will be able to specify tags during subscription. And after that you'll be able to send push notifications according to this tags.

Resources