tinycreative / react-native-intercom

React Native wrapper for Intercom.io
MIT License
406 stars 280 forks source link

Android docs outdated #362

Closed nabilfreeman closed 2 years ago

nabilfreeman commented 4 years ago

Intercom 5 is due to be discontinued and will stop working in June 2020.

Users need to install Intercom 6:

implementation 'io.intercom.android:intercom-sdk:6.+'
implementation 'com.google.firebase:firebase-messaging:20.+'

https://github.com/intercom/intercom-android

Additionally the MainMessagingService example for combining Intercom pushes with react-native-firebase no longer works due to a major version change on that library.

I'm currently integrating this library with all the newer stuff - will post in this issue the necessary changes and then we can hopefully update the docs!

nabilfreeman commented 4 years ago

I managed to get things mostly working without much stress. Autolinking does work so it's not necessary to do any gradle steps apart from the intercom-android docs. Pretty cool.

I haven't tested push notifications yet.

Vitiell0 commented 4 years ago

I want able to build when trying to use intercom-sdk:6. @nabilfreeman what did you have to change to get it to build properly?

nabilfreeman commented 4 years ago

What build error are you getting @Vitiell0 ? As far as I recall it just worked out of the box. This is the first native module I implemented after rebuilding the app on a RN 61 platform.

Hard for me to tell you my config now as I've added tons of other bits to the build 🙈

nabilfreeman commented 4 years ago

To get react-native-intercom working with the newest React Native Firebase (there is an example for this in the docs...

The change is quite simple to be honest, RNFirebaseMessagingService has changed to ReactNativeFirebaseMessagingService. That's it. Also, the original implementation was missing something for the Intercom push token that also needs to be present.

Feel free to remove the below logs, I found them really helpful.

PushNotificationService.java (make sure the name matches in AndroidManifest.xml)

package com.your.package.name.here;

import io.intercom.android.sdk.push.IntercomPushClient;
import io.invertase.firebase.messaging.ReactNativeFirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;
import android.util.Log;
import java.util.Map;

public class PushNotificationService extends ReactNativeFirebaseMessagingService {
    private static final String TAG = "PushNotificationService";
    private final IntercomPushClient intercomPushClient = new IntercomPushClient();

    @Override
    public void onNewToken(String refreshedToken) {
        intercomPushClient.sendTokenToIntercom(getApplication(), refreshedToken);

        super.onNewToken(refreshedToken);
    }

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        Map message = remoteMessage.getData();

        Log.d(TAG, "Hi I received a push message: " + message.toString());

        if (intercomPushClient.isIntercomPush(message)) {
            Log.d(TAG, "The message is from Intercom.");
            intercomPushClient.handlePush(getApplication(), message);
        } else {
            Log.d(TAG, "The message is from Firebase.");
            super.onMessageReceived(remoteMessage);
        }
    }
}
waclock commented 4 years ago

Thanks @nabilfreeman, the implementation you mentioned works with react-native-firebase 6 (the reworked version).

I added this to the AndroidManifest.xml

      <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
      <service android:name=".PushNotificationService"
      android:enabled="true"
      android:exported="true" >
        <intent-filter>
          <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
      </service>

For any newcomers

gabriel-franzoni-pier commented 4 years ago

This should definitely have a section on README.md

StarryFire commented 4 years ago
Intercom.addEventListener(Intercom.Notifications.UNREAD_COUNT, callback);
      return () => {
        Intercom.removeEventListener(
          Intercom.Notifications.UNREAD_COUNT,
          callback,
        );
      };
    })

the callback doesn't get called even when there are unread messages until you call Intercom.displayMessenger for the first time, after that it works fine.

This is only happening for Android, iOS is working fine. Any ideas on how to fix this?

aibrahim3546 commented 4 years ago

@nabilfreeman I am getting this error

error: package io.invertase.firebase.messaging does not exist

what am i lacking of? any idea?

nlabofa commented 4 years ago

Any luck on this?

tingzhouu commented 3 years ago

hey @aibrahim3546 i got the same error. i added @react-native-firebase/app and @react-native-firebase/messaging to fix it.

ptdede commented 3 years ago

@tingzhouu @aibrahim3546 Don't forget to remove implementation "com.google.firebase:firebase-messaging:20.+" from your app build.gradle. Unless @react-native-firebase/app and @react-native-firebase/messaging cannot autolinked properly. I was stuck here.