0

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! :)

Mr. Robot
  • 1,334
  • 6
  • 27
  • 79

1 Answers1

1

tag is a payload key for Notification type pushes, but ConnectyCube sends all pushes as Data.

With Data pushes there is full control over what to do with notification (to show or not to show), so there is a way to add a code in app to hide an existing notification and then show a new one once a Data push received

  • Ok thank you very much - is it possible for you to give me an example of how / where I would do this in the code? At the moment I'm worried I might have to deploy my own XXMP server to do this and handle all notifications myself.. – Mr. Robot Jan 17 '20 at 07:23