Я хотел бы знать, как отправить облачное сообщение firebase через бэкэнд моей функции firebase. Похоже, что есть проблема с полезной нагрузкой. Я хотел бы знать, как решить проблему. Нужен ли интерфейс для полезной нагрузки? Заранее спасибо!
Ошибка
Error sending message: { Error: Invalid JSON payload received. Unknown name "message" at 'message': Cannot find field.
at FirebaseMessagingError.FirebaseError [as constructor] (/home/ubuntu/environment/****/functions/node_modules/firebase-admin/lib/utils/error.js:42:28)
Функция уведомления (обновленный рабочий код)
async function notification(
notificationType: string,
registrationToken: string,
objectText: string
) {
const matchesRef = db.collection("notifications");
const notificationObject = await matchesRef.doc(notificationType).get();
if (notificationObject.exists) {
const tokenMessage: admin.messaging.Message = {
token: registrationToken,
notification: {
title: notificationObject.data()!.title,
body: notificationObject.data()!.body
},
data: {
click_action: "FLUTTER_NOTIFICATION_CLICK",
title: notificationObject.data()!.title,
body: notificationObject.data()!.body
},
android: {
priority: "high"
},
apns: {
headers: {
"apns-priority": "5"
}
}
};
admin
.messaging()
.send(tokenMessage)
.then((response: string) => {
// Response is a message ID string.
logMe(`Successfully sent message: ${response}`);
return response;
})
.catch((error: string) => {
console.log("Error sending message:", error);
});
}
return false;
}