1

The Firebase Admin documentation shows examples on how to send notifications to a specific user, or users subscribed to topics.

https://firebase.google.com/docs/cloud-messaging/admin/send-messages

In the Firebase Cloud Messaging Console though, it's possible to send a notification to all users of a specific app enter image description here

That works regardless of the clients subscribing to topics.

How can I replicate that behaviour with the Firebase Admin libraries?

XelharK
  • 598
  • 8
  • 21
  • There is currently no API to do this with Firebase Admin. You would have to proceed on using Topics. On your app's initial activity, you could immediately subscribe to a topic named for your specific app. – AL. Jun 28 '18 at 17:35
  • Yes, the problem with this is that I'd have to send an update, and I cannot contact users who still have the previous version of the app in any other way besides the firebase console. Having automated tasks to handle notifications in my server would help a lot. – XelharK Jul 02 '18 at 10:17

1 Answers1

1

Based on my read of the documentation, it seems like you could automatically subscribe every new user to a topic such as "appWideAlerts" upon sign in. Then use this as your app wide notification system.

Send to a topic

Based on the publish/subscribe model, FCM topic messaging allows you to send a message to multiple devices that have opted in to a particular topic. You compose topic messages as needed, and FCM handles routing and delivering the message reliably to the right devices.

For example, users of a local weather forecasting app could opt in to a "severe weather alerts" topic and receive notifications of storms threatening specified areas. Users of a sports app could subscribe to automatic updates in live game scores for their favorite teams.

Some things to keep in mind about topics:

  • Topic messaging supports unlimited topics and subscriptions for each app.
  • Topic messaging is best suited for content such as news, weather, or other publicly available information.
  • Topic messages are optimized for throughput rather than latency. For fast, secure delivery to single devices or small groups of devices, target messages to registration tokens, not topics.
  • If you need to send messages to multiple devices per user, consider device group messaging for those use cases.
Community
  • 1
  • 1
Ronnie Royston
  • 16,778
  • 6
  • 77
  • 91