4
我有一個Android應用程序,我可以通過http格式從我的設備發送推送通知,但現在我想寫一個節點,我希望推送通知安排在特定的日期和時間,有人請幫助我,我被困在這個過程中,從很長一段時間Google Cloud Function Node.js Firebase Url
這裏是我的節點;
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天= 17 &月= 10 &小時= 12 &分鐘= 22
那麼我的朋友說,你只需要創建Node.js端點來調度推送通知。日期/時間網址查詢......................... 一樣,https://www.npmjs.com/package/cron 使用這個庫,它有時區,並使用它們........... 我嘗試過,但無法弄清楚。 –
該包不適用於雲端函數,因爲它沒有運行一直處於活動狀態的單個node.js實例。相反,多個託管實例可隨着您的功能需求隨時間而變化,並且隨着時間的推移而變化。 –
那麼你有沒有關於如何在預定日期和時間運行鏈接的建議? –