-
Notifications
You must be signed in to change notification settings - Fork 161
Add FCM HTTP V1 service #171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Hi, |
@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 |
I have overwritten |
Any plans to merge this ? |
is this PR will be merged soon ? |
Hi thanks for your contribution here. I will have a look at this next weeks and will prepare a release for that. |
how much time it will take to fix? |
@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 |
Class |
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. |
All these keys al valid according to documentation: https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages?hl=es#AndroidNotification |
@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 |
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 I'll post the changes when I have a chance. |
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any chance we can add a test using mocks for basic coverage?
'priority' => 'normal', | ||
'dry_run' => false, | ||
'projectId' => 'my-project-id', | ||
'jsonFile' => __DIR__ . '/fcmCertificates/file.json', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use storage_path()
instead of __DIR__
to follow Laravel standards.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe apn config needs that change too...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does, yes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's up to you to modify it in the main branch for both drivers.
src/FcmV1.php
Outdated
|
||
protected function getOauthToken() | ||
{ | ||
return Cache::remember( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets add Cache::driver(config(...))
so people can configure a cache driver of their choice (depending on their setups). Variable for cache duration should be named more specific about what's actually be cached. Also duration should be moved into the config
so people can adjust.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you mean Cache::store(config(...))
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed 01da9cc
src/FcmV1.php
Outdated
{ | ||
$this->config = $this->initializeConfig('fcmv1'); | ||
|
||
$this->url = 'https://fcm.googleapis.com/v1/projects/' . $this->config['projectId'] . '/messages:send'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Base URL should be changed to constant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed 0e9d756
@@ -25,8 +25,8 @@ | |||
"require": { | |||
"php": "^7.1.3 || ^8.0", | |||
"guzzlehttp/guzzle": "^6.3 || ^7.0.1", | |||
"illuminate/support": "~5.8 || ^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0 || ^11.0", | |||
"illuminate/notifications": "~5.8 || ^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0 || ^11.0", | |||
"illuminate/support": "~5.8 || ^6.0 || ^7.0 || ^8.0 || ^9.0|^10.0|^11.0|^12.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Single pipe are deprecated. Only for backwards compatibility
In my opinion, the entire test suite needs a major rewrite. I believe such changes are beyond the scope of this PR. |
It definitely needs that. But yes, would be out of scope. But would be good to have at least basic coverage on that one here. |
Add service to use FCM HTTP v1 API.
According to Google (https://firebase.google.com/docs/cloud-messaging/migrate-v1)