var functions = require('firebase-functions');
var admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.pushNotification = functions.database.ref('/cancelledClasses/{dsd}').onWrite(change=> {
var test=change.data;
var ids=["505050","121212"];
const message = change.after.val();
var tokens=[]
var rootSnapshot = change.after.ref.parent.parent;
for(i of ids){
rootSnapshot.child("usersToken/"+i).once("value",snapshot => {
if (snapshot.exists()){
newArray.push(tokens.child("token").val());
}})}
var payload = {
"notification":{
"click_action":"FCM_PLUGIN_ACTIVITY",
"title":"From: Mr." + message.senderName,
"body":message.course+" Class has been cancelled !",
"sound":"default",
},
"data":{
"sender": "Mr." + message.senderName,
"click_action":"FCM_PLUGIN_ACTIVITY",
"title": message.course + " Cancelled Class",
"body": " The class of "+message.day + " has been cancelled."
}
}
return admin.messaging().sendToDevice(newArray, payload).then((response) => {
console.log('Pushed notifications');
}).catch((err) => {
console.log(err);
})
})
Подскажите, пожалуйста, как запросить эти данные?У меня есть массив идентификаторов, и я хочу выбрать их токены из документа usersToken… вот мой код и база данных введите описание изображения здесь
введите описание изображения здесь