Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

1.5 KB
Raw Blame
"""Everything the shared platform delivers one alert's events to."""

from __future__ import annotations

from collections.abc import Collection

from products.alerts.backend.logic.alert_email import (
    SUBSCRIBER_EVENT_IDS,
    insight_alert,
    insight_email_groups,
    recipients_with_access,
)
from products.alerts.backend.logic.alert_in_app import insight_in_app_groups
from products.alerts.backend.logic.destinations import list_alert_destination_groups
from products.alerts_platform.backend.facade.contracts import AlertDestinationGroup


def list_delivery_destination_groups(
    *, team_id: int, alert_id: str, allowed_event_ids: Collection[str]
) -> list[AlertDestinationGroup]:
    """An alert's HogFunction destinations, plus its subscribers' email and in-app notifications
    for an insight alert.

    Separate from `list_alert_destination_groups`, which the alert APIs list and delete through. A
    subscriber group there would show up as a destination a person could delete.
    """
    groups = [
        *list_alert_destination_groups(team_id=team_id, alert_id=alert_id, allowed_event_ids=allowed_event_ids),
    ]
    event_ids = SUBSCRIBER_EVENT_IDS.intersection(allowed_event_ids)
    if not event_ids:
        return groups
    alert = insight_alert(team_id=team_id, alert_id=alert_id)
    if alert is None:
        return groups
    recipients = recipients_with_access(alert)
    return [
        *groups,
        *insight_email_groups(recipients),
        *insight_in_app_groups(alert, event_ids=event_ids, recipients_with_access=recipients),
    ]