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

@wayofmono/whatsapp

v1.0.2

Published

WayOfMono first-party WhatsApp SDK package.

Readme

@wayofmono/whatsapp

This package provides a first-party TypeScript SDK for interacting with the WhatsApp Cloud API. It aims to integrate WhatsApp functionality within the WayOfMono ecosystem.

Features

  • WhatsApp Cloud API Client: Provides a WhatsAppBot class to interact with the WhatsApp Cloud API.
  • Token and Phone Number ID Validation: setupWhatsAppBot(token, phoneNumberId) function to validate bot tokens and phone number IDs.
  • Message Sending: sendMessage method for sending text messages.
  • Webhook Integration: onMessage and handleIncomingWebhook for receiving and processing updates via webhooks.

Installation

pnpm add @wayofmono/whatsapp
# or
npm install @wayofmono/whatsapp
# or
yarn add @wayofmono/whatsapp

Usage

import { setupWhatsAppBot } from '@wayofmono/whatsapp';

async function main() {
  const token = process.env.WHATSAPP_BOT_TOKEN;
  const phoneNumberId = process.env.WHATSAPP_PHONE_NUMBER_ID;

  if (!token || !phoneNumberId) {
    console.error('WHATSAPP_BOT_TOKEN and WHATSAPP_PHONE_NUMBER_ID environment variables must be set.');
    process.exit(1);
  }

  try {
    const { bot, botInfo } = await setupWhatsAppBot(token, phoneNumberId);
    console.log(`WhatsApp Bot connected: ${botInfo.name} (ID: ${botInfo.id})`);

    // Example: Send a message
    // Note: The 'to' field should be a valid WhatsApp ID (phone number with country code).
    // await bot.sendMessage('<RECIPIENT_WHATSAPP_ID>', 'Hello from WayOfMono WhatsApp Bot!');

    // Example: Registering an incoming message handler (for webhook processing)
    // This handler would typically be called by an external HTTP server receiving WhatsApp webhooks.
    // bot.onMessage(async (payload) => {
    //   console.log('Received WhatsApp webhook payload:', JSON.stringify(payload, null, 2));
    //   // Process the payload and extract messages
    //   // Example: Extracting text messages
    //   payload.entry.forEach(entry => {
    //     entry.changes.forEach(change => {
    //       if (change.field === 'messages' && change.value.messages) {
    //         change.value.messages.forEach(message => {
    //           if (message.type === 'text' && message.text) {
    //             console.log(`Received text message from ${message.from}: ${message.text.body}`);
    //             // You can reply here, e.g., bot.sendMessage(message.from, `You said: ${message.text.body}`);
    //           }
    //         });
    //       }
    //     });
    //   });
    // });

    // In a real application, you would set up an HTTP server to receive webhooks
    // and then call `bot.handleIncomingWebhook(webhookPayload)` when a payload arrives.

  } catch (error) {
    console.error('Failed to set up WhatsApp Bot:', error);
  }
}

main();

API

setupWhatsAppBot(token: string, phoneNumberId: string): Promise<{ bot: WhatsAppBot; botInfo: WhatsAppBotInfo }>

Validates the provided bot token and phone number ID, then returns a WhatsAppBot instance along with WhatsAppBotInfo.

class WhatsAppBot

constructor(token: string, phoneNumberId: string)

Initializes the WhatsAppBot instance with the provided token and phone number ID.

async getMe(): Promise<WhatsAppBotInfo>

Returns basic information about the WhatsApp Business Account associated with the phoneNumberId.

async sendMessage(to: string, text: string): Promise<WhatsAppMessageResponse>

Sends a text message to a specified WhatsApp ID.

onMessage(handler: (message: WhatsAppIncomingMessage) => Promise<void>): void

Registers a handler function to be called when incoming WhatsApp messages are processed via handleIncomingWebhook. This method does not set up a webhook itself.

async handleIncomingWebhook(payload: WhatsAppIncomingMessage): Promise<void>

Processes an incoming webhook payload from WhatsApp, typically called by an external HTTP server. If a handler is registered with onMessage, it will be invoked.

Contributing

Please refer to the main repository's contributing guidelines.