我创建了以下功能,用于将通知发送给特定的 fcmToken
/**
* FOR ADMIN
*/
exports.adminNotification = functions.firestore.document('/pending_videos/{pushId}').onCreate(async (snap, context) => {
const newValue = snap.data();
const title = newValue.title;
const category = newValue.category;
const uploadedBy = newValue.uploadedBy;
// Grab the current value of what was written to the Realtime Database.
let adminRef = admin.firestore().collection('admin').doc('57MRzgiBwx2gO2JXZ4jo');
let token;
let getDoc = adminRef.get()
.then(doc => {
if (!doc.exists) {
console.log('No such document!');
} else {
console.log('Document data:', doc.data().url);
token = doc.data().token;
// Create a notification
const payload = {
data: {
title: "Jain Stavan Video Status",
body: title + " video uploaded in " + category + " category by " + uploadedBy + ".",
sound: "default"
},
};
//Create an options object that contains the time to live for the notification and the priority
const options = {
priority: "high",
timeToLive: 60 * 60 * 24
};
console.log('Sending notification');
return admin.messaging().sendToDevice(token, payload, options);
}
})
.catch(err => {
console.log('Error getting document', err);
});
});
我已经使用静态文档 .doc('57MRzgiBwx2gO2JXZ4jo')完成了此操作,但我想将其发送给所有 admin ,这意味着 admin中的所有文档收藏。
我该怎么做?