npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

wapi-cloud

v1.0.1

Published

A promise-based, fully-typed Node.js wrapper for integrating the WhatsApp Cloud API (Meta Graph API) into your applications.

Readme

wapi-cloud

A promise-based, fully-typed Node.js wrapper for the WhatsApp Cloud API (Meta Graph API)

npm version npm downloads License: MIT TypeScript

Documentation · Quick Start · NPM · Webhooks · Examples · Contributing


📚 Documentation

Full documentation is available at:

👉 Messaging API documentation The documentation site contains detailed guides and API references


✨ Features

  • 🔒 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-paginationfor await over any list endpoint
  • 🌲 Tree-shakeable — ships as ESM + CJS with .d.ts via tsup

📦 Install

npm install wapi-cloud

🚀 Quick Start

1. Import and configure

import { 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!,
});

2. Send your first message

const { data, error } = await whatsapp.messages.sendText(
  "15551234567",
  {
    body: "Hello from wapi-cloud!",
  }
);

if (error) {
  console.error(error);
} else {
  console.log(data);
}

📖 Learn more

For the complete setup guide, configuration options, authentication, and examples:

👉 Read the Quick Start documentation


🎯 Every call returns { data, error }

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: data and error are mutually exclusive — TypeScript narrows correctly once you check error.

Every response also carries:

  • status
  • statusText
  • raw

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.


💬 Sending Messages

Text

await whatsapp.messages.sendText(
  "15551234567",
  {
    body: "Hello!",
  }
);

Template

await whatsapp.messages.sendTemplate(
  "15551234567",
  {
    name: "order_confirmation",
    language: "en_US",
    components: [
      {
        type: "body",
        parameters: [
          {
            type: "text",
            text: "Jordan",
          },
        ],
      },
    ],
  }
);

Image

await whatsapp.messages.sendImage(
  "15551234567",
  {
    link: "https://example.com/photo.jpg",
  }
);

Interactive message

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


🗂 Templates, Media & Account Management

Templates

const { data } = await whatsapp.templates.create({
  name: "order_confirmation",
  category: "UTILITY",
  language: "en_US",
  components: [
    {
      type: "BODY",
      text: "Hi {{1}}, your order is confirmed.",
    },
  ],
});

Auto-pagination

for await (const template of whatsapp.templates.listAll()) {
  console.log(template.name);
}

Media

const { data: media } = await whatsapp.media.upload(
  fileBuffer,
  {
    type: "image/png",
  }
);

await whatsapp.messages.sendImage(
  to,
  {
    mediaId: media!.id,
  }
);

| 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:

https://wapi-cloud-docs.vercel.app/


🪝 Webhooks

Manual style

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);
  }
);

One-liner style

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


📖 Documentation & Resources

| 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 |


🛠 Development

Clone the repository:

git clone https://github.com/niyassby/wapi-cloud.git

cd wapi-cloud

npm install

Run type checking:

npm run typecheck

Build the package:

npm run build

The build generates:

  • ESM
  • CommonJS
  • TypeScript declaration files

using tsup.


🤝 Contributing

Contributions are welcome!

Please open an issue to discuss significant changes before submitting a PR.

See CONTRIBUTING.md for contribution guidelines.


📄 License

MIT © wapi-cloud contributors


Built with ❤️ for developers integrating WhatsApp into their products.