A promise-based, fully-typed Node.js wrapper for the WhatsApp Cloud API (Meta Graph API)
Documentation Β· Quick Start Β· NPM Β· Webhooks Β· Examples Β· Contributing
Full documentation is available at:
π Messaging API documentation The documentation site contains detailed guides and API references
- π Fully typed β first-class TypeScript support, narrows correctly on error checks
- π§΅ Never throws β every call resolves to a consistent
{ data, error }result, Supabase-style - π¦ Batteries included β messages, templates, media, contacts, flows, QR codes, analytics
- πͺ Webhook helpers β signature verification, event parsing, and an Express one-liner
- π Auto-pagination β
for awaitover any list endpoint - π² Tree-shakeable β ships as ESM + CJS with
.d.tsviatsup
npm install wapi-cloudimport { Whatsapp } from "wapi-cloud";
const whatsapp = new Whatsapp({
accessToken: process.env.WA_TOKEN!,
phoneNumberId: process.env.WA_PHONE_ID!,
businessAccountId: process.env.WA_WABA_ID!,
appSecret: process.env.WA_APP_SECRET!,
});const { data, error } = await whatsapp.messages.sendText(
"15551234567",
{
body: "Hello from wapi-cloud!",
}
);
if (error) {
console.error(error);
} else {
console.log(data);
}For the complete setup guide, configuration options, authentication, and examples:
π Read the Quick Start documentation
No try/catch needed for expected API failures β every SDK method resolves, never throws, and gives you a consistent result object:
const { data: templates, error } = await whatsapp.templates.list();
if (error) {
console.error(error.code, error.type, error.message);
// Additional information:
// error.isRetryable
// error.raw
// error.fbtraceId
} else {
console.log(templates.items);
}Why this matters:
dataanderrorare mutually exclusive β TypeScript narrows correctly once you checkerror.
Every response also carries:
statusstatusTextraw
The raw property contains the untouched Graph API JSON as an escape hatch.
Config-only failures, such as calling:
whatsapp.templates.list();without providing a businessAccountId, also return:
{
data: null,
error
}rather than throwing.
await whatsapp.messages.sendText(
"15551234567",
{
body: "Hello!",
}
);await whatsapp.messages.sendTemplate(
"15551234567",
{
name: "order_confirmation",
language: "en_US",
components: [
{
type: "body",
parameters: [
{
type: "text",
text: "Jordan",
},
],
},
],
}
);await whatsapp.messages.sendImage(
"15551234567",
{
link: "https://example.com/photo.jpg",
}
);await whatsapp.messages.sendInteractive(
"15551234567",
{
type: "button",
body: "Pick one:",
buttons: [
{
id: "yes",
title: "Yes",
},
{
id: "no",
title: "No",
},
],
}
);π See the complete Messaging API documentation
const { data } = await whatsapp.templates.create({
name: "order_confirmation",
category: "UTILITY",
language: "en_US",
components: [
{
type: "BODY",
text: "Hi {{1}}, your order is confirmed.",
},
],
});for await (const template of whatsapp.templates.listAll()) {
console.log(template.name);
}const { data: media } = await whatsapp.media.upload(
fileBuffer,
{
type: "image/png",
}
);
await whatsapp.messages.sendImage(
to,
{
mediaId: media!.id,
}
);Full module surface
| Module | Description |
|---|---|
messages |
Send WhatsApp messages |
templates |
Create, list, and manage message templates |
media |
Upload and reference media assets |
contacts |
Contact management |
phoneNumbers |
Phone number configuration |
businessProfile |
Business profile details |
flows |
WhatsApp Flows |
qrCodes |
QR code / short-link management |
analytics |
Messaging analytics |
twoStepVerification |
Two-step verification settings |
webhooks |
Webhook verification and event parsing |
See src/modules/ for the full source.
π For detailed API documentation, visit:
app.post(
"/webhook",
express.raw({
type: "application/json",
}),
(req, res) => {
if (
!whatsapp.webhooks.verifySignature({
payload: req.body,
signatureHeader:
req.headers["x-hub-signature-256"],
})
) {
return res.sendStatus(401);
}
const events = whatsapp.webhooks.parse(req.body);
for (const event of events) {
if (
event.type === "message" &&
event.messageType === "text"
) {
whatsapp.messages.sendText(
event.from,
{
body: `Echo: ${event.text.body}`,
}
);
}
}
res.sendStatus(200);
}
);whatsapp.webhooks.handleExpress(
app,
"/webhook",
{
verifyToken: process.env.WA_VERIFY_TOKEN!,
}
);
whatsapp.webhooks.on("message", (msg) => {
// Handle incoming message
});
whatsapp.webhooks.on("status", (status) => {
// Handle message status
});π See examples/node-express-webhook for a full runnable server.
π Read the Webhooks documentation
| Resource | Link |
|---|---|
| π Documentation | wapi-cloud-docs |
| π¦ NPM Package | npmjs.com/package/wapi-cloud |
| π» GitHub Repository | github.com/niyassby/wapi-cloud |
| π Examples | ./examples |
| π€ Contributing | CONTRIBUTING.md |
| π License | LICENSE |
Clone the repository:
git clone https://github.com/niyassby/wapi-cloud.git
cd wapi-cloud
npm installRun type checking:
npm run typecheckBuild the package:
npm run buildThe build generates:
- ESM
- CommonJS
- TypeScript declaration files
using tsup.
Contributions are welcome!
Please open an issue to discuss significant changes before submitting a PR.
See CONTRIBUTING.md for contribution guidelines.
MIT Β© wapi-cloud contributors
Built with β€οΈ for developers integrating WhatsApp into their products.
π Read the full documentation β