1

I have an app which has an admin login. I am trying to add the ability for an admin to send out push notifications from within the app itself without having to go to my Firebase Console. When I asked Firebase support I received this reply.

"It is possible through Firebase Cloud Messaging. What you can do is send an upstream message from your app to the app server then it will process the upstream message to send a push notification to the client app."

Has anyone done this before? I am trying to figure out how this would work. Since non admins just use the app without a login in would I create a default user id that the app itself listens on that upstream messages meant as push notifications would be sent to? Is there a way to send an upstream message that goes to anyone with the app on their phone as a push notification?

Brandon
  • 507
  • 5
  • 21

2 Answers2

1

You can use Firebase Console GUI to send push notifications to your client apps: https://firebase.google.com/docs/notifications/

But if you wish to send push notifications directly from your client app (mobile or web), you have to implement your own App server which will work together with FCM (Firebase Cloud Messaging) server to deliver notifications to other clients.

It's explained here in Firebase docs: https://firebase.google.com/docs/cloud-messaging/server

There's also Firebase blog post about this: https://firebase.googleblog.com/2016/08/sending-notifications-between-android.html

ElectroBuddha
  • 630
  • 10
  • 20
  • With Google Cloud Functions, you need your own app server. See answer below. – Crashalot Nov 04 '17 at 01:14
  • Update: as @Crashalot has pointed out, after Firebase introduced Cloud Functions there's no need for implementing separate App server, you could write cloud function to handle sending push notifications from device to device. – ElectroBuddha Nov 06 '17 at 08:36
  • Forgot to link to the answer explaining how to do push notifications without your own app server: https://stackoverflow.com/a/47106374/144088 – Crashalot Nov 06 '17 at 09:21
0

Sounds like you want to enable your admins to initiate an FCM message from within the admin version of the app. In that case the Firebase support is correct and there are a couple of ways you can implement that type of thing.

The basic logic would be:

  1. Admin tell server to send request.
  2. Server sends request on behalf of admin.

You have a couple of options to implement step 1, step 2 will always be the same. For step 1 you can:

  • Create an endpoint on your server that only accepts requests from your admin users. The admin user sends an HTTP request to that endpoint with all the required information for the server to then send an FCM message to all relevant users.
  • Use upstream messaging from the client to the server via an XMPP connection to FCM. The admin user would use the FCM client SDK to send an "upstream" message to FCM which would be forwarded to your server at which point your server would send an FCM message to all relevant users.

I think the first option is easier, and works just as well, assuming I understood your requirements.

Arthur Thompson
  • 9,087
  • 4
  • 29
  • 33