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

whatsapp-business-serverless

v1.1.1

Published

Connector for the WhatsApp Business APIs with TypeScript support. Serverless version.

Readme

WhatsApp Business SDK - Cloudflare Workers Compatible

This is a modified version of the WhatsApp Business SDK that has been optimized for Cloudflare Workers compatibility by removing Node.js-specific dependencies.

Changes Made

Removed Dependencies

  • Express.js - Removed webhook server functionality (Express-based)
  • form-data - Replaced with native Web API FormData
  • fs (File System) - Removed file system operations
  • axios - Replaced with native fetch API

Modified Components

1. REST Client (src/utils/restClient.ts)

  • Replaced axios with native fetch API
  • Added proper error handling for Workers environment
  • Supports FormData uploads using Web APIs

2. WABA Client (src/WABA_client.ts)

  • File Upload: Now accepts File or Blob objects instead of file paths
  • Media Download: Returns ArrayBuffer instead of writing to file system
  • Added deprecated methods with helpful error messages for Node.js-specific functionality

3. Webhook Functionality

  • Removed: All Express.js-based webhook handlers
  • Reason: Not needed for client-only usage in Workers

Usage in Cloudflare Workers

Basic Setup

import { WABAClient } from 'whatsapp-business';

export default {
  async fetch(request: Request, env: any): Promise<Response> {
    const client = new WABAClient({
      apiToken: env.WHATSAPP_API_TOKEN,
      phoneId: env.WHATSAPP_PHONE_ID,
      accountId: env.WHATSAPP_ACCOUNT_ID,
    });

    // Your logic here
  }
};

Sending Messages

// Send text message
const response = await client.sendMessage({
  to: "1234567890",
  type: "text",
  text: {
    body: "Hello from Cloudflare Workers!"
  }
});

File Upload (Changed API)

Before (Node.js):

// ❌ This won't work in Workers
await client.uploadMedia({
  file: "/path/to/file.jpg",
  type: "image"
});

After (Workers Compatible):

// ✅ Use File or Blob objects
const formData = await request.formData();
const file = formData.get('file') as File;

await client.uploadMedia({
  file: file, // File object from FormData
  type: "image"
});

Media Download (Changed API)

Before (Node.js):

// ❌ This won't work in Workers
await client.downloadMedia(mediaUrl, "/path/to/save/file.jpg");

After (Workers Compatible):

// ✅ Returns ArrayBuffer
const mediaBuffer = await client.downloadMedia(mediaUrl);

// Return as response or process as needed
return new Response(mediaBuffer, {
  headers: {
    'Content-Type': 'application/octet-stream'
  }
});

Environment Variables

Set these in your wrangler.toml:

[vars]
WHATSAPP_API_TOKEN = "your_api_token"
WHATSAPP_PHONE_ID = "your_phone_id"
WHATSAPP_ACCOUNT_ID = "your_account_id"

Available Methods

All WhatsApp Business API methods are available:

Business Profile

  • getBusinessProfile()
  • updateBusinessProfile()

Messages

  • sendMessage() - Send any type of message
  • markMessageAsRead()

Media

  • uploadMedia() - Upload media (File/Blob)
  • getMedia() - Get media URL
  • deleteMedia() - Delete media
  • downloadMedia() - Download as ArrayBuffer

Phone Numbers

  • getBusinessPhoneNumbers()
  • getSingleBusinessPhoneNumber()
  • updateIdentityCheckState()
  • requestPhoneNumberVerificationCode()
  • verifyPhoneNumberCode()
  • registerPhone()
  • deregisterPhone()
  • setupTwoStepAuth()

Health

  • getHealthStatus()

Migration Notes

If you're migrating from the original SDK:

  1. File Uploads: Change from file paths to File/Blob objects
  2. Media Downloads: Handle ArrayBuffer instead of file writes
  3. Webhooks: Implement your own webhook handling in Workers if needed
  4. Error Handling: Errors now use standard fetch error patterns

Example Worker

See examples/cloudflare-worker-example.ts for a complete working example.

Compatibility

  • ✅ Cloudflare Workers
  • ✅ Web browsers
  • ✅ Deno
  • ✅ Modern Node.js (with polyfills)
  • ❌ Legacy Node.js environments (use original SDK)