I've been trying to send push notification via Cloud Functions. This is the guide on how to do it from Firebase: https://github.com/firebase/functions-samples/blob/master/fcm-notifications/functions/index.js
This is the payload I have
const payload = {
"notification": {
title: 'Title!',
body: 'Body!',
sound: 'default'
},
"data":{"score":"3x1"},
"content_available": true,
};
Now, this throwing an error, and when I check the log, here's the error:
Error: Messaging payload contains an invalid "content_available" property. Valid properties are "data" and "notification".
at FirebaseMessagingError.Error (native)
at FirebaseMessagingError.FirebaseError [as constructor] (/user_code/node_modules/firebase-admin/lib/utils/error.js:25:28)
at new FirebaseMessagingError (/user_code/node_modules/firebase-admin/lib/utils/error.js:130:23)
at /user_code/node_modules/firebase-admin/lib/messaging/messaging.js:465:23
at Array.forEach (native)
at Messaging.validateMessagingPayload (/user_code/node_modules/firebase-admin/lib/messaging/messaging.js:462:21)
at /user_code/node_modules/firebase-admin/lib/messaging/messaging.js:204:37
at process._tickDomainCallback (internal/process/next_tick.js:129:7)
If I removing the content_available: true, it works fine, so I know the code works.
I also tried to send this manually with CURL/POST request WITH content_available: true, and it also works.
Thanks!
contentAvailable is passed in the options parameter of sendToDevice(regToken, payload, options). Example code is in this documentation. The documentation for MessagingOptions is here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With