import type { NormalizedEvent } from "@b2bcall/telephony"; import { getRedisClient } from "../common/redis"; const EVENTS_CHANNEL = "b2bcall:events"; /** * Publica no mesmo canal que b2bcall-fs-events usa pros eventos vindos do * FreeSWITCH — o RealtimeRedisBridge (apps/api) não distingue a origem, só * reencaminha pro tenant certo via WebSocket (docs/REALTIME.md). Diferente * dos eventos vindos do ESL, aqui o tenantId já é conhecido de cara (vem do * JWT da requisição HTTP) — não precisa do fan-out de tenant-resolve.ts. */ export async function publishAgentStateChanged( tenantId: string, agentId: string, state: string, ): Promise { const event: NormalizedEvent = { type: "AGENT_STATE_CHANGED", occurredAt: new Date().toISOString(), tenantId, data: { agentId, state }, }; await getRedisClient().publish(EVENTS_CHANNEL, JSON.stringify(event)); }