Prerequisites
Before installing WAPI, ensure your environment meets these requirements:
Node.js 20.0.0 or higher is required. WAPI is built with modern JavaScript features and requires a current Node.js version.
Check your Node.js version:
If you need to update Node.js, visit nodejs.org or use a version manager like nvm.
Installing WAPI
Install the package
Choose your preferred package manager and install WAPI: Install QR code library (optional)
If you plan to use QR code authentication, install the qrcode package:npm install qrcode
npm install --save-dev @types/qrcode
The QR code library is only needed if you want to display QR codes in the terminal. For OTP authentication, you don’t need this package.
Install logger (optional)
WAPI includes a default logger, but you can use the recommended logger for better formatting:npm install @imjxsx/logger
Verify installation
Create a simple test file to verify WAPI is installed correctly:import { Bot, LocalAuth } from "@imjxsx/wapi";
console.log("WAPI installed successfully!");
console.log("Bot:", typeof Bot);
console.log("LocalAuth:", typeof LocalAuth);
Run the test:You should see output confirming the imports work:WAPI installed successfully!
Bot: function
LocalAuth: function
Authentication Strategies
WAPI supports multiple authentication backends. Install the dependencies for your chosen strategy:
Local File Storage (Default)
No additional dependencies required. Perfect for development and single-instance deployments.
import { LocalAuth } from "@imjxsx/wapi";
const auth = new LocalAuth(uuid, "sessions");
Redis Storage
For production deployments with multiple instances:
import { RedisAuth } from "@imjxsx/wapi";
import Redis from "ioredis";
const redis = new Redis();
const auth = new RedisAuth(uuid, redis);
MongoDB Storage
For deployments using MongoDB:
import { MongoAuth } from "@imjxsx/wapi";
import { MongoClient } from "mongodb";
const client = await MongoClient.connect("mongodb://localhost:27017");
const auth = new MongoAuth(uuid, client, "myDatabase");
TypeScript Configuration
WAPI is built with TypeScript and includes full type definitions out of the box.
If you’re using TypeScript, ensure your tsconfig.json includes these settings:
{
"compilerOptions": {
"target": "ES2022",
"module": "ESNext",
"moduleResolution": "node",
"esModuleInterop": true,
"strict": true
}
}
Package Manager Notes
Using ESM Modules
WAPI is an ESM-only package. Make sure your package.json includes:
WAPI does not support CommonJS (require()). You must use ES modules (import).
Using with Bun
WAPI works seamlessly with Bun:
bun add @imjxsx/wapi
bun run index.js
Using with tsx (TypeScript)
For running TypeScript files directly during development:
npm install --save-dev tsx
npx tsx index.ts
Next Steps
Quick Start
Build your first WhatsApp bot
Authentication Guide
Learn about authentication strategies
Troubleshooting
Module Not Found Error
If you see ERR_MODULE_NOT_FOUND, ensure:
- Your
package.json has "type": "module"
- You’re using
import instead of require
- File extensions are included in imports (
.js)
Node Version Error
If you encounter compatibility errors, verify you’re using Node.js 20.0.0 or higher:
Update Node.js if needed using nvm:
nvm install 20
nvm use 20