-
Notifications
You must be signed in to change notification settings - Fork 0
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
JS-7167 Add fcm api support #13
Conversation
lib/rpush/daemon/fcm/delivery.rb
Outdated
PROJECT_ID = Settings.firebase.fcm_push_notification.project_id | ||
ENDPOINT = "https://fcm.googleapis.com/v1/projects/#{PROJECT_ID}/messages:send".freeze |
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.
[Question/Blocker]: Is there a reason why this is being set here? I think either of these should be configurable from outside of this project
The library shouldn't be dependent on Settings
.
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 looks like this should be stored in the rpush_apps
table. It uses STI, so we'd need to add a new column for it to do it properly.
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.
add new columns to rpush apps: https://github.com/Codefied/housecall-web/pull/51155
validates_with Rpush::Client::ActiveModel::PayloadDataSizeValidator, limit: 4096 | ||
validates_with Rpush::Client::ActiveModel::RegistrationIdsCountValidator, limit: 1000 |
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.
[NOTE]: These are the same validations as current GCM, so we're good. I think this is good.
I think as it stands, the PR mostly works. I'd like to see if we can find away around not passing accessing I also don't know how |
@v7chan Could you take a look too? |
# TODO: Add whatever validation is needed here | ||
# validates :auth_key, presence: true |
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.
We should fill this in to make it clear which columns we need for Fcm (presumably with the new column for project_id)
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.
also need other columns also to make OAuth logic for fetching an access token self-contained in the Rpush: https://github.com/Codefied/housecall-web/pull/51155/files#diff-ad01b5deb18c1010b83f08165e8b3bdedd5e72e17a62a2c644506a8617f1b2ffR9
looks ok?
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.
added validates :fcm_json_token, presence: true
fcm_access_token and fcm_access_token_expiration will be filled in with the first call, so i guess i cannot add the validation here
validates :priority, inclusion: { in: FCM_PRIORITIES }, allow_nil: true | ||
|
||
validates_with Rpush::Client::ActiveModel::PayloadDataSizeValidator, limit: 4096 | ||
validates_with Rpush::Client::ActiveModel::RegistrationIdsCountValidator, limit: 1000 |
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.
Shouldn't registration_ids
not be set for FCM notifications? GCM allowed for multiple as array, but it looks like we want to use the device_token
(singular) field here
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.
fcm does not use registration_ids
, i can remove this validation
def priority_for_notification | ||
case priority | ||
when 0 then 'PRIORITY_UNSPECIFIED' | ||
when 1 then 'PRIORITY_MIN' | ||
when 2 then 'PRIORITY_LOW' | ||
when 5 then 'PRIORITY_DEFAULT' | ||
when 6 then 'PRIORITY_HIGH' | ||
when 10 then 'PRIORITY_MAX' | ||
else | ||
'PRIORITY_DEFAULT' | ||
end |
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.
I'm not sure if I'm following this correctly. priority=
only allows the values of 10 and 5, do we need to handle these other values?
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.
we can remove this since we remove the duplicate override
json = { | ||
'notification' => android_notification, | ||
} | ||
json['data'] = data if data |
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.
Does this need to be duplicated here? I think this is only for Android-specific override if necessary and since we are not using FCM to deliver to both platforms, not having to duplicate this key makes the payload smaller
I see similar duplicated values like notification_priority
within the Android overrides. In general, I think the first phase of FCM we are adding is only to deliver to Android, Apns8 will continue to be used for iOS. So we can avoid duplicating platform-overrides for now.
How we use rpush will need to change if we are to deliver to both iOS and Android via FCM and that's not the intention right now anyway.
# Android does not appear to handle content_available anymore. Instead "priority" should be used | ||
# with "low" being a background only message. APN however should support this field. | ||
# json['content_available'] = content_available if content_available |
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.
I think we should either map this or disallow this field from being set, this comment won't be visible to users of rpush
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.
looks like we are not currently using 'content_available' for sending push to android, if the anyone add this to the fcm notification, the NotificationKeysInAllowedListValidator will catch it.
when 400 | ||
bad_request(response) | ||
when 401 | ||
unauthorized |
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.
As we roll this out, it's worth catching up with the 400/401s we've been facing from Firebase in our web push. As far as I remember, there was a bit of intermittent nature to them and I don't know if Voice ever got to the bottom of it
https://housecall.atlassian.net/browse/VOICE-6463
At the very least we'll need to monitor closely to know if we're failing to deliver more than normal on FCM v1 compared to legacy.
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 worth catching up with the 400/401s
What do you mean by "catch up with"? As in have visibility into why they happen? We'll ensure we have some monitoring before we roll out.
Since failures get logged to sumologic we can add some reporting there. If needed, we can also add some metrics to datadog with the Reflections API, but I figured the sumologic logs should be good enough.
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.
As in have visibility into why they happen?
Yeah, just chat with Voice and/or read the investigations they've left behind. There was some number of mysterious errors that I don't know if they ever got to the bottom of, just don't want us to assume all requests will magically work
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.
might be this? for 401: https://firebase.google.com/docs/reference/fcm/rest/v1/ErrorCode
THIRD_PARTY_AUTH_ERROR (HTTP error code = 401) APNs certificate or web push auth key was invalid or missing. | A message targeted to an iOS device or a web push registration could not be sent. Check the validity of your development and production credentials
when 400 | ||
bad_request(response) | ||
when 401 | ||
unauthorized |
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 worth catching up with the 400/401s
What do you mean by "catch up with"? As in have visibility into why they happen? We'll ensure we have some monitoring before we roll out.
Since failures get logged to sumologic we can add some reporting there. If needed, we can also add some metrics to datadog with the Reflections API, but I figured the sumologic logs should be good enough.
This PR: in progress