【发布时间】:2020-11-28 20:50:41
【问题描述】:
我要做的是在特定时间运行作业,它将从我的文档中获取特定字段并使用获取的内容向用户发送通知。
但问题是通知正文仍然是空的。我试图记录我从文档中获取的内容是否为空。但是根据日志,引用变量不为空。
请指出我错过了什么
exports.sendDailyQuotes = functions.pubsub.schedule('0 7 * * *').timeZone('Asia/Kolkata').onRun(async (context) => {
var today = new Date();
today.setDate(today.getDate() + 1);
var currMonth = today.getMonth() + 1;
var dateQry = today.getDate() + "-" + currMonth;
var quote;
admin.firestore().collection('quotes').doc(dateQry).get().then(snapper => {
quote = snapper.data().english;
return "";
}).catch(reason => {
console.log(reason);
});
var dailyQuote = {
notification : {
title : "Daily Quote",
body : quote, //This is staying empty
},
topic : 'notifications'
}
let response = await admin.messaging().send(dailyQuote);
console.log(response);
});
【问题讨论】:
标签: javascript firebase google-cloud-firestore google-cloud-functions firebase-cloud-messaging