React-native-intercom: Not receiving push notifications in android

Created on 18 Feb 2019  路  17Comments  路  Source: tinycreative/react-native-intercom

We are using firebase and react-native-firebase to integrate it with our react-native platform. We have followed all the steps which were mentioned in the intercom and firebase documentation. From firebase, we are able to send/receive notifications in our app but it is not working when the notification is triggered from the intercom. Please let me know what all config files should I attach to give you some more context about the problem.

Thanks in advance

Most helpful comment

Section added to README:

Here's an example if you're using react-native-firebase as your existing FCM setup:

I. Add a new file if you don't have one (android/app/src/main/java/com/YOUR_APP/MainMessagingService.java)

package com.YOUR_APP;
import io.invertase.firebase.messaging.*;
import android.content.Intent;
import android.content.Context;
import io.intercom.android.sdk.push.IntercomPushClient;
import io.invertase.firebase.messaging.RNFirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;
import android.util.Log;
import java.util.Map;

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

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

        if (intercomPushClient.isIntercomPush(message)) {
            Log.d(TAG, "Intercom message received");
            intercomPushClient.handlePush(getApplication(), message);
        } else {
            super.onMessageReceived(remoteMessage);
        }
    }
}

II. Then add the following code to android/app/src/main/AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.YOUR_APP"

  ...other configuration here...

>
  <application

    ...other configuration here...

    xmlns:tools="http://schemas.android.com/tools"
  >

    <!-- ...other configuration here... -->
    <!-- ...ADD THE SERVICE BELOW... -->
    <service
      android:name=".MainMessagingService"
      android:enabled="true"
      android:exported="true">
        <intent-filter>
          <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
    </service>
  </application>
</manifest>

All 17 comments

We are using firebase and react-native-firebase to integrate it with our react-native platform. We have followed all the steps which were mentioned in the intercom and firebase documentation. From firebase, we are able to send/receive notifications in our app but it is not working when the notification is triggered from the intercom. Please let me know what all config files should I attach to give you some more context about the problem.

Thanks in advance

Hi @Dhruv56, this PR adds an example on how push notifications can be configured for users that are using react-native-firebase.

Section added to README:

Here's an example if you're using react-native-firebase as your existing FCM setup:

I. Add a new file if you don't have one (android/app/src/main/java/com/YOUR_APP/MainMessagingService.java)

package com.YOUR_APP;
import io.invertase.firebase.messaging.*;
import android.content.Intent;
import android.content.Context;
import io.intercom.android.sdk.push.IntercomPushClient;
import io.invertase.firebase.messaging.RNFirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;
import android.util.Log;
import java.util.Map;

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

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

        if (intercomPushClient.isIntercomPush(message)) {
            Log.d(TAG, "Intercom message received");
            intercomPushClient.handlePush(getApplication(), message);
        } else {
            super.onMessageReceived(remoteMessage);
        }
    }
}

II. Then add the following code to android/app/src/main/AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.YOUR_APP"

  ...other configuration here...

>
  <application

    ...other configuration here...

    xmlns:tools="http://schemas.android.com/tools"
  >

    <!-- ...other configuration here... -->
    <!-- ...ADD THE SERVICE BELOW... -->
    <service
      android:name=".MainMessagingService"
      android:enabled="true"
      android:exported="true">
        <intent-filter>
          <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
    </service>
  </application>
</manifest>

Thank you so much @carlosa54 for the quick response. Above solution worked like a charm.

No luck for me, I precisely followed @carlosa54 instructions, still not receiving anything when app is in the background or closed. Isn't it supposed to add a tray notification?
Otherwise it's working in app.

In logcat, I can't see any Intercom message received entries, so I believe onMessageReceived is never triggered :/
Regular FCM push notifications work by the way.

@Annihil Looks like you're not receiving push notifications. The in-app message is handled by the SDK and doesn't have to do with push notifications.

  1. Did you enabled push notifications for android and added your FCM server key to Intercom? verify the docs here

  2. Are you sending the FCM token to Intercom?

Send FCM token directly to Intercom for push notifications (Android only)

Firebase.messaging().getToken()
  .then((token) => {
    console.log('Device FCM Token: ', token);
    Intercom.sendTokenToIntercom(token);
});

@carlosa54 I wasn't aware of that setting, it was indeed not enabled.
Yes I'm sending the fcm token to intercom.
Even thought, unfortunately it still does not work.

2019-02-19 11:45:48.655 4873-4892/? W/ProcStatsManager: No process com.xxxxx/10094 for service io.intercom.android.sdk.fcm.IntercomFcmMessengerService
2019-02-19 16:02:03.778 5222-5222/com.xxxxx W/Intercom聽realtime: No realtime endpoints present so we can't connect
2019-02-19 16:02:30.670 5222-5289/com.xxxxx I/Intercom: sendTokenToIntercom

It seems that Intercom does not send anything to the app when chatting...

@carlosa54 I wasn't aware of that setting, it was indeed not enabled.
Yes I'm sending the fcm token to intercom.
Even thought, unfortunately it still does not work.

2019-02-19 11:45:48.655 4873-4892/? W/ProcStatsManager: No process com.xxxxx/10094 for service io.intercom.android.sdk.fcm.IntercomFcmMessengerService
2019-02-19 16:02:03.778 5222-5222/com.xxxxx W/Intercom聽realtime: No realtime endpoints present so we can't connect
2019-02-19 16:02:30.670 5222-5289/com.xxxxx I/Intercom: sendTokenToIntercom

It seems that Intercom does not send anything to the app when chatting...

Can you share your build.gradle? I'm thinking there might be something missing with the Intercom setup

Sure

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.xxxxx">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.USE_FINGERPRINT" />

    <application
        android:name=".MainApplication"
        android:allowBackup="false"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">
        <activity
            android:name=".MainActivity"
            android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
            android:label="@string/app_name"
            android:launchMode="singleTask"
            android:screenOrientation="portrait"
            android:windowSoftInputMode="adjustResize">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
        <service
            android:name=".MainMessagingService"
            android:enabled="true"
            android:exported="true">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT" />
            </intent-filter>
        </service>
        <service android:name="io.invertase.firebase.messaging.RNFirebaseMessagingService">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT" />
            </intent-filter>
        </service>
    </application>

</manifest>

Regular FCM push notifications are triggering onMessageReceived of the MainMessagingService, but it's not called while sending message from Intercom web to a registered mobile user.

You can remove the following code cause MainMessagingService is already extending RNFirebaseMessagingService

<service android:name="io.invertase.firebase.messaging.RNFirebaseMessagingService">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT" />
            </intent-filter>
</service>

@carlosa54 I can confirm that removing it does not break regular FCM push notifications, but still no luck from Intercom. How can I trigger a push notification from Intercom? I'm currently using a [TEST] workspace, could that be the reason?

Damn it, it was because I was using a test workspace 馃が
Perfectly working now, many thanks for your valuable help @carlosa54 馃檹
Ooh I see, I needed to setup an FCM server key on every workspaces, prod and test ones!

Same here i didn't receive notifications.. :\ i'm not using test work space.

@Annihil Looks like you're not receiving push notifications. The in-app message is handled by the SDK and doesn't have to do with push notifications.

  1. Did you enabled push notifications for android and added your FCM server key to Intercom? verify the docs here
  2. Are you sending the FCM token to Intercom?

Send FCM token directly to Intercom for push notifications (Android only)

Firebase.messaging().getToken()
  .then((token) => {
    console.log('Device FCM Token: ', token);
    Intercom.sendTokenToIntercom(token);
});

this is just awesome, i forgot to enable notification from intercom

@Annihil @carlosa54 hey guys, i followed every step.

  1. enabled FCM on TEST workspace.
  2. Overridden the Firebase service.

I am still enable to receive push notifications from Intercom. FCM works fine. Is there a special way to send push notifications from Intercom that I am missing here?

I am recieving the push notification. But my app does not open on the chat screen. Any ideas?

@acollazomayer Are you able to fix the issue? I am facing the same 馃槕

@subinsuresh991 no i was not able to fix it. We ditched intercom

Was this page helpful?
0 / 5 - 0 ratings