Skip to content

parseWebhook

parseWebhook(body, options?): WebhookPayload

Defined in: src/resources/webhook-core.ts:120

Validates the top-level envelope and returns it typed as a WebhookPayload. Accepts a parsed object or a JSON string (parsed internally). Only the top-level shape is validated (object is whatsapp_business_account and entry is an array); per-message narrowing happens lazily in extractMessages/extractStatuses so new Meta message types never break parsing.

String and byte bodies larger than options.maxBodyBytes (default 3 MiB, Meta’s documented maximum) are rejected before parsing.

unknown

A parsed webhook object, or its JSON as a string, Uint8Array (including Node byte buffers) or ArrayBuffer. Byte bodies are decoded as UTF-8.

ParseWebhookOptions = {}

Optional size limit override.

WebhookPayload

WhatsAppWebhookError when the body is unparseable or malformed.

Independent open-source project. Not affiliated with, endorsed by or sponsored by Meta or WhatsApp. Released under the MIT licence. Source on GitHub.