0
Hello, I am trying to create a Firebase Function for my flutter app to send notification to the token that is in an undercutting without specifying the Document. In Dart I can use "documentId", but in the javascript function returned me "Referenceerror: documentId is not defined". How do I access this undercutting without specifying the document? Thanks in advance.
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
var msgData;
exports.chatTrigger = functions.firestore.document(
'chat/{chatId}/users/{usersId}/messages/{messagesId}'
).onCreate((snapshot, context) => {
msgData = snapshot.data();
return
admin.firestore().collection('chat').document(documentId)
.collection('users').document(documentId)
.collection('messages').get().then((snapshots) => {
var tokens = [];
if (snapshots.empty) {
console.log('No Devices');
return false;
} else {
for (var token of snapshots.docs) {
tokens.push(token.data().token);
}
var payload = {
"notification": {
"title": msgData.name,
"body": msgData.title,
"sound": "default"
},
"data": {
"sendername": msgData.name,
"message": msgData.title,
}
}
return admin.messaging().sendToDevice(tokens, payload).then((response) => {
console.log('Pushed them all');
}).catch((err) => {
console.log(err);
})
}
})
})
Thanks William, really did not know, so I need to reference the way to the document?
– Ricardo Oscar Kanitz