3

I am trying to send a notification to all users of my app whenever there is a write on the database.

Here is the code that I have so far.

export const newUserAdded = functions.database
                        .ref('1_0_0/updateDate/date')
                        .onWrite((event)=>{
                            //send notfigication to all 
                            admin.messaging().sendToCondition()
                        })

As you can see whenever there is a write to the date key the function will trigger.

But note here that I do not have device token of the user as I want to send a notification to all users. I was not able to find any method do so.

Kindly do let me know how can I achieve this.

Thanks

krv
  • 2,830
  • 7
  • 40
  • 79

1 Answers1

1

You can use topic messaging. Arrange for all your client apps to subscribe to a dedicated, named topic for broadcasting to all app installations, then send your message to that topic.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
  • any examples of that in js/angular? – krv Feb 26 '18 at 05:52
  • Did you check the documentation? https://firebase.google.com/docs/cloud-messaging/js/topic-messaging – Doug Stevenson Feb 26 '18 at 05:53
  • yeah I did. Thanks. But need more of example like in codelabs. Will try out the docs. thanks – krv Feb 26 '18 at 05:55
  • I got it to work with subscribing to topic. But no sound is played when notification arrives. Any payload data changes to be made there? – krv Feb 26 '18 at 06:06
  • You can't control that with a notification payload. If you want to control the notification, use a data payload and handle the incoming payload yourself. – Doug Stevenson Feb 26 '18 at 06:08
  • for the sound https://stackoverflow.com/questions/4441334/how-to-play-an-android-notification-sound – Liker777 Jun 20 '21 at 16:14