Most apps should use Spectrum - it gives you
a unified, higher-level API across WhatsApp Business, iMessage, and other
platforms. Reach for
@photon-ai/whatsapp-business directly only when you
need low-level WhatsApp control that Spectrum doesn’t expose.@photon-ai/whatsapp-business is a TypeScript SDK for the WhatsApp Business API. It connects to our managed gRPC gateway, which fronts Meta’s Cloud API — you get typed message sending, a resumable event stream, and media handling without wiring webhooks yourself.
Installation
Credentials
Three values are required. Get them in one of two ways:- Spectrum Cloud (one-click)
- Bring your own Meta app
Sign up at app.photon.codes, toggle WhatsApp on in your project, finish the guided config, and copy the credentials.Use these directly with
createClient, or pass them to spectrum-ts to combine WhatsApp with iMessage and other platforms behind one unified API.Quick start
createClient
| Option | Type | Description |
|---|---|---|
retry | boolean | RetryOptions | Enable automatic retry with exponential backoff for retryable errors. Pass true for default settings, or a RetryOptions object to customise the behaviour. |
timeout | number | Default timeout in milliseconds for unary RPC calls. Sets a deadline on each call unless one is already provided. |
WhatsAppClient exposes three resources:
Disposing the client
The client implementsSymbol.asyncDispose, so await using handles teardown automatically:
Your first echo bot
event.typeis narrowed to"message"or"status"— only messages get a.messagefield.InboundContentis a discriminated union; switch oncontent.typebefore reading fields.event.message.fromis the WhatsApp ID of the sender — pass it straight tosend.to.