Fix the concatenation issue with message

This commit is contained in:
jetli 2025-03-13 23:46:49 -07:00
parent 2043baf4ab
commit b12f8cc965

View File

@ -86,26 +86,44 @@ class NotificationManager:
properties: dict, properties: dict,
region: Optional[UserRegion] = None, region: Optional[UserRegion] = None,
) -> str: ) -> str:
# leverage the information in properties to enrich the message. # Default region to international if not set
message_subject = None
message = None
if subject.lower() == "payment":
pass
# Default region to be international if not set
if region is None: if region is None:
region = UserRegion.OTHER region = UserRegion.OTHER
message_subject = SystemNotifications[region][subject.lower()][event.lower()][ subject_lower = subject.lower()
"message_subject" event_lower = event.lower()
]
message = SystemNotifications[region][subject.lower()][event.lower()]["message"]
if event.lower() == "authentication": try:
message = message.format(properties["auth_code"]) # Get message template and subject from SystemNotifications
if not message: notification_config = SystemNotifications[region][subject_lower][event_lower]
raise RuntimeError("unsupported event:{}".format(event)) message = notification_config["message"]
return message, message_subject 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( async def send_in_app_notification(
self, receiver_id: str, subject: str, event: str, properties: dict = None self, receiver_id: str, subject: str, event: str, properties: dict = None