Home > Software design >  Firebase Cloud Function schedule to create document
Firebase Cloud Function schedule to create document

Time:09-15

We have a Flutter project with Firebase setup we would like to create a Firebase cloud function with node js that perform the following:

Every 27th of any month check the subscription date from the subscription collection. And create a new document in invoices collection then finally send an email & FCM with a payment URL.

CodePudding user response:

For that you need to use a scheduled Cloud Function.

More precisely, you need to:

  • Schedule the Cloud Function as desired, for example with 0 0 27 * *, i.e. at 00:00 on day-of-month 27.
  • In the Cloud Function, query your Firestore collection for "checking the subscription dates"
  • In the Cloud Function, send an email. For example through the Trigger Email extension. it's actually just a matter of creating a doc in a Firestore collection, see this article for more details.
  • In the Cloud Function, send the FCM as explained here in the doc.

For the last 3 points, you need to use the Admin SDKs since you are coding in a Cloud Function. (Doc for Firestore and doc for Messaging)

  • Related