IONIC push notifications don't trigger for group messages

Notifications don’t trigger nor do they get received on my IONIC app. I am using the following code from the documentation -
However, I get this error message when using getJoinedGroups() -
It works fine for one to one messages. How do I make this work?

Property ‘getJoinedGroups’ does not exist on type ‘typeof CometChat’.ts(2339)

var appID = "APP_ID";
var token = "GENERATED_FCM_TOKEN";
var userUID = "UID_OF_LOGGED_IN_USER";
var appToken;
CometChat.getJoinedGroups().then(groups => {
  CometChat.getAppSettings().then(settings => {
    settings.extensions.forEach(ext => {
      if (ext.id == "push-notification") {
        appToken = ext.appToken;
      }
    });
    var url =
      "https://push-notification-us.cometchat.io/v1/subscribetomany?appToken=" +
      appToken;
    fetch(url, {
      method: "POST",
      headers: new Headers({
        "Content-Type": "application/json"
      }),
      body: JSON.stringify({
        appId: appID,
        fcmToken: token,
        uid: userUID,
        groups: groups,
        platform: "ionic"
      })
    })
      .then(response => {
        if (response.status < 200 || response.status >= 400) {
          console.log("Error subscribing to topics: " +response.status +" - " +response.text());
        } else {
          console.log("Subscribed to all topics");
        }
      })
      .catch(error => {
        console.error(error);
      });
  });
});

Hello @neeraj, can you please let us know which version of the SDK are you using?

I am using “@cometchat-pro/cordova-ionic-chat”: “^2.0.4” version for ionic framework

Hello @neeraj,

Please update to the latest version v2.0.6

1 Like

Still shows error after updating it to v2.0.6-
Property ‘getJoinedGroups’ does not exist on type ‘typeof CometChat’.ts(2339)

Any update on this? I have updated to the version v2.0.6, still it shows the error on getJoinedGroups.

Updated to new version as per the solution.
Getjoinedgroups started working.

2 new issues encountered -

  1. I receive my own message’s notification when I send a message in a group.
  2. Background notification click does not open the application. It just dismisses the notification received.

What’s the solution to fix this?

Hello @neeraj,

  1. Yes, this is the behavior at the moment since we are using a topic-based approach for push notifications. We are currently in the process of migrating our systems to token-based push notifications. The task has been taken up already and is in the development phase at the moment. We will keep you posted on the updates for the same.
  2. Background notification click is not handled by us. They are handled by the plugin you use. We use this plugin and it does work as expected.
1 Like

Hello @mayur.bhandari,
But when receiving notifications for non-group messages, it works as expected. That is, when clicked on the notification, it opens the app.
Initially for one to one messages too, it works fine.
Only the notifications received for “group” disappear once the notification is tapped.
It has to be the issue of the notification payload.

Hi @mayur.bhandari,

Since updating to the new version, none of the message notifications when received in background “open” the app when clicked on them. The notification just dismisses.

Earlier this wasn’t the case.
We were using this method mentioned on the documentation to subscribe -

This would open the app when received in background and worked for foreground and background cases - in iOS and Android both.

We did not implement the group chat feature in this.

subscribeTopic() {

var token = this.FCMToken;
CometChat.getAppSettings().then(settings => {
    var appToken;
    settings.extensions.forEach(ext => {
        if (ext.id == "push-notification"){
            appToken = ext.appToken;
        }
    });
  var userType = "user";
  var UID = this.chatID;
  var appId = this.appID;
  var region = "us";
  var topic = appId + "_" + userType + "_" + UID+ "_ios";
  var url =
    "https://push-notification-"+ region +".cometchat.io/v1/subscribe?appToken=" +
    appToken +
    "";
  fetch(url, {
    method: "POST",
    headers: new Headers({
      "Content-Type": "application/json"
    }),
    body: JSON.stringify({ appId: appId, fcmToken: token, topic: topic })
  })
    .then(response => {
      if (response.status < 200 || response.status >= 400) {
        console.log(
          "Error subscribing to topic: " +
            response.status +
            " - " +
            response.text()
        );
      }
      console.log('Subscribed to "' + topic + '"');
    })
    .catch(error => {
      console.error(error);
    });
});

}

Now, we have changed the method to subscribe to group notifications, and now we have several bugs.

  1. Background notifications received only in Android. Not in iOS
  2. I receive notifications of my own messages when I send them. - Android
  3. On clicking notifications in the background, the app doesn’t open. It just dismisses the notification.
  4. No foreground notifications in iOS.

Hi @mayur.bhandari Any update on this?