Я создал следующую функцию для отправки Уведомление конкретному 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);
});
});
Я сделал это с помощью stati c document . do c ('57MRzgiBwx2gO2JXZ4jo') но я хочу отправить его всем admin означает все документы внутри коллекции admin .
Как можно Я делаю это?