Configuration
WhatsAppClient takes a single configuration object. Only accessToken is
required; everything else has a sensible default.
| Option | Type | Default | Description |
|---|---|---|---|
accessToken |
string |
— (required) | Permanent or temporary access token used to authenticate requests. |
phoneNumberId |
string |
— | Default sender phone number ID for messaging and media calls. |
businessAccountId |
string |
— | WhatsApp Business Account (WABA) ID. Default id for client.waba methods. |
apiVersion |
string |
v26.0 |
Graph API version to target. |
baseUrl |
string |
https://graph.facebook.com |
Base URL for the Graph API (override for a proxy or a mock). |
timeoutMs |
number |
30000 |
Per-attempt request timeout in milliseconds. |
maxRetries |
number |
2 |
Max retries (total attempts = maxRetries + 1). See Retries. |
retryMessageSends |
boolean |
false |
Also retry message sends on 5xx, network and timeout errors. Can send a message twice. |
The defaults are exported as DEFAULT_API_VERSION, DEFAULT_BASE_URL,
DEFAULT_TIMEOUT_MS, and DEFAULT_MAX_RETRIES.
const client = new WhatsAppClient({ accessToken: process.env.WHATSAPP_ACCESS_TOKEN!, phoneNumberId: process.env.WHATSAPP_PHONE_NUMBER_ID!, businessAccountId: process.env.WHATSAPP_WABA_ID, apiVersion: 'v26.0', timeoutMs: 15_000, maxRetries: 3,});
client.getPhoneNumberId(); // the configured default sender, if anyclient.getApiVersion(); // 'v26.0'client.getBaseUrl(); // 'https://graph.facebook.com/v26.0'Per-call phone number override. Every message and media method accepts an
optional trailing phoneNumberId so a single client can send from multiple
numbers. When omitted, the client’s configured phoneNumberId is used; if
neither is set, the call throws WhatsAppValidationError.
The HTTP core retries with jittered exponential backoff, honoring a
Retry-After header when present. GET, DELETE and non-message POST
requests retry on 429, 5xx and network/timeout errors. A POST to
{phoneNumberId}/messages (sends, sendRaw, mark-as-read, typing indicators)
retries on 429 only, because Meta documents no idempotency for sends and a
retry after a lost response could deliver the message twice. Set
retryMessageSends: true to retry those on 5xx and network errors too. See
Retries.
Independent open-source project. Not affiliated with, endorsed by or sponsored by Meta or WhatsApp. Released under the MIT licence. Source on GitHub.