I am trying to give my Firebase Cloud Messaging notification a tag property on Android as described here and here so I can replace notifications that have been received if necessary.
I am using React Native, React Native Firebase and the ConnectyCube API. ConnectyCube works with Firebase to handle user management and push notifications - I have all of this working.
What I can't figure out is how to format my payload object to include optional properties such as tag
as the documentation is fairly cryptic. I am successfully sending a message
which is included in the message
property, and in the ConnectyCube docs you will see that the iOS optional property of badge
is just another property in the payload
object, but in the case of tag
for android, the below code is not working:
export const sendNotification = async (calleeId, callLength, tagUUID) => {
const callersUserName = await getUserNameFromStorage();
const payload = JSON.stringify({
message: callersUserName + '-' + callLength,
tag: tagUUID,
});
const pushParameters = {
notification_type: 'push',
user: { ids: [calleeId] }, // recipients.
environment: 'production', // environment, can be 'production'.
message: ConnectyCube.pushnotifications.base64Encode(payload)
};
ConnectyCube.pushnotifications.events.create(pushParameters, function (error, result) {
});
setTimeout(() => {
const payload2 = JSON.stringify({
message: 'replacement-notification',
tag: tagUUID,
});
const pushParameters2 = {
notification_type: 'push',
user: { ids: [calleeId] }, // recipients.
environment: 'production', // environment, can be 'production'.
message: ConnectyCube.pushnotifications.base64Encode(payload2)
};
ConnectyCube.pushnotifications.events.create(pushParameters2, function (error, result) {
});
}, 3000)
}
When push notifications have the same tag, each notification will be replaced with the newer one which I am trying to mimic with setTimeout
.
I am receiving both messages but the first is not being replaced with the second!
Any help is much appreciated! :)