简体   繁体   中英

Flutter Firebase: Send notifications from cloud functions

I have a collection, 'users', where each document holds an int votesUseable. I have a cloud function setup to reset all users votes everyday:

export const resetDay = functions.pubsub.schedule("00 22 * * *")
    .timeZone("America/New_York")
    .onRun(async () => {
      await admin.firestore().collection("users")
          .get().then((querySnapshot) => {
            querySnapshot.forEach(async (doc) => {
              // eslint-disable-next-line max-len
              await doc.ref.update({"votesUsable": 2});
            });
          })
          .catch((error) => {
            console.log("Error getting documents: ", error);
          });
      return null;
    });

Id like to add a push notification sent to each user, however I am having trouble implementing it. I am trying to follow the documentation example: https://github.com/firebase/functions-samples/blob/main/fcm-notifications/functions/index.js , however it feels very different from the way I implemented the function. Does anyone have any ideas? Im also using this with a flutter app, if that makes a difference. Thank you

If you're wondering about the code that loads the tokens from the database, the example you linked reads them from the Realtime Database while you read them from Firestore. While both databases are part of Firebase, they are completely separate and have a quite different API.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM