WhaBuzzdocs
Start

Node.js SDK

Install the whabuzz package, send your first message in ten lines, verify webhooks.

The whabuzz package for Node 18+ and edge runtimes. Zero dependencies, fetch only, ESM and CommonJS, full TypeScript types. Request bodies and responses are Meta's own.

bash
npm install whabuzz
export WHABUZZ_API_KEY="wb_live_..."   # your key

#First message

js
import { WhaBuzz } from 'whabuzz';

const wb = new WhaBuzz(); // reads WHABUZZ_API_KEY
const res = await wb.messages.send({
  from: '+14692311132', // your connected number
  to: process.env.TO, // the recipient, E.164
  type: 'text',
  text: { body: 'Hello from WhaBuzz' },
});
console.log(res.messages[0].id);

Outside the 24-hour customer window send a template instead. A busy number answers 202 {"status":"queued"}; the message then goes out in order.

#Options and resources

new WhaBuzz({ apiKey, baseUrl, tenant, fetch, timeoutMs }). Platform keys pass tenant. Pass { idempotencyKey } as the second argument of send, batch and create calls; see Idempotency.

tenant.get, messages (send, batch, getBatch, listBatchItems, cancelBatch, markRead), templates (list, create, get), numbers (list, get), webhooks.endpoints (list, create, get, update, delete, verify, rotateSecret), events (list, get, iterate), media.get, connectSessions (create, get, list; see below). For any other route use wb.request({ method, path }).

#Connect sessions

Create a hosted link for your customer, then verify the return on your server. The flow is in Onboard your customer's number.

js
const session = await wb.connectSessions.create({
  return_url: 'https://app.example.com/whatsapp/done',
  branding: { product_name: 'Acme CRM' },
});
// redirect the customer to session.url

// on return_url: session_id, state and result_token come from the query string
const s = await wb.connectSessions.get(sessionId, { resultToken });
if (s.result_token?.valid && s.state === 'completed') console.log(s.result.phone_number_id);

const page = await wb.connectSessions.list({ limit: 25 }); // page.next_before for the next page

An invalid or expired resultToken throws a WhaBuzzError with code: 'invalid_result_token'.

#Errors

Failures throw WhaBuzzError: status, source (meta, whabuzz, client), code, meta (Meta's error object, verbatim), requestId. See Errors.

js
try {
  await wb.messages.send(body);
} catch (e) {
  if (e.source === 'meta') console.error(e.meta.code, e.meta.message);
  else throw e;
}

#Verify a webhook

js
import { verifyWebhook } from 'whabuzz';

// rawBody must be the exact bytes received, before JSON parsing
const event = await verifyWebhook(rawBody, request.headers, process.env.WHABUZZ_WEBHOOK_SECRET);
console.log(event.type);

It throws WebhookVerificationError with a reason when the signature, timestamp (300 s) or header is wrong. Details of the scheme: Webhooks.

#Next

The same package ships the whabuzz CLI.

This page as Markdown: /sdks/node.md. All docs in one file: /llms-full.txt. Status.