fix: sanitize fcm data payload keys for android
- avoid reserved FCM key names like message_type - send push metadata in camelCase keys already supported by Android
This commit is contained in:
@@ -81,10 +81,26 @@ def _send_fcm_to_user(user_id: int, title: str, body: str, data: dict[str, Any])
|
||||
return
|
||||
|
||||
string_data = {
|
||||
**{str(key): str(value) for key, value in data.items()},
|
||||
"title": title,
|
||||
"body": body,
|
||||
}
|
||||
for key, value in data.items():
|
||||
normalized_key = str(key)
|
||||
if normalized_key == "chat_id":
|
||||
normalized_key = "chatId"
|
||||
elif normalized_key == "message_id":
|
||||
normalized_key = "messageId"
|
||||
elif normalized_key == "sender_id":
|
||||
normalized_key = "senderId"
|
||||
elif normalized_key == "message_type":
|
||||
normalized_key = "messageType"
|
||||
elif normalized_key == "preview_image_url":
|
||||
normalized_key = "previewImageUrl"
|
||||
elif normalized_key == "sender_name":
|
||||
normalized_key = "senderName"
|
||||
elif normalized_key == "text_preview":
|
||||
normalized_key = "textPreview"
|
||||
string_data[normalized_key] = str(value)
|
||||
for platform, token in tokens:
|
||||
webpush = None
|
||||
notification = None
|
||||
|
||||
Reference in New Issue
Block a user