【发布时间】:2020-06-17 11:24:16
【问题描述】:
我正在制作一个功能,一旦在他的帐户中添加了新的订单文档,它将发送到用户登录的所有设备。
这是我运行该函数的代码。我的问题是如何从文档中访问 {userEmail}/{orderId}。
export const orderUserNotif = functions.firestore
.document('userAccounts/{userEmail}/orders/{orderId}')
.onCreate(async snapshot => {
const order = snapshot.data();
const querySnapshot = await db
.collection('userAccounts')
.doc("{userEmail}") //Want to access the userEmail from the document address
.collection('tokens')
.get();
const tokens = querySnapshot.docs.map(snap => snap.id);
const payload: admin.messaging.MessagingPayload = {
notification: {
title: order!.title + " with ID " + '{orderId}', //Want to access order id here
body: `Your order has been shipped`,
}
};
return fcm.sendToDevice(tokens, payload);
})
【问题讨论】:
标签: typescript google-cloud-firestore push-notification google-cloud-functions firebase-cloud-messaging