Я пытался отправить уведомление через функции Firebase
, когда данные обновляются в базе данных Firebase
.Я предполагаю, что это из-за того, как я ссылался на свои переменные в полезной нагрузке, но я не могу определить ошибку.Ниже logcat.
Error sending message: { Error: Messaging payload contains an invalid
value for the "data.name" property. Values must be strings.
at FirebaseMessagingError.Error (native)
at FirebaseMessagingError.FirebaseError [as constructor] (/user_code/node_modules/firebase-admin/lib/utils/error.js:39:28)
at FirebaseMessagingError.PrefixedFirebaseError [as constructor] (/user_code/node_modules/firebase-admin/lib/utils/error.js:85:28)
at new FirebaseMessagingError (/user_code/node_modules/firebase-admin/lib/utils/error.js:241:16)
at /user_code/node_modules/firebase-admin/lib/messaging/messaging.js:782:27
at Array.forEach (native)
at /user_code/node_modules/firebase-admin/lib/messaging/messaging.js:779:32
at Array.forEach (native)
at Messaging.validateMessagingPayload (/user_code/node_modules/firebase-admin/lib/messaging/messaging.js:772:21)
at /user_code/node_modules/firebase-admin/lib/messaging/messaging.js:609:37
errorInfo:
{ code: 'messaging/invalid-payload',
message: 'Messaging payload contains an invalid value for the "data.name" property. Values must be strings.' },
codePrefix: 'messaging' }
Ниже мой код JS:
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
exports.sendNotification = functions.database.ref('/Lecture_Materials/{MIS}/{MISId}/name')
.onWrite((change, context) => {
// Grab the current value of what was written to the Realtime Database.
var eventSnapshot = change.after.val();
var str1 = "Lecture note uploaded is: ";
var str = str1.concat(eventSnapshot.name);
console.log(str);
var topic = "Management.Information.System";
var payload = {
data: {
name: eventSnapshot,
}
};
// Send a message to devices subscribed to the provided topic.
return admin.messaging().sendToTopic(topic, payload)
.then(function(response) {
// See the MessagingTopicResponse reference documentation for the
// contents of response.
console.log("Successfully sent message:", response);
return;
})
.catch(function(error) {
console.log("Error sending message:", error);
});
});
Кто-нибудь мне поможет?В чем моя ошибка?