Thanks, the answer helped me. Below is the whole cloud function which is currently running fine for me.
exports.givenMinutesNotification = functions.pubsub.schedule('55 23 * * *').onRun(async context => {
const collectionRef = database.collection(Notebook);
const date = new Date(Date.now() + 120*60*1000);
const timestamp = admin.firestore.Timestamp.fromDate(date)
const query = collectionRef.where('status', '==', 'Booked')
.where('startTimeStamp', '>=' , timestamp);
const docs = (await query.get()).docs;
for (const doc of docs) {
whatYouDoForOneDoc(doc);
}
});
async function whatYouDoForOneDoc(doc)
{
let title = "xxxxx";
const docID = doc.id;
let xxxxx = doc.get("xxxxx");
let xxxxx = doc.get("xxxxx");
let xxxxx = doc.get("xxxxx");
let xxxxx = doc.get("xxxxx");
let xxxxx = doc.get("xxxxx");
let xxxxx = doc.get("xxxxx");
let xxxxx = doc.get("xxxxx");
let xxxxx = doc.get("xxxxx");
let xxxxx = doc.get("xxxxx");
let xxxxx = doc.get("xxxxx");
let xxxxx = doc.get("xxxxx");
let xxxxx = doc.get("xxxxx");
let xxxxx = doc.get("xxxxx");
let xxxxx = doc.get("xxxxx");
let xxxxx = doc.get("xxxxx");
let xxxxx = doc.get("xxxxx");
let topic = 'xxxxx';
console.log("-----------------docID<<<<<-----------"+ docID);
var message = {
data:
{
"id": docID,
"xxxxx": xxxxx,
"xxxxx": xxxxx,
"xxxxx": xxxxx,
"xxxxx": xxxxx,
"xxxxx": xxxxx,
"xxxxx": xxxxx,
"xxxxx": xxxxx,
"xxxxx": xxxxx,
"xxxxx": xxxxx,
"xxxxx": xxxxx,
"xxxxx": xxxxx,
"xxxxx": xxxxx,
"xxxxx": xxxxx,
"status": Booked,
"topic": topic,
},
notification: {
title: title,
body: xxxxx,
},
topic: topic,
android: {
notification: {
clickAction: 'com.xxxxx.xxxxx."ActivityName"',
},
}
};
let response = await admin.messaging().send(message);
console.log(response);
}