【发布时间】:2023-03-08 03:29:02
【问题描述】:
我正在尝试为用户编写一个云功能以获取通知。 我有一个任务模型,其中用户指定一个任务并写入他分配任务的另一个用户的电子邮件 ID。
添加上述任务后,它应该向字段“Taskgivento”中指定的用户发送通知
我的用户模型如下 我有一个用户模型,其中包含用户数据和子集合,其中将 fcm 保存在令牌子集合中。子集合的 id 是 fcm 令牌。
我的云功能
export const sendToDevice = functions.firestore
.document('Task/{TaskId}')
.onCreate(async snapshot => {
const Taskdata=snapshot.data()
const querySnapshot = await db
.collection('users')
.doc('HMPibf2dkdUPyPiDvOE80IpOsgf1')
.collection('tokens')
.get();
const tokens = querySnapshot.docs.map(snap => snap.id);
const payload: admin.messaging.MessagingPayload = {
notification: {
title: 'New Order!',
body: 'new notification',
icon: 'your-icon-url',
click_action: 'FLUTTER_NOTIFICATION_CLICK'
}
};
return fcm.sendToDevice(tokens, payload);
});
在 const queryshot 中,我试图过滤用户模型以获取 fcm 令牌,以便它通知 Taskgiven 到 emailid 的 uid。
上述功能有效。 我在上面的模型中手动编写了uid。 我需要它来搜索数据库并填写taskgivento的电子邮件的uid。 我应该如何进行 我试过像在 dart 中那样写 where('email','=','Taskdata.Taskgivento') 但没有用。它给出了一个错误。
【问题讨论】:
标签: typescript firebase google-cloud-firestore google-cloud-functions