Fix the concatenation issue with message
This commit is contained in:
parent
2043baf4ab
commit
b12f8cc965
@ -86,27 +86,45 @@ 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:
|
||||||
|
# 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"])
|
message = message.format(properties["auth_code"])
|
||||||
if not message:
|
|
||||||
raise RuntimeError("unsupported event:{}".format(event))
|
# 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
|
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
|
||||||
) -> None:
|
) -> None:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user