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

@awadoc/whatsapp-cloud-api

v3.1.3

Published

Node.js library for creating bots and sending/receiving messages using the Whatsapp Cloud API

Downloads

172

Readme

whatsapp-cloud-api

A modern Node.js wrapper for WhatsApp Cloud API with full TypeScript support. Built to send and receive messages, handle webhooks via Express or Next.js, and scale cleanly in your apps.

Forked from: tawn33y/whatsapp-cloud-api (Archived)
Maintained with extended support, modular routing, and Next.js support.


🚀 Install

npm install @awadoc/whatsapp-cloud-api

For Next.js support (optional):

npm install next

📦 Usage with Express

import express from "express";
import { createBot } from "@awadoc/whatsapp-cloud-api";
import { getExpressRoute } from "@awadoc/whatsapp-cloud-api/express";

const phoneId = process.env.PHONE_ID!;
const token = process.env.ACCESS_TOKEN!;
const webhookVerifyToken = process.env.WEBHOOK_VERIFY_TOKEN!;

const app = express();
const bot = createBot(phoneId, token);

// Register WhatsApp webhook route
app.use("/webhook", getExpressRoute(phoneId, { webhookVerifyToken }));

// Handle incoming messages
bot.on("message", async (msg) => {
  console.log(msg);
  if (msg.type === "text") {
    await bot.sendText(msg.from, "Got your text!");
  }
});

app.listen(3000, () => console.log("Server running on http://localhost:3000"));

📦 Usage with Next.js

App Router (Next.js 13+)

// app/api/whatsapp/webhook/route.ts
import { createBot } from "@awadoc/whatsapp-cloud-api";
import { getNextAppRouteHandlers } from "@awadoc/whatsapp-cloud-api/next";

const phoneId = process.env.PHONE_ID!;
const bot = createBot(phoneId, process.env.ACCESS_TOKEN!);

export const { GET, POST } = getNextAppRouteHandlers(phoneId, {
  webhookVerifyToken: process.env.WEBHOOK_VERIFY_TOKEN,
});

bot.on("message", (msg) => console.log(msg));

Pages Router

// pages/api/whatsapp/webhook.ts
import { createBot } from "@awadoc/whatsapp-cloud-api";
import { getNextPagesApiHandler } from "@awadoc/whatsapp-cloud-api/next";

const phoneId = process.env.PHONE_ID!;
const bot = createBot(phoneId, process.env.ACCESS_TOKEN!);

export default getNextPagesApiHandler(phoneId, {
  webhookVerifyToken: process.env.WEBHOOK_VERIFY_TOKEN,
});

bot.on("message", (msg) => console.log(msg));

💡 Features

  • ✅ Send & receive all message types: text, image, video, audio, location, templates, buttons.
  • ✅ Drop-in webhook support via Express or Next.js (App Router & Pages Router).
  • ✅ Full TypeScript typing & dev experience.
  • ✅ Custom routing support for integration with existing apps.
  • WhatsApp Flows - Full support for creating, managing, and handling interactive flows.

📱 WhatsApp Flows

This library provides comprehensive support for WhatsApp Flows - interactive, form-based experiences within WhatsApp.

Quick Example

import { createBot } from "@awadoc/whatsapp-cloud-api";
import { createFlowManager, FlowJSON, Screen, TextInput, Footer, CompleteAction } from "@awadoc/whatsapp-cloud-api/flows";

const bot = createBot(phoneId, accessToken);
const flows = createFlowManager(wabaId, accessToken);

// Create and configure a flow
const { id: flowId } = await flows.create({ name: "Feedback Form" });

const flowJson = new FlowJSON()
  .addScreen(
    new Screen("FEEDBACK")
      .setTitle("Share Feedback")
      .addComponent(new TextInput("feedback", "Your feedback"))
      .addComponent(new Footer("Submit", new CompleteAction()))
  );

await flows.updateJson(flowId, flowJson);
await flows.publish(flowId);

// Send the flow to a user
await bot.sendFlow(userPhone, flowId, "Give Feedback", {
  body: "We value your opinion!",
});

// Handle flow completion
bot.on("nfm_reply", (msg) => {
  console.log("Feedback received:", msg.data.response);
});

Flows Documentation


📚 Examples

// Send an image
await bot.sendImage(to, "https://example.com/pic.jpg", {
  caption: "Look at this!",
});

// Send a location
await bot.sendLocation(to, 6.5244, 3.3792, { name: "Lagos, Nigeria" });

// Send a template message
await bot.sendTemplate(to, "hello_world", "en_US");

🔧 Custom Webhook Path or Middleware

You can easily change the webhook route or plug into your existing middleware:

app.use(
  "/custom-whatsapp-hook",
  bot.getExpressRoute({ webhookVerifyToken: "secret_token" }),
);

🧪 Environment Setup (for local testing)

Create a .env file:

FROM_PHONE_NUMBER_ID=""
ACCESS_TOKEN=""
VERSION=""
TO=""
WEBHOOK_VERIFY_TOKEN=""
WEBHOOK_PATH=""

🧪 Testing & Development

Running Tests

To run the test suite, use the following command:

npm test

Running the Demo Server

A demo server is included to help you test the integration locally.

  1. Create a .env file from the template:
    cp .env.template .env
  2. Fill in your WhatsApp Cloud API credentials in .env.
  3. Start the demo server:
    npm run start:demo

🤝 Contributing

Forks, issues, and PRs are welcome.

  • Improve modularity (e.g., router separation)
  • Add support for more message types
  • Improve webhook logic for other frameworks (e.g., Fastify, Hono)

🔗 Links


🧼 License

MIT