Features
- ✅ WhatsApp Instance Management - Create, connect, and manage multiple WhatsApp instances
- ✅ API Key Authentication - Secure API access with key-based authentication
- ✅ QR Code Generation - Generate QR codes for WhatsApp Web authentication
- ✅ Message Management - Send, receive, and manage WhatsApp messages
- ✅ Contact Management - Manage contacts and contact information
- ✅ Webhook Support - Real-time notifications via webhooks
- ✅ WebSocket Support - Real-time updates via WebSocket connections
- ✅ Database Integration - MySQL/MariaDB with Prisma ORM
- ✅ TypeScript - Full TypeScript support with proper type safety
- ✅ Error Handling - Comprehensive error handling and validation
Quick Start
Prerequisites
- Node.js 18+
- MySQL/MariaDB database
- npm or yarn
Installation
- Clone the repository
- Install dependencies:
npm install - Set up environment variables:
cp .env.example .env # Edit .env with your configuration - Set up the database:
npx prisma migrate dev npx prisma db seed - Start the development server:
npm run dev
The API will be available at http://localhost:3000/api/v1
API Endpoints
Authentication
All API endpoints require authentication via the X-API-Key header:
curl -H "X-API-Key: your_api_key_here" http://localhost:3000/api/v1/healthInstance Management
List Instances
GET /api/v1/instancesCreate Instance
POST /api/v1/instances Content-Type: application/json { "name": "My WhatsApp Instance", "sessionId": "unique-session-id" }Connect Instance (Generate QR Code)
POST /api/v1/instances/{instanceId}/connectDisconnect Instance
POST /api/v1/instances/{instanceId}/disconnectMessages
Send Message
POST /api/v1/messages/{instanceId}/send Content-Type: application/json { "to": "1234567890@s.whatsapp.net", "message": "Hello, World!" }Webhooks
Configure webhooks to receive real-time notifications when events occur in your WhatsApp instances.
List Webhooks
GET /api/v1/webhooksCreate Webhook
POST /api/v1/webhooks Content-Type: application/json { "url": "https://your-webhook-endpoint.com", "events": ["message", "qr", "connection"] }Deployment
Docker Deployment (Recommended)
The easiest way to deploy this WhatsApp API is using Docker. A complete Docker setup is provided with MySQL database included.
Requirements
- Docker
- Docker Compose
Steps
- Start the services:
docker-compose up -d - View logs:
docker-compose logs -f whatsapp-api - Apply database migrations:
docker-compose exec whatsapp-api npx prisma migrate deploy - Seed the database:
docker-compose exec whatsapp-api npx prisma db seed
Docker Commands
- Start services:
docker-compose up -d - Stop services:
docker-compose down - View logs:
docker-compose logs -f whatsapp-api - Rebuild services:
docker-compose up -d --build - Remove volumes:
docker-compose down -v