How to Send Data Message Using Firebase Console

Unable to send data message using firebase console

You can now send notification message via the console. Note that it is different from data messages; notification messages only trigger the onMessageReceived callback when the app is in the foreground.

They are inside the advanced options tab on the compose message screen.

Sample Image

Just expand it and type your key/value map.

Sample Image

These will be included into the data field of the notification.

Firebase Cloud Messaging: how to send data message to all users?

Use topic messaging. You can define the name of a topic that all installations of your app will subscribe to, then send the message to that topic.

You can use the Firebase Admin SDK from your server to send that message. Or you can use the FCM HTTP API to send that message.

Firebase Messaging: Send a data message to all app users with a cloud function

I believe the only part you will need to change is the end. You won't need this part here admin.database().ref("/messages/" + context.params.meta).remove().

For the messaging, your code needs to look something like the below sample:

// Send a message to devices subscribed to the provided topic.
admin.messaging().send(payload)
.then((response) => {
// Response is a message ID string.
console.log('Successfully sent message:', response);
})
.catch((error) => {
console.log('Error sending message:', error);
});

You need to user a catch to manage the error - this way you will be able to visualize as well, what might be causing your issue. You can find more information in this documentation here: Send messages to topics.

Besides that, I found this nice repository - that you can access here - with some examples and more code samples, on how to use Cloud Functions with FCM.

Let me know if the information helped you!

How to send test push notification with custom data from firebase console?

Yes, Sure you can test it through printing the device token

  FCM.getFCMToken().then(token => {
console.log(token)
});

Then take the token and go to the cloud messaging section and you just set the FCM token in test message like the picture below:

Sample Image

Update

the new Firebase interface does not provides a direct way to test cloud messaging with data at the moment. However you have two options: either you create a certain subject and subscribe to it like the following code

  FCM.subscribeToTopic("/topics/testTopic");

and then in the target section you can target topic testTopic (This may require time to confirm a new subject)

Or you can do this programming using Firebase admin, you can follow this tutorial:
https://medium.com/android-school/test-fcm-notification-with-postman-f91ba08aacc3

Hopefully this answer your question

Send notification to one user with firebase cloud function node

Firebase Cloud Messaging has no concept of a user. Instead it can send messages to:

  • Specific app instances (so your specific app as installed on one specific device), as identified by an FCM/device token.
  • A group of app instances/tokens, as defined by your application logic.
  • A specific topic, to which app instances can then subscribe.

It's up to your application logic to decide how to map from your user ID to one of these options. The most common are to:

  • Store the device token(s) and your user ID in your own database, then look up the device token(s) for a user when needed and fill them in to the API call you already have.
  • Use a specific topic for each user ID, subscribe the application to that when it starts, and then send a message to that topic when needed. Note that anyone can subscribe to any topic though, so this approach would allow folks to receive message for anyone whose user ID they know.

Can I Send notifications to specific users in firebase cloud messaging console

You can send notifications from the console to specific users by following the steps below:

  1. Get the FCM registration tokens for the users' devices. You can check how to get the tokens for the devices depending on the platform here.
  2. Go to the project's Notification Composer.
  3. Enter the notification details i.e notification title(optional),
    notification text, notification image(optional), notification name(optional)
    .
  4. Click Send test message.
  5. Enter the FCM registration tokens.
  6. Click Test.


Related Topics



Leave a reply



Submit