import type { Db } from "@peppa/db"; import { sql } from "drizzle-orm"; export const EVENTS_CHANNEL = "peppa_events"; export type PeppaNotification = | { type: "question"; questionId: number } | { type: "question_answered"; questionId: number } | { type: "task_updated"; taskId: number } | { type: "progress"; eventId: number } | { type: "session_updated"; sessionId: number } | { type: "incident"; incidentId: number }; /** Broadcasts via Postgres NOTIFY; the bot and web listen on EVENTS_CHANNEL. */ export async function notify(db: Db, n: PeppaNotification): Promise { await db.execute(sql`select pg_notify(${EVENTS_CHANNEL}, ${JSON.stringify(n)})`); }