A RESTful API service that allows external applications to send WhatsApp messages via HTTP requests.
Features:
- ✅ UUID token-based authentication
- ✅ Automatic token generation and persistence
- ✅ Health check endpoint
- ✅ Send messages to phone numbers or chat IDs
- ✅ Get WhatsApp client information
- ✅ Comprehensive error handling
The API server is automatically started when the bot becomes ready and has access to the WhatsApp client.
Complete API documentation with:
- Endpoint descriptions
- Authentication methods
- Usage examples (cURL, JavaScript, Python)
- Error responses
- Security best practices
npm install express body-parser uuid
npm install --save-dev @types/express @types/uuidnpm run build# Development
npm run watch
# Production with PM2
npm run pm2- Default: 3000
- Configure: Set
API_PORTenvironment variable
- Location:
data/api-token.json - Auto-generated: On first startup
- Security: Stored in gitignored
data/folder
Method 1 - Console Logs: When the bot starts, the token is displayed:
📝 API Token: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
Method 2 - Check File:
cat data/api-token.jsoncurl http://localhost:3000/healthcurl -X POST http://localhost:3000/api/send \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"message": "Hello from API!",
"number": "YOUR_NUMBER"
}'curl http://localhost:3000/api/info \
-H "Authorization: Bearer YOUR_TOKEN"| Method | Endpoint | Auth | Description |
|---|---|---|---|
| GET | /health |
No | Health check |
| GET | /api/token/info |
No | Token information |
| POST | /api/send |
Yes | Send WhatsApp message |
| GET | /api/info |
Yes | Get client information |
- UUID Token: Unique, randomly generated authentication token
- Multiple Auth Methods: Header, body, or query parameter
- Token Persistence: Saved securely in
data/folder - Gitignore Protected: Token file excluded from version control
- Request Validation: Validates all required fields
const axios = require('axios');
async function sendWhatsAppMessage(number, message) {
const response = await axios.post('http://localhost:3000/api/send', {
message,
number
}, {
headers: {
'Authorization': 'Bearer YOUR_TOKEN'
}
});
return response.data;
}import requests
def send_whatsapp_message(number, message):
response = requests.post('http://localhost:3000/api/send',
json={'message': message, 'number': number},
headers={'Authorization': 'Bearer YOUR_TOKEN'}
)
return response.json()server {
listen 80;
server_name your-domain.com;
location / {
proxy_pass http://localhost:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}Use Let's Encrypt or similar for SSL/TLS:
certbot --nginx -d your-domain.com- Check if port 3000 is available
- Verify dependencies are installed
- Check logs for errors
- Verify token from
data/api-token.json - Check Authorization header format:
Bearer TOKEN - Ensure no extra spaces in token
- Verify WhatsApp client is connected
- Check
/api/infoendpoint for client status - Verify number format (country code + number)
WA-Bot/
├── src/
│ ├── api/
│ │ └── server.ts # API server implementation
│ ├── commands/
│ ├── utils/
│ └── index.ts # Main bot entry (integrated with API)
├── data/
│ └── api-token.json # Auto-generated token (gitignored)
└── API_DOCUMENTATION.md # Complete API documentation
- Install Dependencies: Run
npm install - Build: Run
npm run build - Start Bot: Run
npm run pm2ornpm run watch - Get Token: Check console logs or
data/api-token.json - Test API: Use cURL examples from documentation
- Integrate: Use the API in your applications
For detailed API documentation, see API_DOCUMENTATION.md
For bot commands and features, see README.md