Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Messaging payload contains an invalid "android" property. Valid properties are "data" and "notification"

I'm trying to send Push Notifications with Firebase Cloud Functions with platform specific configuration. I got following config from https://firebase.google.com/docs/cloud-messaging/send-message

var message = {
  notification: {
    title: '$GOOG up 1.43% on the day',
    body: '$GOOG gained 11.80 points to close at 835.67, up 1.43% on the day.',
  },
  data: {
    channel_id: threadId,
  },
  android: {
    ttl: 3600 * 1000,
    notification: {
      icon: 'stock_ticker_update',
      color: '#f45342',
    },
  },
  apns: {
    payload: {
      aps: {
        badge: 42,
      },
    },
  },
};

but got error for admin.messaging().sendToDevice(deviceToken, message)

Messaging payload contains an invalid "android" property. Valid properties are "data" and "notification"

Any idea what is wrong here? Or maybe some samples of proper configuration for iOS/Android platforms?

like image 888
Dima Portenko Avatar asked Apr 05 '19 16:04

Dima Portenko


People also ask

What is Registration_ids in FCM?

"registration_ids" is an array of the registration tokens acquired by calling FirebaseInstanceId. getInstance(). getToken() on a device. If you put multiple registration tokens in the array, the same push notification will be sent to each.

What is Multicast_id?

It's just an identifier. multicast_id Unique ID (number) identifying the multicast message.


1 Answers

sendToDevice() is a function that uses the legacy FCM HTTP endpoint. The legacy endpoint doesn't offer platform-specific fields. In order to get that functionality, you can use the new endpoint through the send() function. You may need to update your version of the Admin SDK. You can see an example in the documentation here.

For the code you provided, for example, you would send a message like this:

let message = {
  notification: {
    title: '$GOOG up 1.43% on the day',
    body: '$GOOG gained 11.80 points to close at 835.67, up 1.43% on the day.',
  },
  data: {
    channel_id: threadId,
  },
  android: {
    ttl: 3600 * 1000,
    notification: {
      icon: 'stock_ticker_update',
      color: '#f45342',
    },
  },
  apns: {
    payload: {
      aps: {
        badge: 42,
      },
    },
  },
  token: deviceToken,
};

admin.messaging().send(message)
  .then((response) => {
    // Response is a message ID string.
    console.log('Successfully sent message:', response);
  })
  .catch((error) => {
    console.log('Error sending message:', error);
  });

Notice the device token is now in the message object.

like image 170
Jen Person Avatar answered Sep 21 '22 13:09

Jen Person