fix: send android pushes as data-only fcm messages
- include title and body in FCM data payload for Android - use high priority Android config so the app builds notifications itself
This commit is contained in:
@@ -80,18 +80,30 @@ def _send_fcm_to_user(user_id: int, title: str, body: str, data: dict[str, Any])
|
||||
if not tokens:
|
||||
return
|
||||
|
||||
string_data = {str(key): str(value) for key, value in data.items()}
|
||||
string_data = {
|
||||
**{str(key): str(value) for key, value in data.items()},
|
||||
"title": title,
|
||||
"body": body,
|
||||
}
|
||||
for platform, token in tokens:
|
||||
webpush = None
|
||||
notification = None
|
||||
android = None
|
||||
if platform == "web":
|
||||
webpush = messaging.WebpushConfig(
|
||||
fcm_options=messaging.WebpushFCMOptions(link=settings.firebase_webpush_link)
|
||||
)
|
||||
notification = messaging.Notification(title=title, body=body)
|
||||
elif platform == "android":
|
||||
android = messaging.AndroidConfig(priority="high")
|
||||
else:
|
||||
notification = messaging.Notification(title=title, body=body)
|
||||
message = messaging.Message(
|
||||
token=token,
|
||||
notification=messaging.Notification(title=title, body=body),
|
||||
notification=notification,
|
||||
data=string_data,
|
||||
webpush=webpush,
|
||||
android=android,
|
||||
)
|
||||
try:
|
||||
messaging.send(message, app=app)
|
||||
|
||||
Reference in New Issue
Block a user