Angular web app (not a native app)
I have my logic working to generate and save FCM tokens.
And I can send a send a message to one token using curl in the terminal.
I have been reviewing MANY tutorials and all I have seen send messages to one token at a time.
Is it possible to send a message to all the tokens you have saved in your Firebase Realtime Database?
Do I need to use (or build) some other tool to do this?
Thre is no built-in mechanism in Firebase Cloud Messaging to send a message to "all tokens".
Instead you can call the FCM legacy API to send a message to a collection of up to 1000 tokens at a time. The key is to use the registration_ids parameter (instead of the to parameter for a single token), as AL explains here: FCM (Firebase Cloud Messaging) Send to multiple devices and here: FCM: Message to multiple registration ids limit?, and as shown in the documentation for the legacy API.
Related
I have both my web app and my android app included into my firebase project. Using the web app, the user can insert data into the realtime database. Using the android app, the user can view his record, which is read from the realtime database.
My javascript:
firebase.database().ref("db/0/").push(
{
"name":"XXXX",
"age":YY,
"address":"ABCDEF"
}
)
//I want to send a notification to the app, whenever a new data is pushed
I want to send a notification to the app, whenever a new data is pushed into the realtime database. How do I proceed?
Calls to the FCM REST API to send a message to a device require that you specify the FCM server* key in your code. As its name implies, this key should only be used in server-side code, or in an otherwise trusted environment.
The reason for this is that anyone who has the FCM server key can send whatever message they want to all of your users. By including this key in your Android or web app, a malicious user can find it and you're putting your users at risk.
See How to send one to one message using Firebase Messaging for a better solution, which also links to the Firebase documentation of using Cloud Functions to notify a usr when something relevant to them happens in the Realtime Database.
Im trying to use firebase cloud messaging to enable push notifications on my PWA.
but i can't figure out how to save tokens after the 'user' click on 'accept' on the push notification subscription message.
Should i save token to a firebase database? or there is a automatic system to subscribe/unsubscribe/ clean the list of tokens.
Did you mean registration tokens? If so, please check out this doc which has comprehensive information about how to manage registration tokens.
I will create python api using Django
now I trying to verify phone number using firebase authentication end send SMS to user but I don't know how I will do
The phone number authentication in Firebase is only available from it's client-side SDKs, so the code that runs directly in your iOS, Android or Web app. It is not possible to trigger sending of the SMS message from the server.
So you can either find another service to send SMS messages, or to put the call to send the SMS message into the client-side code and then trigger that after it calls your Django API.
Can anyone tell me how to push notification by a device to another device ? Maybe that’s good if it in One Signal , but no problem if also by firebase ?
For android
My approach is to use firebase.
Use need a server and a database.
You initialize firebase in your app.
When user open your application you get token from firebase and send it to your server and in your server you store token for each user.
And then when a user wants to send message to another user, it call an api from your server to send notification to specific user.
And in your server you have firebase token for each user and by using that you can send push notification to that user with apis that firebase prepared.
My end goal here is to subscribe web clients to topics in Firebase Cloud Messaging to receive simple data push events, partitioned by keys. Via this question, that seems to be possible, but only if you can send the clients' registration keys to an app server you control using the FCM Admin API: How to subscribe to topics with web browser using Firebase Cloud Messaging
Also, via https://firebase.google.com/docs/cloud-messaging/js/client, it seems to be required to request permission from the user to show desktop notifications in order to get access to the registration token for Firebase messaging.
Is there any way to tell Firebase no, I absolutely do not want desktop notifications, in fact please never show them, I just want to use data messages and never notification? And then, to get the registration token? Alternatively, is there some other way to subscribe to topics from a web client?
There is currently no other alternative to get a registration token nor is there a different way to subscribe to topics for a web client.
You already know this, but might as well mention it. Requesting permissions is a must for security purposes (preventing notifications not wanted by the user) and that in order to subscribe a web client to a topic, you'll first have to get a token (which won't generate unless the user grants permission).
Looks like you are looking for Pusher
User channel for communication. Works with out token and support bidirectional contact.
Sample code
Back End
pusher->trigger('my-channel', 'my-event', [
'message' => 'hello world'
]);
Front End
var channel = pusher.subscribe('my-channel');
channel.bind('my-event', function(data) {
alert('Received my-event with message: ' + data.message);
});