A WhatsApp Cloud API channel.
Pass it as host({channels: {whatsapp: whatsapp({...})}}). Webhooks are verified with the app secret; a message becomes a run of agent, and the reply is sent from the business phone number the message arrived on. Secrets are resolved on the host at ready().
Import from @threads/whatsapp (TypeScript) or threads.whatsapp (Python).
function whatsapp(options: {
agent: string;
appSecret: Secret;
verifyToken: Secret;
accessToken: Secret;
graphVersion?: string;
tenant?: string | ((phoneNumberId: string) => string | undefined);
fetch?: (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
now?: () => number;
}): ChannelAdapterParameters
agentstringrequiredThe key of host({agents}) this channel routes to. invalid_config: the channel's agent must be a key of host({ agents }).
appSecret / app_secretSecretrequiredThe Meta app secret that signs webhooks. Unset at ready() is missing_secret. See Secret.
verifyToken / verify_tokenSecretrequiredThe token Meta's subscription check (GET) must present. Unset at ready() is missing_secret. See Secret.
accessToken / access_tokenSecretrequiredA system-user access token replies are sent with. Unset at ready() is missing_secret. See Secret.
graphVersion / graph_versionstringdefault v21.0The Graph API version replies are sent to.
tenantstring | ((phoneNumberId: string) => string | undefined)TypeScript only. The tenant for a business phone number, or a function mapping a phone number id to one (undefined refuses it). Omitted: whatsapp:<phone_number_id>. In Python each number is whatsapp:<phone_number_id>.
tenant(phoneNumberId)stringrequiredTypeScript only. The business phone number id the webhook speaks for.
fetch(input: string | URL | Request, init?: RequestInit) => Promise<Response>TypeScript only. Seam: the fetch replies are sent through (tests); the run's fence wraps it either way. Omitted: the process's fetch.
now() => numberTypeScript only. Seam: the clock the 24-hour session window is checked against, in milliseconds (tests). Omitted: Date.now.
apistrdefault https://graph.facebook.comPython only. Seam: the Graph API base URL, before the version (tests point it at a fake).
transporthttpx.AsyncBaseTransportPython only. Seam: the httpx transport replies are sent through (tests); the run's fence wraps it either way. Omitted: httpx's default.
Returns
Throws ConfigError with one of these codes: invalid_config, missing_secret.