Fix the concatenation issue with message
This commit is contained in:
parent
2043baf4ab
commit
b12f8cc965
@ -86,26 +86,44 @@ class NotificationManager:
|
||||
properties: dict,
|
||||
region: Optional[UserRegion] = None,
|
||||
) -> str:
|
||||
# leverage the information in properties to enrich the message.
|
||||
message_subject = None
|
||||
message = None
|
||||
if subject.lower() == "payment":
|
||||
pass
|
||||
|
||||
# Default region to be international if not set
|
||||
# Default region to international if not set
|
||||
if region is None:
|
||||
region = UserRegion.OTHER
|
||||
|
||||
message_subject = SystemNotifications[region][subject.lower()][event.lower()][
|
||||
"message_subject"
|
||||
]
|
||||
message = SystemNotifications[region][subject.lower()][event.lower()]["message"]
|
||||
subject_lower = subject.lower()
|
||||
event_lower = event.lower()
|
||||
|
||||
if event.lower() == "authentication":
|
||||
message = message.format(properties["auth_code"])
|
||||
if not message:
|
||||
raise RuntimeError("unsupported event:{}".format(event))
|
||||
return message, message_subject
|
||||
try:
|
||||
# Get message template and subject from SystemNotifications
|
||||
notification_config = SystemNotifications[region][subject_lower][event_lower]
|
||||
message = notification_config["message"]
|
||||
message_subject = notification_config["message_subject"]
|
||||
|
||||
# Handle authentication specific formatting
|
||||
if event_lower == "authentication" and "auth_code" in properties:
|
||||
message = message.format(properties["auth_code"])
|
||||
|
||||
# Append content_text if it exists in properties
|
||||
if properties.get("content_text"):
|
||||
if isinstance(properties["content_text"], dict):
|
||||
# If content_text is a dictionary, use format with kwargs
|
||||
message = message.format(**properties["content_text"])
|
||||
elif isinstance(properties["content_text"], str):
|
||||
# If content_text is a string, append it with proper spacing
|
||||
content = properties["content_text"].strip()
|
||||
if message and content:
|
||||
# Use HTML line breaks for email compatibility
|
||||
message = f"{message.rstrip()}<br><br>{content}"
|
||||
else:
|
||||
# If either is empty, just use the non-empty one
|
||||
message = message or content
|
||||
|
||||
return message, message_subject
|
||||
|
||||
except KeyError as e:
|
||||
raise RuntimeError(f"Unsupported configuration - subject: {subject_lower}, event: {event_lower}, error: {str(e)}")
|
||||
except ValueError as e:
|
||||
raise RuntimeError(f"Invalid message format - error: {str(e)}")
|
||||
|
||||
async def send_in_app_notification(
|
||||
self, receiver_id: str, subject: str, event: str, properties: dict = None
|
||||
|
||||
Loading…
Reference in New Issue
Block a user