Documentation Index
Fetch the complete documentation index at: https://docs.photon.codes/docs/llms.txt
Use this file to discover all available pages before exploring further.
client.events.subscribe() returns an async iterable of every event Meta sends for your business account — inbound messages and delivery status updates. The stream reconnects automatically on failure and buffers missed events while you’re offline.
The event stream
cursor string. The cursor advances with each event — save the most recent one and pass it back on restart to pick up where you left off:
Subscribe options
SubscribeOptions
SubscribeOptions
| Option | Type | Description |
|---|---|---|
cursor | string | Resume from a previously saved cursor. |
reconnect | ReconnectOptions | Reconnection configuration for automatic reconnects. |
Inbound messages
Whenevent.type === "message", the event carries an . Narrow on content.type before reading content-specific fields:
Inbound content variants
InboundContent
Every content shape a WhatsApp user can send.
InboundContent
Every content shape a WhatsApp user can send.
| Variant | Fields |
|---|---|
"text" | body |
"image" | media |
"video" | media |
"audio" | media |
"document" | media |
"sticker" | sticker |
"location" | location |
"contacts" | contacts |
"reaction" | reaction |
"interactive" | interactive |
"button" | button |
"order" | order |
"system" | system |
"unknown" | — |
Replying to an incoming message
Thread your reply withreplyTo: message.id:
Status updates
Whenevent.type === "status", the event carries a . The status field progresses through sent → delivered → read (or played for voice notes, or failed):
status.bizOpaqueCallbackData echoes whatever you passed on the original send() call — use it to correlate the status back to your own order/ticket/session ID.
Reconnection
subscribe() reconnects automatically. Tune the backoff via options.reconnect:
ReconnectOptions
ReconnectOptions
| Option | Type | Description |
|---|---|---|
initialDelay | number | Initial delay in milliseconds before the first reconnect. Default 1000. |
maxAttempts | number | Maximum number of consecutive reconnect attempts. Default Infinity. |
maxDelay | number | Maximum delay in milliseconds between retries. Default 30000. |
multiplier | number | Multiplier applied to the delay after each failed attempt. Default 2. |
onReconnect | (attempt: number) => void | Callback invoked before each reconnect attempt. |
fetchMissedEvents with the last cursor it saw, so you don’t lose events that arrived while you were offline.
Fetching missed events manually
If your client crashed without draining the stream, fetch missed events on startup before resubscribing:app_secret server-side before being returned — payloads that fail verification are dropped.
Message context, referrals, errors
EveryInboundMessage can also carry:
context— reply-to metadata if the user replied to one of your earlier messages.referral— set when the user arrived via a Click-to-WhatsApp ad.errors— non-empty when Meta returned a partial error alongside the message.contact— the sender’s display name (when available).