0

I am trying to build an app which will send notifications to the users according to the data changes from Rest API.

i.e A user subscribes that he wants to be notified when Spain scores the goal against Portugal. So my question is, is it possible to connect that link which sends requests to Rest API which I'm using to retrieve data to FCM or should I look for other product which will solve my problem?

Android Team
  • 11,274
  • 2
  • 26
  • 46
Kuba
  • 13
  • 5
  • You can just integrate FCM api with your Rest API – Safvan CK May 15 '18 at 10:08
  • @SafvanCK can you give me a hint where to look for a guide how to do that? I'm looking at official guides at firebase site and I'm kinda lost between so many new terms. Thank you for your answer – Kuba May 15 '18 at 10:15
  • When you say "data changes from Rest API", does it mean change into the Firebase database for example? – Renaud Tarnec May 15 '18 at 10:21
  • @Kuba can you please more specific on your requirement – Safvan CK May 15 '18 at 10:29
  • @SafvanCK maybe I will make it with resources which you have provided for me – Kuba May 15 '18 at 10:35
  • @RenaudTarnec I meant that if I can somehow make FCM observe constant changes in Rest API(with providen link which responses with data in JSON format like this: [link](https://andfun-weather.udacity.com/weather)) and then if FOR EXAMPLE temperature reaches 35 degrees - user gets notified while app is not running – Kuba May 15 '18 at 10:50
  • You can view bellow link. It has Spring java implementation https://stackoverflow.com/a/51172021/3073945 – Md. Sajedul Karim Jul 29 '18 at 05:00

1 Answers1

0

You could do it with Cloud Functions, which "run backend code in response to events triggered by Firebase features and HTTPS requests", see the general doc here.

You could regularly trigger an HTTPS Cloud Functions that would:

  1. Call the REST API, e.g. with Request (https://github.com/request/request)
  2. Based on the response of the REST API, send a notification with FCM.

To send a FCM notification via Cloud Function, have a look a this official Firebase sample https://github.com/firebase/functions-samples/tree/master/fcm-notifications

To call your HTTPS Cloud Function regurlarly, you have to trigger it via http through a cron-job.

Have a look at: https://firebase.google.com/docs/functions/http-events and https://www.youtube.com/watch?v=CbE2PzvAMxA. You could also use another online CRON service to call the HTTPS Function, like https://www.easycron.com/

Note that you would need to be on Blaze Plan to be able to query an outside service.

Renaud Tarnec
  • 53,666
  • 7
  • 52
  • 80
  • I will take a look into these resources, thank you for your answer Sir! – Kuba May 15 '18 at 11:30
  • @Kuba Hello. Did you have the opportunity to give a try to the solution I proposed? – Renaud Tarnec Sep 30 '18 at 11:52
  • Hello, unfortunantlly I gave up on this topic because if I remember corectly, to use these kind of services require paid plan and I wanted to use this in my educational project and didn't want to spend any money on it. To be honest it I felt like it was kind of too advanced for me to implement this in my app that's why i moved on. Anyway, I really appreacaite your time Sir, next time when I will need this kind of feature maybe I will give it a try :) Thank you. – Kuba Oct 01 '18 at 20:02