使用firebase中的onUpdate函数,如何从前端传入信息?

Using the onUpdate function in firebase, how do I pass in information from the front end?

基本上,我有一个功能,可以在房间状态变为“可用”时向用户发送电子邮件

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
    }
})

我需要传递到函数中的是用户希望收到通知的特定房间:{roomId}

只有当用户单击旁边的通知我按钮时,我如何才能通过该特定房间?

当您部署该功能时,需要知道该功能的触发器。这意味着您可以触发所有房间,也可以触发特定房间,但不能触发满足动态条件的房间,例如您的房间。

实现 use-case 的常用方法是查询 Firestore inside Cloud Functions 代码,以查找是否需要为特定房间通知任何用户已更新。