Skip to content

notifications.dto

dto

codex_platform.notifications.dto

Notification payload contracts.

Three classes:

NotificationPayloadDTO — base, always required fields TemplateNotificationDTO — Mode 1: workers fetches context from Redis, renders template RenderedNotificationDTO — Mode 2: pre-rendered HTML (e.g. from Django)

Classes

NotificationRecipient

Bases: BaseDTO

Recipient info. PII fields auto-masked in repr via BaseDTO.

Source code in src/codex_platform/notifications/dto.py
class NotificationRecipient(BaseDTO):
    """Recipient info. PII fields auto-masked in __repr__ via BaseDTO."""

    email: str | None = None
    phone: str | None = None

NotificationPayloadDTO

Bases: BaseDTO

Base notification payload — identification and routing only.

Do not use directly. Use TemplateNotificationDTO or RenderedNotificationDTO.

Source code in src/codex_platform/notifications/dto.py
class NotificationPayloadDTO(BaseDTO):
    """
    Base notification payload — identification and routing only.

    Do not use directly. Use TemplateNotificationDTO or RenderedNotificationDTO.
    """

    notification_id: str
    recipient: NotificationRecipient
    channels: list[NotificationChannel] = [NotificationChannel.EMAIL]
    event_type: str | None = None
    subject: str | None = None

TemplateNotificationDTO

Bases: NotificationPayloadDTO

Mode 1 — Worker renders the template itself (requires Jinja2).

Redis key where context_data is stored (JSON).

Allows updating data after enqueue (e.g. reschedule).

template_name: Relative template path (e.g. 'booking/bk_confirmation.html').

Source code in src/codex_platform/notifications/dto.py
class TemplateNotificationDTO(NotificationPayloadDTO):
    """
    Mode 1 — Worker renders the template itself (requires Jinja2).

    context_key: Redis key where context_data is stored (JSON).
                 Allows updating data after enqueue (e.g. reschedule).
    template_name: Relative template path (e.g. 'booking/bk_confirmation.html').
    """

    template_name: str
    context_key: str

RenderedNotificationDTO

Bases: NotificationPayloadDTO

Mode 2 — Pre-rendered HTML passed directly to the workers.

Use when Django (or another layer) renders the template and the workers only needs to deliver.

Source code in src/codex_platform/notifications/dto.py
class RenderedNotificationDTO(NotificationPayloadDTO):
    """
    Mode 2 — Pre-rendered HTML passed directly to the workers.

    Use when Django (or another layer) renders the template
    and the workers only needs to deliver.
    """

    html_content: str
    text_content: str | None = None