Мне трудно передать приведенное ниже от терминала к функциям Firebase. По сути, пользователи должны начать получать уведомление, когда сообщение отправляется другому пользователю. < /P>
const admin = require("firebase-admin");
const functions = require("firebase-functions");
admin.initializeApp();
exports.sendNotificationOnNewMessage = functions.firestore
.document("messages/{s}/messages/{r}/pm/{id}")
.onCreate(async (snap, context) => {
const messageData = snap.data();
const {s, r} = context.params;
const u = await admin.firestore().collection("users").doc(r).get();
if (!u.exists) {
console.log(`User ${r} not found in users collection.`);
return null;
}
const receiverToken = u.data().token;
if (!receiverToken) {
console.log(`Skipping notification.`);
return null;
}
const payload = {
notification: {
title: `New message from ${s}`,
body: messageData.content,
},
token: u.data().token,
};
try {
await admin.messaging().send(payload);
console.log("Notification sent successfully");
} catch (error) {
console.error("Error sending notification:", error);
}
return null;
});
< /code>
Также у меня есть правила Firestore, как ниже < /p>
match /messages/{s}/messages/{r}/pm/{id} {
allow read, write: if request.auth != null &&
(request.auth.uid == s || request.auth.uid == r);
}
< /code>
Я продолжаю получать эту ошибку < /p>
TypeError: functions.firestore.document is not a function
at Object. (/Users/x/Desktop/y/functions/index.js:5:6)
at Module._compile (node:internal/modules/cjs/loader:1562:14)
at Object..js (node:internal/modules/cjs/loader:1699:10)
at Module.load (node:internal/modules/cjs/loader:1313:32)
at Function._load (node:internal/modules/cjs/loader:1123:12)
at TracingChannel.traceSync (node:diagnostics_channel:322:14)
at wrapModuleLoad (node:internal/modules/cjs/loader:217:24)
at Module.require (node:internal/modules/cjs/loader:1335:12)
at require (node:internal/modules/helpers:136:16)
Error: Functions codebase could not be analyzed successfully. It may have a syntax or runtime error
Мне трудно передать приведенное ниже от терминала к функциям Firebase. По сути, пользователи должны начать получать уведомление, когда сообщение отправляется другому пользователю. < /P> [code]const admin = require("firebase-admin"); const functions = require("firebase-functions"); admin.initializeApp(); exports.sendNotificationOnNewMessage = functions.firestore .document("messages/{s}/messages/{r}/pm/{id}") .onCreate(async (snap, context) => { const messageData = snap.data(); const {s, r} = context.params; const u = await admin.firestore().collection("users").doc(r).get(); if (!u.exists) { console.log(`User ${r} not found in users collection.`); return null; } const receiverToken = u.data().token; if (!receiverToken) { console.log(`Skipping notification.`); return null; } const payload = { notification: { title: `New message from ${s}`, body: messageData.content, }, token: u.data().token, }; try { await admin.messaging().send(payload); console.log("Notification sent successfully"); } catch (error) { console.error("Error sending notification:", error); } return null; });
< /code> Также у меня есть правила Firestore, как ниже < /p> match /messages/{s}/messages/{r}/pm/{id} { allow read, write: if request.auth != null && (request.auth.uid == s || request.auth.uid == r); } < /code> Я продолжаю получать эту ошибку < /p> TypeError: functions.firestore.document is not a function at Object. (/Users/x/Desktop/y/functions/index.js:5:6) at Module._compile (node:internal/modules/cjs/loader:1562:14) at Object..js (node:internal/modules/cjs/loader:1699:10) at Module.load (node:internal/modules/cjs/loader:1313:32) at Function._load (node:internal/modules/cjs/loader:1123:12) at TracingChannel.traceSync (node:diagnostics_channel:322:14) at wrapModuleLoad (node:internal/modules/cjs/loader:217:24) at Module.require (node:internal/modules/cjs/loader:1335:12) at require (node:internal/modules/helpers:136:16)
Error: Functions codebase could not be analyzed successfully. It may have a syntax or runtime error [/code] Как это исправить?
Я продолжаю получать это сообщение об ошибке, когда пытаюсь запустить свое ионное приложение на своих устройствах Android.
Большая часть вопросов, доступных с тем же сообщением, имеет отказ в разрешении, но в моем случае это Strong>...
Я продолжаю получать это сообщение об ошибке, когда пытаюсь запустить свое ионное приложение на своих устройствах Android.
Большая часть вопросов, доступных с тем же сообщением, имеет отказ в разрешении, но в моем случае это Strong>...
Я пытаюсь запустить функцию облака Firebase (V2) только тогда, когда в документ Firestore добавляется конкретное вложенное поле. Это означает, что значение для этого конкретного поля должно быть неопределенным в Event.data.fore и определено в...