Skip to main content

What is WAPI?

WAPI is a powerful framework for building WhatsApp bots with TypeScript/JavaScript. Built on top of Baileys, WAPI provides a clean, intuitive API that makes bot development fast and enjoyable.

Fast Development

Get your bot running in minutes with an intuitive API and minimal boilerplate

Type-Safe

Built 100% in TypeScript with full type definitions for a better developer experience

Production Ready

Multiple authentication strategies including Local, Redis, and MongoDB

Feature Rich

Middleware system, command handling, context API, and rich message utilities

Key Features

Middleware System

WAPI includes a powerful middleware system similar to Express.js, allowing you to intercept and process messages before they reach command handlers:
bot.use(async (ctx, next) => {
  bot.logger.info(`New message from '${ctx.from.name}' in '${ctx.chat.name}'`);
  await next();
});

Command Handling

Define commands with a simple, declarative API. Commands support custom prefixes (/ and ! by default) and provide full access to message context:
bot.command("ping", async (ctx) => {
  await ctx.reply(`> ¡Pong! \`\`\`${bot.ping.toFixed(2)} ms\`\`\``);
});

Rich Context API

Every message comes with a rich context object providing:
  • Message details: Text content, media, quoted messages
  • Sender information: Name, phone number, JID
  • Chat information: Group or private chat details
  • Utility methods: reply(), replyWithImage(), replyWithVideo(), and more
  • Parsed data: Links, mentions, command arguments

Multiple Authentication Strategies

WAPI supports flexible authentication backends to suit your infrastructure:
import { Bot, LocalAuth } from "@imjxsx/wapi";

const auth = new LocalAuth(uuid, "sessions");
const bot = new Bot(uuid, auth, account);

Flexible Login Methods

Choose between QR code or OTP (One-Time Password) authentication:
// QR Code login (scan with WhatsApp)
await bot.login("qr");

// OTP login (phone number required)
await bot.login("otp");

Why Choose WAPI?

WAPI abstracts away the complexity of WhatsApp’s protocol while giving you full control over your bot’s behavior.
  • Developer Experience First: Clean API, full TypeScript support, comprehensive error handling
  • Battle Tested: Built on Baileys, the most reliable WhatsApp Web API library
  • Scalable: Support for Redis and MongoDB means you can scale horizontally
  • Active Development: Regular updates and compatibility with the latest WhatsApp features

Quick Example

Here’s a complete bot in just a few lines:
import { Bot, LocalAuth } from "@imjxsx/wapi";
import QRCode from "qrcode";

const uuid = "1f1332f4-7c2a-4b88-b4ca-bd56d07ed713";
const auth = new LocalAuth(uuid, "sessions");
const bot = new Bot(uuid, auth, { jid: "", pn: "", name: "" });

bot.on("qr", async (qr) => {
  qr = await QRCode.toString(qr, { type: "terminal", small: true });
  console.log(qr);
});

bot.on("open", (account) => {
  bot.logger.info(`Logged in as @${account.name}`);
});

bot.command("ping", async (ctx) => {
  await ctx.reply(`Pong! ${bot.ping.toFixed(2)} ms`);
});

await bot.login("qr");

What’s Next?

Installation

Install WAPI and set up your development environment

Quick Start

Build your first WhatsApp bot in under 5 minutes

Build docs developers (and LLMs) love