Your handler receives one Event per delivery. Branch on event.type, read data via the typed accessor.
@client.on_event()
async def handle(event):
if event.type == "webhook.received":
handle_webhook(event.webhook) # WebhookData | None
elif event.type == "email.received":
handle_email(event.email) # EmailData | None
Fields
| Attribute | Type | Notes |
|---|---|---|
id | str | ULID. Stable across live + replay. |
type | str | webhook.received or email.received. |
origin | str | live or replay. Use for idempotency. |
created_at | datetime | Timezone-aware UTC. |
channel | Channel | .id, .label, .type. |
data | dict[str, Any] | Raw source payload. |
prompt_ready | str | LLM-ready text rendering. |
prompt_ready_version | int | Renderer version stamp. |
webhook | WebhookData | None | Populated when type == "webhook.received". |
email | EmailData | None | Populated when type == "email.received". |
WebhookData
event.webhook.method # "POST"
event.webhook.path # "/v1/webhook/…"
event.webhook.headers # dict[str, str]
event.webhook.body_encoding # "json" | "text" | "base64"
event.webhook.body # Any | None — JSON-decoded when encoding is "json"
event.webhook.body_raw_b64 # str — raw bytes base64-encoded, when "base64"
event.webhook.body_size_bytes # int
EmailData
event.email.from_ # str — (note the trailing underscore; `from` is a Python keyword)
event.email.to # list[str]
event.email.cc # list[str]
event.email.bcc # list[str]
event.email.subject # str
event.email.text # str
event.email.html # str
event.email.message_id # str — RFC 5322 Message-ID; used for threading replies
event.email.attachments # list[Attachment]
event.email.received_at # datetime | None
Attachment
attachment.filename # str
attachment.content_type # str
attachment.size_bytes # int
attachment.url # str | None — signed, short-lived (future)
Immutability
Event is a frozen dataclass. Safe to share across tasks, safe to cache, safe to hash.
Prompt-ready
A small convenience: event.prompt_ready is a pre-rendered text string useful when a model is the next hop. Ignore it if you don’t need it. See Prompt-ready.