freeleaps-service-hub/apps/notification/backend/application/notification_hub.py
2024-10-30 20:49:50 -07:00

37 lines
1.2 KiB
Python

from typing import Dict
from backend.business.notification_manager import NotificationManager
from backend.models.constants import NotificationChannel
class NotificationHub:
def __init__(self):
pass
async def enqueue_notification(
self,
channels: list[str], # Accept multiple channels as a list of strings
receiver_id: str,
subject: str,
event: str,
properties: Dict,
):
# Convert string channels to NotificationChannel enums
notification_channels = []
for channel_str in channels:
try:
notification_channels.append(NotificationChannel[channel_str.upper()])
except KeyError:
raise ValueError(f"Unsupported notification channel: {channel_str}")
# Initialize NotificationManager with sender_id
notification_manager = NotificationManager()
# Call the enqueue_notification method in NotificationManager
return await notification_manager.enqueue_notification(
channels=notification_channels,
receiver_id=receiver_id,
subject=subject,
event=event,
properties=properties,
)