Firebase Admin SDK - andrehtissot/cordova-plugin-firebase-extended-notification-app-example GitHub Wiki
The examples given in this github project are based on the curl approach, but if you intend to use the Firebase Admin SDK, you may get the error Messaging payload contains an invalid value for the "data.notificationOptions" property. Values must be strings
due to the fact that the data
attributes cannot natively contain objects, only strings.
When the notificationOptions
are sent via curl, it's received as a String and parsed to a JSONObject.
To force the same behavior, it's necessary to stringify the notificationOptions
JSON before send through Firebase.
The code may look like this:
var payload = {
data: {
dataValuesToGetWhenClickedOn: '111',
notificationOptions: JSON.stringify({
id: '4',
title: 'Title test',
text: 'Test message',
smallIcon: 'drawable/icon',
largeIcon: 'https://avatars2.githubusercontent.com/u/1174345?v=3&s=96',
autoCancel: true,
vibrate: [200,300,200,300],
color: '0000ff',
headsUp: true,
sound: true
})
}
};
admin.messaging().sendToTopic('myTopic', payload);
This way there no mixing notification options and app-related data and more configurations patterns are allowed to be used in the future.