I have a react native app. I am using react-native push-notification npm module for pushnotifications (mainly local notifications), this is working fine.
I use OneSignal service for remote notifications which works fine as well.
However, now I am trying to use react-native-freshchat-sdk
(third party tool) to provide chat functionality within the app.
I have the following code
PushNotification.configure({
// (optional) Called when Token is generated (iOS and Android)
onRegister: function (token: any) {
console.log('TOKEN:', token)
dispatch(tokenGenerated(token));
},
//(required) Called when a remote or local notification is opened or received
onNotification: function (notification: any) {
console.log(`**********notification received ********************* : ${JSON.stringify(notification)}`)
Freshchat.isFreshchatNotification(notification.data, (freshchatNotification: any) => {
if (freshchatNotification) {
console.log(`**********freshchatNotification received *********************`)
Freshchat.handlePushNotification(notification.data);
} else {
console.log(`**********some other notification*********************`)
}
})
},
Things work fine when the app is in the foreground or background. I do get remote notifications from FreshChat
with the chat content. FreshChat uses FCM for sending notifications. However, when the app is closed or killed, I do not get the notifications (atleast they are not shown in the tray) When I open the chat, I can see the chat message there. Chat remote notification looks like the following
{
"foreground": false,
"userInteraction": false,
"id": "-1665678567",
"data": {
"channel_id": "748134",
"app_id": "5787643203",
"notif_type": "1",
"msg_alias": "8343f922-9dfa-4fe9-9220b-61af8902e7650",
"source": "freshchat_user",
"body": "heelo world message",
"timestamp": "1660956855495",
"user_name": "Foo Bar",
"target_user_alias": "ssd1232-75df-87f0-fsdsd",
"conv_id": "6479825358242"
}
}
I have been scratching my head to understand why I am not getting remote notifications when the app is closed. What's confusing me even more is that I get OneSignal
remote notifications even when the app is closed. I would like to see similar behaviour with the remote notification sent by FreshChat
Any help pointers would be really handy. I have been stuck with these for days now and have no clue what's going wrong. Thanks in advance