【问题标题】:send FCM Push Notification after every 3 hours interval using nodejs?使用nodejs每隔3小时发送一次FCM推送通知?
【发布时间】:2020-10-24 11:18:35
【问题描述】:

我正在尝试向昨天在我们平台上活跃的用户发送推送通知,以便每天早上以自动方式发送一次,这是我能够做到的。但是在 4 小时后发送,我无法思考如何在 4 小时后发送它们,就像我在早上 6 点左右发送推送通知,然后在上午 10 点左右,然后在下午 2 点左右,然后在下午 6 点左右发送,但在下午 6 点之后我不想向用户发送推送通知。我该如何解决这个问题。

基本上,有一次我会查询昨天开始时间和结束时间之间的时间戳,然后我将能够提取昨天的活跃用户,然后我可以获得 devicetoken,然后我只是发送推送通知。但是如何间隔发送请提出任何解决方案

    const start = momentTz()
        .tz("Asia/Kolkata")
        .subtract(1, "days")
        .startOf("day")
        .format();
    
      const end = momentTz()
        .tz("Asia/Kolkata")
        .subtract(1, "days")
        .endOf("day")
        .format();
      const profileSnapshot = await db
        .collection("Profiles")
        
         .where("lastQueryFrom", ">=", momentTz(start).valueOf())
         .where("lastQueryFrom", "<=", momentTz(end).valueOf())
        .get();
    
      const profile = [];
      profileSnapshot.forEach((doc) => {
        profile.push(doc.data().phoneNumber);
//here i will get the device token and i will run the fcm push notification logic
      });
      console.log(profile.length);

【问题讨论】:

    标签: node.js firebase google-cloud-functions firebase-cloud-messaging amazon-sns


    【解决方案1】:

    Firebase 有scheduled functions,您可以安排一个间隔来执行您提到的检查并发送推送通知。您可以每 4 小时安排一次。您当然可以在您提到的时间范围之外提前退出该功能。

    exports.scheduledFunction = functions.pubsub.schedule('every 5 minutes').onRun((context) => {
      // get active users and send push notification
      return null;
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-01-01
      • 1970-01-01
      • 2020-09-17
      • 1970-01-01
      • 2022-08-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多