Back

Notifications sent with FCM has missing fields in the payload

  • 0
  • Messaging
Heien
22 Jun, 2024, 13:03

Hi! I am trying to send push notifications from Appwrite console on a self-hosted environment to native applications using FCM. While the service works fine, and the application will receive notifications both in foreground and background, notifications received while the app is in foreground contain no message or title. I've been troubleshooting this for a bit, and found that the payload sent to FCM services is missing a data field in the object. While taking a brief look through the UTOPIA PHP adapter used for messaging in Appwrite, specifically in the FCM class, I noticed this is indeed the case. The class is found here: https://github.com/utopia-php/messaging/blob/main/src/Utopia/Messaging/Adapter/Push/FCM.php

Take a look at the bare example of the expected payload below, to see which fields are mapped to which Application state.

TypeScript
{
  "message": {
    "token": "some-token",
    "notification": {
        "title": "Works in background",
        "body": "This message is successfully received while app is in background."
      },
    "android": {
      "priority": "high",
      "data": {
        "title": "This title is visible while the app is in foreground.",
        "message": "This message will be seen in the push notification while the app is in foreground."
      }
    },
    "data": {
      "href": "chat"
    }
  }
}
TL;DR
Developers experiencing missing fields in FCM notifications payload. The problem arises from the lack of a "data" field in the object, resulting in no message or title displaying when the app is in foreground. Upon inspection of the UTOPIA PHP adapter, specifically the FCM class, the issue was confirmed. Check the provided link for the code reference. A sample payload is shared for reference containing the necessary fields. **Solution:** Add the missing "data" field to the payload to ensure messages display correctly in foreground notifications.
D5
22 Jun, 2024, 13:41

Hello! Thanks a lot! Can you create an issue on GitHub so the team takes a look into it?

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more