tinycreative / react-native-intercom

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

Unable to show push notifications on android with the latest sdk #397

Closed scesbron closed 2 years ago

scesbron commented 3 years ago

I have an application which integrates react-native-intercom and push notifications with FCM and that works well on production with react-native-intercom 16.0.0 and react-native-firebase 5.5.6.

My app is using react-native 0.59.10 and I am trying to migrate it to react-native 0.62.2.

For this I need to updage react-native-firebase to the new version and I want to upgrade react-native-intercom to the latest version (17.0.0) to use the intercom sdk 7+.

I cannot find in the react-native-intercom documentation a clear statement on which version to use for the @react-native-firebase/messaging dependency and for the underlying FCM sdk.

I tried with version 6.7.1 of @react-native-firebase/* dependencies and with the latest version (8.x for core and 7.x for other libs).

With both configurations I cannot receive the intercom push notifications. What I have tested on my phone

So the problem seems to be one of

What I managed to do is to use https://github.com/zo0r/react-native-push-notification to show the notifications I received from FCM as local notifications but with this solution the notification is not seen as sent nor as opened in the intercom dashboard.

I found that there is a modification between the v5 and the v6+ of the react native firebase messaging dependency. With the old version the notifications were shown when the app is in the foreground but it is not the case with the new versions.

In the intercom documentation it is said that we have to override FirebaseMessagingService which I did for the old version because it seems to be required for the react-native integration. But with the new versions of @react-native-firebase/messaging this is not possible.

I am also using OneSignal for my app push notifications.

scesbron commented 3 years ago

Another point I found in the rnfirebase.io doc (https://rnfirebase.io/messaging/usage#notifications) is that there is no notification shown by default if the message only conains a data attribute and no notification attribute. This is the case for the intercom message : is this done on purpose so the intercom sdk can handle internally the notification ?

himanshu-tiwari commented 3 years ago

same issue @scesbron did you find a solution to this?

scesbron commented 3 years ago

Currently I managed on android to capture the events received on my phone with two pieces of code.

In my app.js file

messaging().setBackgroundMessageHandler(async (message) => {
  // do something
});

and in my top level component

      messaging().onMessage((message) => {
        // do something
      });

My first piece of code capture intercom notifications received while the app is in background and the second one while the app is in foreground.

What I plan to do (after some ios tests) if there is no other solution is to use a library like https://github.com/zo0r/react-native-push-notification to locally show the notification by myself.

The main drawback I see here is that I think that intercom can't detect that the notification is opened in this case so this will not be shown in the intercom dashboard.

himanshu-tiwari commented 3 years ago

Yeah, I had also added the first two bits of code. So, we are able to detect that we have received a notification from Intercom.

Will try out react-native-push-notification and similar libraries for local notifications. Thanks for the suggestion 👍 We can probably still navigate the user to the Intercom dashboard if such a notification is clicked. Will have to handle that manually.

scesbron commented 2 years ago

@browniefed you closed this issue but without any comment: is it because the problem I described does not occur anymore or is it because it is the normal behavior and with the latest versions of Intercom I have to add some code to my app to correctly handle the notifications?

browniefed commented 2 years ago

This library is no longer maintained. Please use the official package https://github.com/intercom/intercom-react-native