Firebase Registration Token for Website - firebase

I am looking to integrate Firebase into an existing project. I would like to create an administrative Website that would have the ability to create topics, and then post messages to topics.
From the mobile devices, the end user would be able to view the Topics that were created, and subscribe to them.
Ideally the administrative user would log into my website, opt to create a new Topic, and then from the backend I would send an HTTP request to FCM to create that topic.
The issue I am having is figuring out how to create Topics. My understanding is that I need to pass in a Token in order to create topics, but I can't find where to create Tokens for a web user in their SDK. Does anyone have any recommendations?

Topics in FCM follow a pub-sub model. There is no such explicit activity as creating a topic. You just subscribe to a topic. Usually you would subscribe from the client side using Android or iOS FCM APIs to subscribe.
If you wanted to subscribe users from the backend, you would need to use Instance ID APIs from your backend service.
Example:
// to list the subscriptions for a given token:
GET https://iid.googleapis.com/iid/info/nKctODamlM4:CKrh_PC8kIb7O...clJONHoA?details=true
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA
// to subscribe
POST https://iid.googleapis.com/iid/v1/nKctODamlM4:CKrh_PC8kIb7O...clJONHoA/rel/topics/movies
Content-Type:application/json
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA
Like you said you need this token. To get this token on the web for a user, use firebase messaging.

Related

How to secure Firebase Messaging topics with cloud functions?

Is there a way to secure validate subscriptions to topics? For example, is it possible to limit topic Test to a specific user with ID XXXXX? Is this possible with Cloud Functions?
firebaser here
To be able to subscribe to a topic, you currently need to know two things: the FCM token/instance ID of the app instance, and the path/name of the topic to subscribe to.
Knowing these two allows one to subscribe to the topic from any client. There currently is no public API to limit who can subscribe to what topics. So if you need to guarantee that the message is only delivered to authorized app instances, you should not use topics and instead delivery to each FCM token/instance ID directly from your own (server-side) code.
This request comes along regularly though, so I recommend that you file a feature request to add your vote.

Get messaging tokens from Go admin backend when adding users to Firebase, over upon registration in Javascript

I haven't seen any examples of this, but I want to purely interact with Firebase through the backend, and not the frontend with Javascript.
I have auth tokens being minted on my Go backend when a new user is added and then these users are written into a mongo database.
What I want is to be able to get a messaging token for my users, and then add it to their user document in mongo, that'll be used to send messages through the backend.
The reasoning is that we don't want to have to communicate with Firebase on our frontend.
Is this even possible?
If you want to send a message directly to a device with Firebase Cloud Messaging, you will definitely need some information from the client. There is no avoiding following the setup instructions on the client. In particular, you will have to handle the registration token on the client and send it to your backend so it can send the messages.
The Firebase Authentication token will not be useful to you at all for sending messages. FCM doesn't send messages to users - it sends messages to devices (or topics). You will have to figure out for yourself which devices belong to which users.

Send Firebase Cloud Messaging notification to users by user property

I'm trying to send out an FCM message to a specific set of users (or really, a single user) based on a specific user property but looking through the FCM HTTP API I can't seem to find a way to do that. I can send to users via topics, registration tokens, and device group notification keys, but I don't have any of that infrastructure set up in the near term. I know this functionality exists as you can send such a message via the UI, but I'm not seeing how to do it in the API documentation as yet.
There is currently no parameter that you could use to specify a user property (or even for user segments) that will serve as a target for the FCM API to send the message to.
As you've already searched, the only targets possible are single/multiple registration tokens (to and registration_ids), topics, conditions, and device groups (notification_key).
The option you're looking for is currently only available when using the Notifications Console.

Push Notifications through Firebase

Yesterday Google has announced a new set of tools for Firebase, one of them was Notifications the ability to send notifications from server to devices which are using my app.
But can we now notify users when they receive a new message?
And if not, is there a way around to achieve this?
Looking at the documentation, this doesn't seem currently possible automatically. Here is a possible way to accomplish it "manually" with another server:
Subscribe a user to it's own user ID
In android
FirebaseMessaging.getInstance().subscribeToTopic("InsertUserIDHere");
In IOS
[[FIRMessaging messaging] subscribeToTopic:#"/topics/InsertUserIDHere"];
Setup an outside server that checks every sent messages. When a message is sent, the server should create a notification that includes the recipient's user ID as the topic.
Look here for more info.
You can send messages to group of users (targeting a specific "topic") or to a single device (targeting a Firebase Cloud Messaging token).
To subscribe a device to a topic use:
FirebaseMessaging.getInstance().subscribeToTopic("topicName");
To obtain the device token use (*1) :
FirebaseInstanceId.getInstance().getToken();
Then you can use the Firebase Notificaitons web console, or the FCM server API if you want to send messages from your server.
See: https://firebase.google.com/docs/cloud-messaging/downstream#sending_topic_messages_from_the_server
Notes:
[1] getToken() can return null if the token is not yet available.
You can use the callback onTokenRefresh() to be notified when the token is available and when the token is rotated.
See: https://firebase.google.com/docs/cloud-messaging/android/client#sample-register

Gamethrive Onesignal Send push from unit to unit

I am considering switching from pushwoosh to gamethrive / onesignal but am a little confused. I am using the Unity SDK and cant see anywhere in the documentation that I am able to sund push from one unit to a specific othe unit. Can anyone help me clarify if this is possible
Thanks in advance
Yes this is possible.
The OneSignal API supports delivering notifications to individual users or groups of users in several ways. In your case, the best way is probably through the device's OneSignal ID (through the include_player_ids field in the OneSignal API).
You can send notifications from one device to another by interacting through the OneSignal API either on your own backend server or from the code running in your app. However, in either case, you will need to have a backend server to store a list of the OneSignal ID for each one of your users.
Here's a rough outline of the process:
Part A (First getting the OneSignal ID):
A device runs your application for the first time
You initialize OneSignal in your application and you receive a new unique OneSignal ID for this new device in a callback
You then must store this OneSignal ID on your own backend server somewhere.
Part B (Delivering a message):
You wish to send a message to a specific user
You ask your backend server for the OneSignal ID of the user who you wish to send a message to.
You use the OneSignal API to send a message to the user.
Related links:
OneSignal Homepage
OneSignal Documentation Home
OneSignal Notification Delivery API Documentation

Resources