Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.

Cannot send to notification centre because there is no 'message' field in: Bundle #1661

Closed
TommyLeong opened this issue Sep 23, 2020 · 10 comments

Comments

@TommyLeong
Copy link

Question

I don't think this is a library bug, but I need help from the community to confirm about reason why I'm not getting notification banner prompt on device.

Is it because the payload return has notification object missing while return, which I assume it's needed by the library to do parsing?

  "notification": {
    "android": {
      "sound": "default"
    },
    "body": "myBody",
    "title": "myTitle"
  },

Payload received with messaging().onMessage method

Below shows the payload returned from my vendor's portal with the comparison of Firebase

Sent via Vendor Portal

{
  "data": {
    "bannerid": "1948826",
    "click": "https: //www.maskedData.com",
    "deeplink": "myapp: //profile",
    "gcm_title": "Android",
    "impr": "www.maskedData.com",
    "message": "AndroidMsg",
    "notificationid": "56789",
  },
  "from": "maskedData",
  "messageId": "0:maskedData",
  "sentTime": 1600846134478,
  "ttl": 172800
}

Sent via Firebase Console

{
  "collapseKey": "com.myapp",
  "data": {
    "bannerid": "1948826",
    "click": "https: //www.maskedData.com",
    "cm_title": "maskedData",
    "deeplink": "myapp: //profile",
    "impr": "www.maskedData.com",
    "message": "AndroidMsg",
    "notificationid": "56789",
  },
  "from": "maskedData",
  "messageId": "0:maskedData",
  "notification": {
    "android": {
      "sound": "default"
    },
    "body": "myBody",
    "title": "myTitle"
  },
  "sentTime": 1600846134478,
  "ttl": 2419200
}

===Logs from Android Studio===

Vendor Portal
Here's the log from Android Studio, it mentioned about D/RNPushNotification: Cannot send to notification centre because there is no 'message' field in: Bundle[

2020-09-23 15:28:53.083 27753-28884/com.myapp V/RNPushNotification: 

onMessageReceived: Bundle[
{
  data=Bundle[
    {
      bannerid=1948826,
      impr=https: //www.maskedData.com,
      gcm_title=Android,
      click=https: //www.maskedData.com,
      deeplink=myapp: //profile,
      notificationid=56789,
      message=AndroidMsg
    }
  ]
}
]




2020-09-23 15:28:53.085 27753-27753/com.myapp V/RNPushNotification: 
sendNotification: Bundle[
{
  userInteraction=false,
  id=-943966453,
  data=Bundle[
    {
      bannerid=1948826,
      impr=https: //www.maskedData.com,
      gcm_title=Android,
      click=https: //www.maskedData.com,
      deeplink=myapp: //profile,
      notificationid=56789,
      message=AndroidMsg
    }
  ],
  foreground=true
}
]




2020-09-23 15:28:53.086 27753-27753/com.myapp D/RNPushNotification: Cannot send to notification centre because there is no 'message' field in: Bundle[
{
  userInteraction=false,
  id=-943966453,
  data=Bundle[
    {
      bannerid=1948826,
      impr=https: //www.maskedData.com,
      gcm_title=Android,
      click=https: //www.maskedData.com,
      deeplink=myapp: //profile,
      notificationid=56789,
      message=AndroidMsg
    }
  ],
  foreground=true
}
]

Firebase Console

I believe onMessageReceived has somewhat parsed the information in needed format, hence the following is formed. Also, when we compare the following payload with the one above (from Vendor Portal). That's exactly what RNPushNotification is complaining about.

2020-09-23 15:18:48.463 27753-28244/com.myapp V/RNPushNotification: 

onMessageReceived: Bundle[
{
  data=Bundle[
    {
      bannerid=1948826,
      impr: www.maskedData.com,
      click: https: //www.maskedData.com,
      deeplink: myapp: //profile,
      notificationid: 56789,
      message: AndroidMsg,
      cm_title=maskedData,
    }
  ],
  color=null,
  sound=default,
  title=myTitle,
  message=myBody
}
]

Questions

  1. Is my findings correct?
  2. Can I append the missing message field myself to RNPushNotification?
@TommyLeong
Copy link
Author

@Dallas62 I'm tagging you directly, believe you will be the best person to help me with this easily. Much appreciated!

@Dallas62
Copy link
Collaborator

Hi @TommyLeong
Thanks for the detailed issue, you will find some detail in others issues such as: #1452 (comment)

The linked issue does fit exactly with your case, but this message doesn't make sense now. I recommend you to implement the logic directly in the application.

You can take the data from your notification (notification.data ?) then pass it to PushNotifications.localNotification(notification.data); (take care of parameters).
In order to avoid loops, you must check if data come from a user interaction or send by the server.

@TommyLeong
Copy link
Author

@Dallas62 That's true, I actually tried to pushed it to local notifications but sometimes im getting twice the same notification (1 frm remote, 1 is the local notifications i pushed)This is probably what you're mentioning here with "avoid loops".

However I'm not aware of a way to identify whether the notification is send by server?

But yes, via the "userInteraction" key i will know whether if the app is opened by user.

@Dallas62
Copy link
Collaborator

With RNFirebase/messaging, I don't know how the userInteraction is defined.

@TommyLeong
Copy link
Author

It basically returns a boolean value of true/false. Anything in specific I should look for to identify?

@TommyLeong
Copy link
Author

@Dallas62 with your comment earlier, I've managed to get my notification showed up with PushNotification.localNotification({..}) within the code of

PushNotification.configure({

onNotification: (notification) => {
...
}

})

However I realized when app is in killed state, notification does not get passed into this method. But if I view at the logcat from Android Studio, it does received with following..

2020-09-2514: 46: 08.19013162-13335/com.myapp/RNPushNotification: onMessageReceived: Bundle[
  {
    data=Bundle[
      {
      ....all my values....
      }
    ]
  }
]



2020-09-2514: 46: 12.45913162-13162/com.myapp/RNPushNotification: sendNotification: Bundle[
  {
    userInteraction=false,
    id=1552146366,
    data=Bundle[
      {
      ....all my values....
      }
    ],
    foreground=false
  }
]


2020-09-2514: 46: 12.48013162-13162/com.myapp/RNPushNotification: Cannot send to notification centre because there is no 'message' field in: Bundle[
  {
    userInteraction=false,
    id=1552146366,
    data=Bundle[
      {
      ....all my values....
      }
    ],
    foreground=false
  }
]

@Dallas62
Copy link
Collaborator

If the notification isn't working/showing, it's probably because there is no channel define. Can you check this ?

@TommyLeong
Copy link
Author

Not really, rmb we had a small discussion on creating custom channel? (:

I'm unsure if this has something to do with my payload return, as it does not contain the "priority:high". However, the same payload works for background state (because I trigger PushNotification.localNotification within onNotification.

@Off2Race

This comment has been minimized.

@Dallas62
Copy link
Collaborator

Hi,
I do not recommend the previous method, please prefer:

onNotification: function(notification) {
  if(!notification.userInteraction) {
    PushNotifications.localNotification(notification.data);
  }
}

If really needed.
Regards,

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants