What I am trying to do is run a job when at specific time it will fetch a specific field from my document and send a notification to the user using the fetched contents.
But the problem is notification body remains empty. I tried to log if whatever I am fetching from the documents are empty or not. But as per the logs the logs the quote variable is not empty.
Please point me what I am missing
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);
});