0

If I make a fully mobile app system with Firebase as its cloud API endpoint without any web server API helper, is it possible to make Firebase (or the mobile) send push notifications to all or targeted devices if some data on the Firebase met certain criteria?

For example, if I have this kind of data:

com.example.app
+ votes
  + a9sd7f98asdf
    - rating: 8
    - timestamp: 129387129387
  + asf9d80a9dsf
    - rating: 3
    - timestamp: 219837182387
  + a9s8d7f9asd8
    - rating: 4
    - timestamp: 123981723189
  + asf8a9sd8f79
    - rating: 9
    - timestamp: 123981728388

Is it possible to make Firebase send push notification to all or targeted devices based on the following situations:

  1. Any new rating inside votes is less than 5? (if the Firebase data is getting any new votes that has rating less than 5, the Firebase will immediately send push notification contains static message and/or the path to the data).

  2. Within a week data, the calculated rating average is less than 5? (in a certain time triggered event, the Firebase will do a calculation on the average review and check, if the calculated average is less than 5, the Firebase will send push notification contains static message).

If there's no way to Firebase to do this calculation and checking by its own, is it possible to trigger such push notification send from Android/iOS mobile app?

Frank van Puffelen
  • 418,229
  • 62
  • 649
  • 645
Chen Li Yong
  • 3,904
  • 5
  • 39
  • 83

1 Answers1

0

There is currently no Firebase API that has precisely the functionality you need.

To send a notification to a device you must specify the FCM server key to the API. As its name implies this key should only be used in a trusted environment, such as your development machine, a server you control, or Cloud Functions.

As Doug said, you can implement your precise logic in Cloud Functions (or another trusted environment) and then call the FCM REST API, or use one of Firebase's Admin SDKs if it's available for your platform, to send the messages.

I recommend checking out some of these previous answers on the topic:

Frank van Puffelen
  • 418,229
  • 62
  • 649
  • 645
  • Yes, currently I'm exploring Cloud Functions, referred to from the commenter Doug Stevenson. I usually work with a web-mobile team so I've never explored the Cloud Functions part of Firebase. Based on the answers I found on the internet about pros and cons working with Cloud Functions, looks like this is the best way to work with "fully mobile" app, although Javascript/Typescript is not my strong suit. Thanks! – Chen Li Yong Aug 26 '19 at 04:05
  • yes! Sorry I was missing that step. Usually I set an answer as accepted so fast that the stack overflow said you need to wait 10 mins before you can accept an answer, so that's why I usually wait right now, but that makes me forgot to accept. xD – Chen Li Yong Aug 26 '19 at 04:25