So basically, I have a function that sends a user an email when a room Status becomes "Available"
exports.sendAvailableRoomEmail = functions.firestore.document('rooms/{roomId}/Status').onUpdate(async (snap, context) => {
const newVal = snap.after.data();
const oldVal = snap.before.data();
if(newVal == "Available"){
// send email
}
})
what I need passed into the function is the specific room that the user wants a notification from: {roomId}
How can I pass that specific room only when the user clicks the notify me button right next to it?
CodePudding user response:
The triggers for a Cloud Function needs to be known when you deploy that function. That means you can either trigger for all rooms, or you can trigger for a specific room, but you can't trigger for rooms that meet a dynamic condition such as yours.
The common way to implement the use-case is to query Firestore inside the Cloud Functions code to find if any user need to be notified for the specific room that was updated.