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

business-whatsapp-api

v1.0.0

Published

TypeScript SDK for WhatsApp Cloud API with ESM & CommonJS support

Downloads

12

Readme

business-whatsapp-api

TypeScript SDK for WhatsApp Cloud API with full ESM & CommonJS support.

Features

  • Full TypeScript support with type definitions
  • ESM and CommonJS compatibility
  • Fluent API for building messages, templates, and flows
  • Comprehensive validation
  • Webhook handling
  • Full async support
  • Error handling with custom error classes
  • Modular structure for selective imports
  • Media upload and management
  • Business account management
  • Interactive flows support
  • Call handling
  • User preferences management

Installation

npm install business-whatsapp-api

API Version

By default this package uses facebook graph api of version v23.0 , you can update it in your app environment variable.

process.env.FB_GRAPH_API_VERSION = <latest_version>

QuickStart

// ESM
import { WhatsAppClient } from 'business-whatsapp-api';
import { text } from 'business-whatsapp-api/messages';
import { template } from 'business-whatsapp-api/templates';

// CommonJS
const { WhatsAppClient } = require('business-whatsapp-api');
const { text } = require('business-whatsapp-api/messages');
const { template } = require('business-whatsapp-api/templates');

const client = new WhatsAppClient('phone_number_id', 'access_token');

// Send a text message
const message = text()
  .to('1234567890')
  .body('Hello, World!')
  .build();

await client.sendMessage(message);

// Send a template
const templateMessage = template()
  .name('shipping_confirmation')
  .language('en_US')
  .addBody([parameter().text('Your order has been shipped!').build()])
  .build();

await client.sendTemplate(templateMessage);

Module Structure

The package is organized into modules for better organization:

  • client: Core client functionality
  • messages: Message types and builders
  • templates: Template functionality
  • flows: Interactive flows
  • filters: Message filtering
  • handlers: Event handlers
  • listeners: Async listeners
  • utils: Utility functions
  • types: Type definitions

Selective Imports

// Import only what you need
import { WhatsAppClient } from 'business-whatsapp-api/client';
import { TextMessageBuilder, ImageMessageBuilder } from 'business-whatsapp-api/messages';
import { TemplateBuilder } from 'business-whatsapp-api/templates';
import { FlowBuilder } from 'business-whatsapp-api/flows';
import { MessageFilterComposer } from 'business-whatsapp-api/filters';
import { isValidPhoneNumber } from 'business-whatsapp-api/utils';

The Following code snippets would come in handy for quick start and better understanding of the package.

const client = new WhatsAppClient('phone_number_id', 'access_token');
const textMessage = text().to('1234567890')
                    .body('Hello, World!')
                    .build();

await client.sendMessage(textMessage);

const imageMessage = image().to('1234567890')
            .link('https://example.com/image.jpg')
            .caption('Check this image')
            .build();

await client.sendMessage(imageMessage);
const templateMessage = template()
  .name('shipping_confirmation')
  .language('en_US')
  .addBody([parameter().text('Your order has been shipped!').build()])
  .build();

await client.sendTemplate(templateMessage);
// Set up webhook handlers
client.onMessage((message) => {
  console.log('Received message:', message);
});

client.onMessageStatus((status) => {
  console.log('Message status:', status);
});

// Handle webhook requests (Express example)
app.get('/webhook', (req, res) => {
  const mode = req.query['hub.mode'];
  const token = req.query['hub.verify_token'];
  const challenge = req.query['hub.challenge'];
  
  if (mode && token) {
    if (mode === 'subscribe' && token === process.env.WEBHOOK_VERIFY_TOKEN) {
      res.status(200).send(challenge);
    } else {
      res.status(403).send('Forbidden');
    }
  }
});

app.post('/webhook', (req, res) => {
  client.handleWebhook(req, res);
});
import { filter } from 'business-whatsapp-api/filters';

const filterObj = filter()
  .since('2023-01-01')
  .limit(10)
  .build();

const messages = await client.getMessages(filterObj);
import { onMessage } from 'business-whatsapp-api/handlers';

async handleMessage(message: any) {
  console.log('Received message:', message.text);
}

onMessage(handleMessage)
import { waitForReply } from 'business-whatsapp-api/listeners';

// Wait for a reply to a message
const reply = await waitForReply(message, { timeout: 30000 });
console.log('Received reply:', reply.text);