Google Cloud Function Node.js Firebase URL

I have an Android app in which I can send a 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 at a specific date and time, Someone help me, I'm stuck in this process since ancient times

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 a url when triggering a push notification,

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

Now please help me plan this push notification like this

local: 8080:? / SchedulePush day = 17 & month = 10 & hour = 12 & minute = 22

+4
source share
1 answer

. - , . , , .

0

Source: https://habr.com/ru/post/1679404/


All Articles