Every webhook delivery body, discriminated on type. Switch on type and TypeScript narrows data to the right payload.
type
data
Async consult lifecycle:
async_consult.created
async_consult.consented
async_consult.declined
async_consult.queued
async_consult.assigned
async_consult.reassigned
async_consult.message
async_consult.message_rejected
async_consult.resolve_requested
async_consult.reopened
active
async_consult.closed
data.closedReason
async_consult.rated
Telehealth lifecycle:
telehealth.created
telehealth.waiting
telehealth.ringing
data.practitionerId
telehealth.in_progress
telehealth.completed
telehealth.cancelled
telehealth.recording_ready
telehealth.rated
function handle(event: WebhookEvent) { switch (event.type) { case 'async_consult.message': return renderMessage(event.data.asyncConsultId, event.data.message); case 'async_consult.closed': return markClosed(event.data.consult.id, event.data.closedReason); // … }} Copy
function handle(event: WebhookEvent) { switch (event.type) { case 'async_consult.message': return renderMessage(event.data.asyncConsultId, event.data.message); case 'async_consult.closed': return markClosed(event.data.consult.id, event.data.closedReason); // … }}
Every webhook delivery body, discriminated on
type. Switch ontypeand TypeScript narrowsdatato the right payload.Async consult lifecycle:
async_consult.created— consult created via the API.async_consult.consented— patient accepted the consent prompt.async_consult.declined— patient declined; the consult closed without ever starting.async_consult.queued— consented but waiting for physician capacity.async_consult.assigned— a physician took the thread.async_consult.reassigned— the thread moved to another physician (SLA breach or takeover).async_consult.message— a message landed on the transcript (any author, including system notices).async_consult.message_rejected— a 202-accepted patient message could not be routed (thread closed underneath).async_consult.resolve_requested— the physician marked it resolved; the acceptance window is running.async_consult.reopened— the patient replied during the acceptance window; back toactivewith the same physician.async_consult.closed— terminal;data.closedReasonsays why.async_consult.rated— the patient rated the consult.Telehealth lifecycle:
telehealth.created— consult created via the API.telehealth.waiting— the patient entered the waiting room.telehealth.ringing— a physician was reserved; the patient's client is confirming (data.practitionerId). Not yet a call.telehealth.in_progress— a physician joined; the call is live.telehealth.completed— the call ended.telehealth.cancelled— cancelled before/without a call.telehealth.recording_ready— composite recording (and transcript, when produced) are available; GET the consult for a fresh URL.telehealth.rated— the patient rated the call.