尝试根据他们选择的语言主题向其他用户发送通知。
在我的应用中,我向用户订阅了:
_fcm.subscribeToTopic('english');
这是我的index.js代码
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
var newData;
exports.messageTrigger = functions.firestore.document('notifications/default/{languageId}/{messagesId}').onCreate(async (snapshot, context) => {
newData = snapshot.data();
const payload = {
notification: {
title: newData.message,
body: newData.body,
},
data: {
click_action: 'FLUTTER_NOTIFICATION_CLICK',
message: newData.message,
}
};
if (context.param.languageId === "english") {
await admin.messaging().sendToTopic('english', payload);
}
else if (context.param.languageId=== "arabic") {
await admin.messaging().sendToTopic('arabic', payload);
}
});
这是它在firebase上的函数登录上给我的错误:
messageTrigger
TypeError: Cannot read property 'languageId' of undefined at exports.messageTrigger.functions.firestore.document.onCreate (/srv/index.js:21:19) at cloudFunction (/srv/node_modules/firebase-functions/lib/cloud-functions.js:132:23) at /worker/worker.js:825:24 at <anonymous> at process._tickDomainCallback (internal/process/next_tick.js:229:7)