FastAPI + Celery + Next.js + Postgres/Redis app with company monitoring, source collection, LLM-based change analysis, enrichment, and account security (Turnstile, escalating lockout, email verification).
32 lines
1.3 KiB
Python
32 lines
1.3 KiB
Python
"""Resolves a NotificationType to a concrete provider. Console is always
|
|
available and never costs anything; email/SMS are only meaningfully
|
|
configured when their settings are present (callers gate on
|
|
NOTIFICATION_SMS_ENABLED before ever routing to SMS - see alert_service.py).
|
|
|
|
SMS has two interchangeable vendor providers (`SMS_PROVIDER=twilio|telnyx`),
|
|
same pattern as LLM_PROVIDER/SEARCH_PROVIDER elsewhere in the app - swapping
|
|
the setting changes which class this returns and nothing else has to change.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from app.core.config import Settings
|
|
from app.models.enums import NotificationType
|
|
from app.notifications.base import NotificationProvider
|
|
from app.notifications.console import ConsoleProvider
|
|
from app.notifications.smtp_email import SmtpEmailProvider
|
|
from app.notifications.telnyx_sms import TelnyxSmsProvider
|
|
from app.notifications.twilio_sms import TwilioSmsProvider
|
|
|
|
|
|
def get_notification_provider(
|
|
notification_type: NotificationType, settings: Settings
|
|
) -> NotificationProvider:
|
|
if notification_type == NotificationType.EMAIL:
|
|
return SmtpEmailProvider(settings)
|
|
if notification_type == NotificationType.SMS:
|
|
if settings.sms_provider == "telnyx":
|
|
return TelnyxSmsProvider(settings)
|
|
return TwilioSmsProvider(settings)
|
|
return ConsoleProvider()
|