【发布时间】:2019-12-03 06:15:19
【问题描述】:
我正在创建一个 Firebase 云函数,该函数会在特定用户的评分更新时向其发送消息(来自 Firestore 的触发器)。
到目前为止我有;
// Send New Rating Notifications
exports.sendNewRatingNotification = functions.firestore.document('users/{userID}/ratings/{ratingID}').onWrite((context) => {
// Get {userID} and field of fcmToken and set as below
var fcmToken = fcmToken;
var payload = {
notification: {
title: "You have recieved a new rating",
body: "Your rating is now..."
}
}
return admin.messaging().sendToDevice(fcmToken, payload).then(function(response) {
console.log('Sent Message', response);
})
.catch(function(error) {
console.log("Error Message", error);
})
})
我需要访问 {userID} 文档的 fcmToken 字段以使用下面如何通过使用通配符 {userID} 来处理此问题
【问题讨论】:
标签: javascript google-cloud-firestore google-cloud-functions