android - 谷歌云功能 Node.js Firebase 网址

标签 android node.js firebase push-notification google-cloud-functions

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

这是我的 Node ;

 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

现在,请帮我安排这样的推送通知

localhost:8080:/schedulePush?day=17&month=10&hour=12&minute=22

最佳答案

Cloud Functions 目前没有内置的调度机制。如果您想在特定时间执行某个功能,则需要使用其他一些调度程序。有一个 blog post那是关于这个的,和sample code也讨论了这个问题。

关于android - 谷歌云功能 Node.js Firebase 网址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44581665/

相关文章:

android - android 在线访问mysql数据库

android - 如何在android中查找网络启用状态?

javascript - 如何在 NodeJs 中断开与 tcp 套接字的连接

node.js - Grunt cwd 选项问题

angular - Firestore - 用户收藏夹数据结构建议

ios - Pod Repo Remove Master 有什么作用?

node.js - React Native + Firebase + Expo 版本三角问题

android - fragment 布局加载延迟

android - 在 Android 游戏中将 java.nio.IntBuffer 传递给 C 函数

linux - bcrypt_lib.node : undefined symbol: node_module_register