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.1 KB
Raw Blame
"""Bridge to the canvas product's teaching-tour seeding.

The tour itself (source, publish, get-or-seed semantics) lives in the canvas
product, reached through its facade; this module adapts it to the shape the
onboarding brief carries. Seeding runs synchronously
in the sign-in path so the session's followup can point at the canvas by id.
"""

from uuid import UUID

from posthog.dataclasses import frozen
from posthog.models.user import User

from products.canvas.backend.facade.enums import TEACHING_CANVAS_NAME as TEACHING_CANVAS_NAME


@frozen
class TeachingCanvas:
    channel_id: UUID
    canvas_id: UUID


def ensure_teaching_canvas(
    team_id: int, channel_id: UUID, user: User, *, refresh: bool = False
) -> TeachingCanvas | None:
    from products.canvas.backend.facade.api import (  # noqa: PLC0415 — keeps the canvas build path off task route setup
        seed_teaching_canvas,
    )

    canvas_id = seed_teaching_canvas(team_id=team_id, channel_id=channel_id, user=user, refresh=refresh)
    if canvas_id is None:
        return None
    return TeachingCanvas(channel_id=channel_id, canvas_id=canvas_id)