Google Cloud Function Node.js Firebase Url



我有一个Android应用程序,我可以在其中以http格式从我的设备发送推送通知,但现在我想编写一个节点,我希望将推送通知安排在特定日期和时间,有人请帮助我 我长期陷入这个过程

这是我的节点;

 const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);

exports.sendNotification = functions.https.onRequest((req, res) => {
  const to = req.query.to;
  const title = req.query.title;
  const body = req.query.body;
  var payload;
  if (body != undefined && body !== '') {
    payload = {
      notification: {
        title: title,
        body: body
      }
    };
  } else {
    payload = {
      notification: {
        title: title
      }
    };
  }
  var options = {
    priority: "high",
    timeToLive: 60 * 60 * 24
  };
  if (to == 'all') {
    admin.messaging().sendToTopic(to, payload, options)
      .then(function (response) {
        res.send(200, 'ok');
      })
      .catch(function (error) {
        res.send(200, 'failed');
      });
  } else {
    admin.messaging().sendToDevice(to, payload, options)
      .then(function (response) {
        res.send(200, 'ok');
      })
      .catch(function (error) {
        res.send(200, 'failed');
      });
  }
});

这里我有运行时生成推送通知的URL,

https://MyProjectName.cloudfunctions.net/sendNotification?to=all&title=hello&body=EnterBodyHere

现在,请帮助我像这样安排此推送通知

本地主机:8080:/schedulePush?day=17&month=10&hour=12&minute=22

Cloud Functions 目前没有内置的调度机制。 如果要在特定时间执行函数,则需要使用其他一些调度程序。 有一篇关于这一点的博客文章,以及讨论这个问题的示例代码。

最新更新