fcm
fcm copied to clipboard
Can't send data only notifications because Notification object is required
The Notification object should be optional when creating a Message object. Currently, it is not possible to send data only notifications.
See https://firebase.google.com/docs/cloud-messaging/concept-options#data_messages
Hello @bennnjamin, thanks for reporting this issue. It should be fix in 3.2. Be aware that this version introduce a BC break, see CHANGELOG for more details.
I've been experimenting on a fork and there are some other issues too, specifically with array $data = [] being serialized to an empty JSON Object. The FCM API doesn't seem to like it. I'm wondering if you should consider making most constructor properties optional. The documentation isn't clear about what is strictly optional but trial and error seems to indicate most JSON keys are optional. I could open an issue but I think it's ultimately your call on how to handle optional/required keys.
Otherwise this is a great concise library.
I'm not against making all parameters optional if there is a specific use case for sending an empty payload (no data and/or notification).
It's either/or. When you send a data only message, there is no notification key, or title/body anywhere in the JSON object. Only custom keys (see https://firebase.google.com/docs/cloud-messaging/concept-options#notifications_and_data_messages). I'm not sure the best way to handle that honestly. If every parameter optional, then it's on the developer to know how to build an alert or data only notification. Maybe some balance that satisfies the FCM V1 API and is also not overburdensome for the developer?
We are running into this issue too, which caught us off-guard when running an initial "simple" test without specifying any data element.
@Mike-Benoit I've forked this repo and fixed the issues on my end, happy to share the changes if you aren't able to get it working.
@Mike-Benoit I've forked this repo and fixed the issues on my end, happy to share the changes if you aren't able to get it working.
I've worked around them too, just wanted to share my experiences here mostly.