Skip to content
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

for mobile app push notifications set FCM android priority to high #1612

Merged
merged 3 commits into from
Mar 23, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- When the `DANGEROUS_WEBHOOKS_ENABLED` environment variable is set to true, it's possible now to create Outgoing Webhooks
using URLs without a top-level domain ([1266](https://github.com/grafana/oncall/pull/1266))
- Updated wording when creating an integration ([1572](https://github.com/grafana/oncall/pull/1572))
- Set FCM Android priority to "high" for mobile app push notifications ([1612](https://github.com/grafana/oncall/pull/1612))

## v1.2.1 (2023-03-23)

Expand Down
25 changes: 24 additions & 1 deletion engine/apps/mobile_app/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from django.conf import settings
from fcm_django.models import FCMDevice
from firebase_admin.exceptions import FirebaseError
from firebase_admin.messaging import APNSConfig, APNSPayload, Aps, ApsAlert, CriticalSound, Message
from firebase_admin.messaging import AndroidConfig, APNSConfig, APNSPayload, Aps, ApsAlert, CriticalSound, Message
from requests import HTTPError
from rest_framework import status

Expand Down Expand Up @@ -185,6 +185,21 @@ def _get_fcm_message(alert_group, user, registration_id, critical):
mobile_app_user_settings.important_notification_override_dnd
),
},
android=AndroidConfig(
# from the docs
# https://firebase.google.com/docs/cloud-messaging/concept-options#setting-the-priority-of-a-message
#
# Normal priority.
# Normal priority messages are delivered immediately when the app is in the foreground.
# For backgrounded apps, delivery may be delayed. For less time-sensitive messages, such as notifications
# of new email, keeping your UI in sync, or syncing app data in the background, choose normal delivery
# priority.
#
# High priority.
# FCM attempts to deliver high priority messages immediately even if the device is in Doze mode.
# High priority messages are for time-sensitive, user visible content.
priority="high",
),
apns=APNSConfig(
payload=APNSPayload(
aps=Aps(
Expand All @@ -201,6 +216,14 @@ def _get_fcm_message(alert_group, user, registration_id, critical):
"interruption-level": "critical" if critical else "time-sensitive",
},
),
headers={
# From the docs
# https://firebase.google.com/docs/cloud-messaging/concept-options#setting-the-priority-of-a-message
#
# When sending data messages to Apple devices, the priority must be set to 5, or normal priority.
# Messages sent with high priority are rejected by the FCM backend with the error INVALID_ARGUMENT.
"apns-priority": "5",
joeyorlando marked this conversation as resolved.
Show resolved Hide resolved
},
),
),
)