3

I am using cloud functions (node.js) to send notifications to devices. I have my payload set up like this:

const payload = {
    notification: {
        title: payloadSender,
        body: payloadMessage,
    },
    data: {
        chatId: chatId,
    },
    android: {
        priority: 'normal',
        collapse_key: chatId,
        //todo how to set badge?
        notification: {
          sound: 'messageSent.wav',  
        },
    },
    apns: {
        headers: {
            'apns-priority': '5',
            'apns-collapse-id': chatId,
        },
        payload: {
            aps: {
                badge: newUnreads,
                sound: 'messageSent.wav',
                'content-available': 1,
            }
        }

    }
};

According to the Firebase docs, you can use the "android" and "apns" fields for device specific behavior. Below is the JSON representation found here for a Message sent by FCM:

{
 "name": string,
 "data": {
   string: string,
   ...
},
"notification": {
  object(Notification)
},
"android": {
  object(AndroidConfig)
},
"webpush": {
  object(WebpushConfig)
},
"apns": {
  object(ApnsConfig)
},

// Union field target can be only one of the following:
"token": string,
"topic": string,
"condition": string
// End of list of possible types for union field target.
}

Why am I getting the error Messaging payload contains an invalid "android" property. Valid properties are "data" and "notification". And Messaging payload contains an invalid "apns" property. Valid properties are "data" and "notification".?

mnearents
  • 646
  • 1
  • 6
  • 31

1 Answers1

1

I can't tell which version you're using based on your post, but it's good to note that the Platform Overrides feature is only available for v1 and not Legacy.

Also, I'm not sure if you just removed some items from your sample payload, but there are a lot of unnecessary commas (,) in there that's breaking the JSON. Try using an online JSON formatter to double check your payload. I tried one on yours and ended up with this after removing all the errors:

{
    "notification": {
        "title": "payloadSender",
        "body": "payloadMessage"
    },
    "data": {
        "chatId": "chatId"
    },
    "android": {
        "priority": "normal",
        "collapse_key": "chatId",
        //todo how to set badge? IIRC, Badges can be enabled via method inside the Android Notification builder
        "notification": {
          "sound": "messageSent.wav"
        }
    },
    "apns": {
        "headers": {
            "apns-priority": "5",
            "apns-collapse-id": "chatId"
        },
        "payload": {
            "aps": {
                "badge": "newUnreads",
                "sound": "messageSent.wav",
                "content-available": 1 // Double check this one if you are to actually use content-available or content_available for FCM
            }
        }

    }
}

Just switch out again the variables as needed.

AL.
  • 36,815
  • 10
  • 142
  • 281