How would i send a push notification automatically, instead of doing it through the firebase console manually. Like when user invites another user send a notification to the user that they have been invited. I am getting the user device token by doing firebase.messaging().getToken();
You would need to develop your own server where you need to save device token and send push notifications based on various triggers.
Alternate way - if you are using other Firebase services like Firestore - you can go with Firebase Functions. Here is quick overview: https://firebase.google.com/docs/functions/use-cases
Do it through your backend, First you need to register users' token on your backend and when userA send invitation to userB send that request to the backend and your backend should have userB token, it will send userB notification.
If you use firebase DB and want to send push notification by some actions (for example, new record in your db ), you can try to use firebase functions.
See here for more information
In any other ways - you should create your own server app that will be connected with fcm or apn services and your db. Of course, you should configure your server app correctly.
Related
Please note that this question is not about getting device token on client side.
I am very new to react-native and firebase and I want to implement push notication service of FCM. What I am planning to do is to send a notification to particular device using its device token on my nodejs app server or cloud function( not through console). But as I have found, FCM doesn't provides any API to accrss token by username. Suppose I want to send notification to user X( for the time being, suppose that one user signs only on single device). Now using the function sendToDevice(), I can send the message to a specific device. But how would I know the device token of user X. Do I need to store tokens in the firebase database by myself? Or can I get along without storing FCM tokens?
Please guide me because firebase docs aren't clear about this.
Save the device token for a particular user in DB and then you can use fcm-node npm in which there is a simple function to send a push to a particular device token.
You also need to use the FCM server key which you will get easily on the firebase console.
FCM doesn't offer a way to associate device tokens to individual users who might be using your app from multiple devices. You will need to write code to associate a device token to a user account by sending that token to your backend, along with the user's ID. Only then can you collect FCM tokens for that user, and message them on any of their devices.
I want to know that is there any way to send push notification programmatically on particular FCM registered token (Device token)? i had implemented group chat but stuck in one-one chat.
I don't want to use any web-service or any back-end at all, because i am using Firebase database and storage as a Back-end in my application.
i want to send upstream message to particular device token.
Any idea's how to do that ? thanks.
Is possible to send push notifications with firebase without using the console,I mean can I send a push notifications when some user makes some action in the app?
Is possible to send push notifications with firebase without using the
console
Yes you can use Firebase API
I mean can I send a push notifications when some user makes some
action in the app?
You can subscribe to a topic when user makes some action in the app
FirebaseMessaging.getInstance().subscribeToTopic("news");
and send a notification from Firebase web console or use Firebase API to all topic subscribers.
You can send a message to a topic from the Firebase Cloud Messaging API.
But this requires the use of your FCM server key, which means it should only be done from an app server. You should never embed your server key in the client-side app. This means that direct device-to-device notifications are not possible at the moment, you will always need an app server for that.
For a tutorial explaining one possible scenario, see: https://firebase.googleblog.com/2016/08/sending-notifications-between-android.html
I'm building an app that allows the user to create events and add people to those events. It stores the event and certain user data (email and display name) in a Firebase database.
What I'm trying to do is send a notification to a specific user when another user adds them to an event. I've tried looking at the documentation for both Firebase Notifications/Cloud Messaging and Batch, but I can't find a way to send the notification to a single user, rather than an entire group.
How do I go about doing this? I'm hoping to avoid storing the notification in the Firebase DB and setting up a servlet backend that queries the DB repeatedly.
Edit: If I do have to make a Java Servlet backend for this, can someone tell me how I would code it?
I think you can do that by specifying the device token when sending the notification using console or using post request to FCM server. But unfortunately you have to handle every single device token manually by yourself (get it from the device when it register to FCM, and save it to your own DB somewhere).
If you use console, you can put the token on "FCM registration token" field under target -> single device.
If you use post request, you can make a request like this
{
"data": {"my_custom_key" : "my_custom_value"},
"registration_ids": ["your-device-token","your-device2-token"]
}
Batch.com provides a simpler API named Transactional API to send a notification to one or more users identified by their User ID, Firebase UID etc. as you probably don't want to deal with the complexity of APNS push tokens or GCM registration ids yourself. Contrary to FCM, you will get a complete analytics view (eg: open-rate) on those notifications.
You can trigger push notifications directly from your app code by using our Swift client for the Transactional API or by coding your own HTTP client (it's a standard POST request with a JSON body). We even have a client for Node.js if you decide to trigger the notifications from a server.
And if you are using Firebase, we have a specific documentation to plug Firebase with Batch.
I am trying to implement push notification using Firebase Cloud Messaging but it seems as if you have to register the device to receive push notifications. I am trying to make it so when there is action in the database, such as an inbox reply, send a push notification to the user who received the message.
Is there a way to send the push notification with Firebase to a particular user, not a particular device?
You don't send push notifications to a user, you send them to a device.
Somewhere in your code (maybe when your user signs up/ logs in to your app), you have to execute the code to get a GCM registration token. This token is unique to your Android app and that specific Android device.
With that token, you can send push notifications to that device using any method you want (from an app, from a website, etc. If you have a GCM reg token you can even send pushes from this handy website: http://1-dot-sigma-freedom-752.appspot.com/).
It is now your responsibility to keep a database of your users and their GCM registration tokens. When a user wants to send a push to another user, you would find the corresponding registration token in your database and then execute the code to send them the push using that token.
FCM provides several ways for you to send notifications to your users. You can send messages directly to devices via an Instance ID token, you can send messages to a topic that your user has subscribed to, and you can also send messages to groups of users eg: country/language etc.
Have a look at this sample which demonstrates sending to a device and topic. Also have a look at the docs for more details on sending and receiving messages.