PushNotification icon indicating copy to clipboard operation
PushNotification copied to clipboard

Add FCM HTTP V1 service

Open dragermrb opened this issue 11 months ago • 15 comments

Add service to use FCM HTTP v1 API.

According to Google (https://firebase.google.com/docs/cloud-messaging/migrate-v1)

Apps using the deprecated FCM legacy APIs for HTTP and XMPP should migrate to the HTTP v1 API at the earliest opportunity. Sending messages (including upstream messages) with those APIs was deprecated on June 20, 2023, and will be removed in June 2024.

dragermrb avatar Feb 29 '24 13:02 dragermrb

Hi, It looks like new message format is not yet implemented. Is it planned?

shaffe-fr avatar Jun 12 '24 12:06 shaffe-fr

@dragermrb Thanks for the solution. We are using your fork. Just wanted to leave a comment here. I know that main project does not allow to use multiple fcm api keys with config structure, but that can be dealt with by using ->setApiKey() . Here I had a bit of a headache. When initializing FcmV1 with default configs or setting projectId the url property was updated. I was using ->setConfig() to set everything at once, that property was not updated. So just a feedback. You could add a check to update url property after setting the whole config. Was trying to find ->setUrl(), but class didn't have that, but PushService::class had that so I had to contruct the full url the same way as in your class. So another feedback. You could override ->setUrl() with project-id injection or something like that where users pass can project-id and code itself could use when reading from config or calling ->setProjectId().

matiss-zalans avatar Jun 20 '24 12:06 matiss-zalans

Hi @matiss-zalans

I have overwritten setConfig() method to updates the URL

dragermrb avatar Jun 20 '24 13:06 dragermrb

Any plans to merge this ?

pushpak1300 avatar Jul 15 '24 07:07 pushpak1300

is this PR will be merged soon ?

hossamadelelsayed avatar Jul 16 '24 08:07 hossamadelelsayed

Hi thanks for your contribution here. I will have a look at this next weeks and will prepare a release for that.

pultho avatar Aug 13 '24 21:08 pultho

how much time it will take to fix?

AbdulRahmanIqbal avatar Sep 10 '24 19:09 AbdulRahmanIqbal

@dragermrb I think you need to update your FCMV1Channel class to include the buildData method, your code currently doesn't work when using the FCM Channel in Laravel Notifications. The google API returns errors for the request keys that are no longer valid (sound, color, etc)

this is my custom channel class that works for me

image

adrianpaiva1 avatar Sep 16 '24 22:09 adrianpaiva1

Hi @adrianpaiva1

Class Edujugon\PushNotification\Channels\FcmV1Channel inherits from Edujugon\PushNotification\Channels\GcmChannel, and it already implements buildData()

dragermrb avatar Sep 17 '24 06:09 dragermrb

hi @dragermrb yes but because the buildData method there is including the 'sound' and 'color' fields in the request the Google API is returning an error as they aren't supported anymore I believe.

I'll post the error response from the API later today.

image

adrianpaiva1 avatar Sep 17 '24 16:09 adrianpaiva1

image

adrianpaiva1 avatar Sep 17 '24 16:09 adrianpaiva1

Hi @adrianpaiva1

All these keys al valid according to documentation: https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages?hl=es#AndroidNotification

dragermrb avatar Sep 17 '24 16:09 dragermrb

@dragermrb it looks like those keys are only valid in the 'android' key of the request though, currently it's including them in the base notification object so it's giving that error

https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages?hl=en#Notification

adrianpaiva1 avatar Sep 17 '24 19:09 adrianpaiva1

Hi @adrianpaiva1

The problem only occurs when using Laravel notifications. Since I don't use them I couldn't reproduce the problem.

I need to do some work to correctly generate the payload from an instance of Edujugon\PushNotification\Messages\PushMessage

I'll post the changes when I have a chance.

dragermrb avatar Sep 18 '24 09:09 dragermrb

Thanks @dragermrb one other thing I noticed was the status codes here. I think this should only be a 404 status code.

I was using the unregistedDeviceTokens to remove any invalid tokens for my users and including the 400 status code here means that if I send any invalid request parameters my tokens will be deactivated even if they are valid. From the docs it looks like 404 is correct to me for detecting deactivated device tokens.

image

adrianpaiva1 avatar Sep 19 '24 13:09 adrianpaiva1