简体   繁体   中英

Google Cloud Function Node.js Firebase Url

I have an Android app where I am able to send push notification from my device in http format, but now I want to write a node where I want the push notification to be scheduled on a particular date and time, Someone please help me I am stuck in this process from a long time

Here is my 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');
      });
  }
});

Here I have URL when run the push notification is generated,

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

Now, please help me in scheduling this push notification like this

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

Cloud Functions currently does not have a built-in scheduling mechanism. You'll need to make use of some other scheduler if you want to execute a function at a particular time. There's a blog post that was written about this, and sample code that discusses this as well.

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