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

townkrier-whapi

v1.0.1-alpha.1

Published

Whapi (WhatsApp) driver for Townkrier

Downloads

99

Readme

townkrier-whapi

WHAPI.cloud WhatsApp adapter for the TownKrier notification system.

Features

  • 📱 WhatsApp Business API integration via WHAPI.cloud
  • 🌍 Support for international messaging
  • 🔄 Automatic retry and error handling
  • 📝 Rich text message support
  • 🔍 Message delivery tracking
  • 🛡️ Type-safe configuration

Installation

npm install townkrier-whapi townkrier-core
# or
pnpm add townkrier-whapi townkrier-core

Quick Start

import { NotificationManager } from 'townkrier-core';
import { createWhapiAdapter, WhapiConfig } from 'townkrier-whapi';

// Configure WHAPI adapter
const whapiConfig: WhapiConfig = {
  apiKey: process.env.WHAPI_API_KEY,
  baseUrl: 'https://gate.whapi.cloud', // Optional, defaults to this URL
};

// Create the adapter
const whapiAdapter = createWhapiAdapter(whapiConfig);

// Use with NotificationManager
const manager = new NotificationManager();

// Send a WhatsApp message
const result = await whapiAdapter.send({
  to: { phone: '+1234567890' },
  text: 'Hello from TownKrier via WHAPI!',
});

console.log('Message sent:', result.messageId);

Configuration

WhapiConfig

interface WhapiConfig extends NotificationChannelConfig {
  apiKey: string; // Required: Your WHAPI API key
  baseUrl?: string; // Optional: API base URL (default: 'https://gate.whapi.cloud')
}

Environment Variables

WHAPI_API_KEY=your_api_key_here

Usage with NotificationManager

import { NotificationManager, NotificationChannel } from 'townkrier-core';
import { createWhapiAdapter } from 'townkrier-whapi';

const manager = new NotificationManager({
  defaultChannel: 'whatsapp-whapi',
  channels: [
    {
      name: 'whatsapp-whapi',
      enabled: true,
      config: {
        apiKey: process.env.WHAPI_API_KEY,
        baseUrl: 'https://gate.whapi.cloud',
      },
    },
  ],
});

// Register the factory
manager.registerFactory('whatsapp-whapi', createWhapiAdapter);

// Send notification
await manager.send({
  channel: 'whatsapp-whapi',
  to: { phone: '+1234567890' },
  text: 'Welcome to our service!',
});

Error Handling

The adapter handles various error scenarios:

  • Authentication errors: Invalid API key
  • Rate limiting: Automatic retry with backoff
  • Network issues: Timeout and connection errors
  • Invalid recipients: Phone number validation
  • API-specific errors: WHAPI error responses
try {
  const result = await whapiAdapter.send({
    to: { phone: '+1234567890' },
    text: 'Test message',
  });

  if (result.status === 'FAILED') {
    console.error('Message failed to send');
  }
} catch (error) {
  console.error('Adapter error:', error);
}

API Reference

createWhapiAdapter(config)

Factory function to create a WHAPI adapter instance.

Parameters:

  • config (WhapiConfig): Configuration object

Returns: WhapiAdapter instance

WhapiAdapter

send(request)

Send a WhatsApp message.

Parameters:

  • request (WhatsAppRequest): Message request object

Returns: Promise<WhatsAppResponse>

Rate Limits

Be aware of WHAPI.cloud's rate limits:

  • Messages per minute: Varies by plan
  • Messages per hour: Varies by plan
  • Messages per day: Varies by plan

The adapter does not implement rate limiting - consider using TownKrier's queue system for production use.

WHAPI Response Format

WHAPI returns messages in this format:

{
  "sent": true,
  "message": {
    "id": "message_id_here",
    "message_id": "alternative_id"
  }
}

The adapter extracts the message ID from either message.id or message.message_id fields.

Error Response Handling

WHAPI error responses include detailed error information:

{
  "error": {
    "code": 400,
    "message": "Invalid phone number",
    "details": "Phone number must be in international format",
    "href": "https://docs.whapi.cloud/errors",
    "support": "[email protected]"
  }
}

The adapter logs these errors and returns a failed status.

Support

For issues specific to the WHAPI adapter:

  1. Check your API key and configuration
  2. Verify phone numbers are in international format
  3. Review WHAPI.cloud API documentation
  4. Check TownKrier logs for detailed error messages

License

MIT