customerio / customerio-reactnative

MIT License
25 stars 13 forks source link

Expo + CIO + Push notifications Intercom #332

Closed TwistedMinda closed 1 month ago

TwistedMinda commented 1 month ago

Hello, We have an issue when using Expo + CustomerIO + Intercom for notifications, on Android. We don't receive notifications from Intercom after installing CustomerIO. On iOS, everything works fine, we receive notifications from CustomerIO as well as from Intercom without any issue.

SDK version:

{
    "@intercom/intercom-react-native": "^7.1.3",
    "customerio-expo-plugin": "^1.0.0-beta.15",
    "customerio-reactnative": "3.7.0"
}

Environment: Android only

Are logs available? No logs available

Describe the bug Push notifications are not received from Intercom after installing CIO SDK.

To Reproduce

Expected behavior We would expect to be able to receive both CIO and Intercom notifications.

Additional context For context, we already have the setup CustomerIO + Intercom and receiving notifications from both, in our react-native setup (without Expo). The problem appears when we try to migrate to Expo. Initially, the problem is the same on React-Native, and we had to override the FirebaseMessagingService to make it work, dispatching in both cases depending on Intercom or CustomerIO, see below.

package com.goliaths.app;

import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;
import com.intercom.reactnative.IntercomModule;
import io.customer.messagingpush.CustomerIOFirebaseMessagingService;

public class MainNotificationService extends FirebaseMessagingService {

  @Override
  public void onNewToken(String refreshedToken) {
    CustomerIOFirebaseMessagingService.onNewToken(this, refreshedToken);
    IntercomModule.sendTokenToIntercom(getApplication(), refreshedToken);
    //DO LOGIC HERE
  }

  public void onMessageReceived(RemoteMessage remoteMessage) {
    boolean handled = CustomerIOFirebaseMessagingService.onMessageReceived(getApplication(), remoteMessage);
    if (handled) {
      // Handled by customerIO
    } else if (IntercomModule.isIntercomPush(remoteMessage)) {
      IntercomModule.handleRemotePushMessage(getApplication(), remoteMessage);
    } else {
      // HANDLE NON-INTERCOM MESSAGE
    }
  }
}

Modifying the native files when using Expo becomes very complicated (using the custom plugins) and it doesn't seem worth to migrate to Expo if we still need to manage this kind of native issues.

Is there a way for you to handle this on the CustomerIO side directly? Or maybe do we need to ask to Intercom if they could do it? I am really not sure who has to take action for this setup "Expo + CustomerIO + Intercom" to work gracefully.

This is the last step preventing us to fully migrate to Expo, so I'm really looking forward for a solution on this. Maybe someone already has a plugin that would create the FirebaseMessagingService just like in a react-native setup?

Thank you very much

Shahroz16 commented 1 month ago

Hey, @TwistedMinda thank you for the detailed explanation here, it is very helpful.

Okay, so I understand the issue and I have been thinking about the possible solutions here, I could come up with 4 and you can weigh your pros and cons.

My recommendation would be to either keep using react native or create a custom plugin for now, until Intercom adds more support/customization with expo or JS methods.

TwistedMinda commented 1 month ago

Hello, thank you for your very fast response!

Okay those 4 options are also the ones I had in mind.

Custom Expo Plugin: This solution doesn't seem viable for us as this just adds a lot of complexity and maintenance to something that was supposed to become simpler when going to Expo (not having to deal with native files), and is already working on our current setup. Of course, if someone in the community creates it, we would be happy to use it!

Keep using react-native: This was and is probably going to be our go-to until there is a cleaner and simpler way to setup Expo without having to deal with native files.

Callbacks: That would be a clean way to fix the problem but I think Intercom might need to make some changes because there is no exposed JS function to delegate a notification for Intercom to display it, as of now.

Use a 3rd party SDK: Same for Callbacks solution, the only possible way seem to display the Intercom notification with their logic is to dispatch the notification right from the FirebaseMessagingService, so won't fit Intercom JS implementation.

So again, I believe we can wait further in order to make a smoother transition to Expo and not have to deal with native files. It is good to know that this should be available at some point.

I think I might also post this to Intercom Developer Forum to see what they think about it!

Thanks again for your quick response

Shahroz16 commented 1 month ago

Awesome, makes sense. Closing this now, feel free to re-open or create another ticket if you have any more questions.