Production-ready API for sending OTP messages via WhatsApp Web protocol with multilingual support
- Persistent WhatsApp Sessions - Automatic session restore using Baileys
- QR Code Generation - Simple web interface for WhatsApp Web connection
- Auth State Management - SQLite database with Drizzle ORM for reliable session storage
- Smart Number Formatting - Automatic international format conversion
- Reliable Message Delivery - Robust error handling with fallback mechanisms
- Template Customization - Configurable OTP message templates
- Multi-language Support - Indonesian and English localization
- Runtime Language Switching - Dynamic locale configuration per request
- Extensible Translation System - Easy addition of new languages
- Modern Dark Theme - Next.js-inspired professional design
- Real-time Status - Live connection status and message statistics
- Responsive Design - Mobile-friendly admin panel
- Full TypeScript Coverage - End-to-end type safety
- Zod Schema Validation - Runtime request validation
- Error Boundaries - Comprehensive error handling
- Bun >= 1.2.0
- Node.js >= 18.0.0 (for compatibility)
- SQLite (included with Bun)
# Clone the repository
git clone https://github.com/idMJA/WApi.git
cd WApi
# Install dependencies
bun install
# Start the server
bun run start-
Start the service:
bun run start
-
Connect WhatsApp:
- Open
http://localhost:3000/admin.html - Scan the QR code with WhatsApp on your phone
- Wait for connection confirmation
- Open
-
Test the API:
curl -X POST http://localhost:3000/send-otp \ -H "Content-Type: application/json" \ -d '{ "phoneNumber": "+6281234567890", "otp": "123456", "websiteName": "MyApp", "locale": "id" }'
http://localhost:3000
Generate QR code for WhatsApp Web connection.
Response:
{
"success": true,
"qr": "data:image/png;base64,..."
}Check WhatsApp connection status.
Response:
{
"success": true,
"status": "connected",
"phoneNumber": "+6281234567890"
}Send OTP message via WhatsApp.
Request Body:
{
"phoneNumber": "+6281234567890",
"otp": "123456",
"websiteName": "MyApp",
"locale": "id"
}Response:
{
"success": true,
"message": "OTP sent successfully"
}Parameters:
phoneNumber(string, required) - Target phone number in international formatotp(string, required) - OTP code to sendwebsiteName(string, optional) - Name of your applicationlocale(string, optional) - Language locale (idoren, defaults toid)
Get all available locales.
Response:
{
"success": true,
"locales": ["id", "en"]
}Get translations for specific locale.
Response:
{
"success": true,
"translations": {
"otpMessage": "Kode OTP Anda untuk {websiteName} adalah: {otp}. Kode ini berlaku selama 5 menit.",
"defaultWebsiteName": "Aplikasi Kami"
}
}Create a .env file in the root directory:
# Server Configuration
PORT=3000
NODE_ENV=production
# Database
DATABASE_URL=./auth_info_baileys/auth.db
# Localization
DEFAULT_LOCALE=id
# WhatsApp Configuration
WHATSAPP_SESSION_PATH=./auth_info_baileysTo add a new language:
-
Create a new language file in
src/locales/languages/:// src/locales/languages/fr.ts export const fr = { otpMessage: "Votre code OTP pour {websiteName} est: {otp}. Ce code expire dans 5 minutes.", defaultWebsiteName: "Notre Application" };
-
Update the locale types:
// src/locales/types.ts export type Locale = 'id' | 'en' | 'fr';
-
Register the language:
// src/locales/languages/index.ts export { fr } from './fr';
βββ src/
β βββ config/ # Configuration management
β βββ controllers/ # Request handlers
β βββ db/ # Database and auth state
β βββ locales/ # Internationalization
β βββ routes/ # API route definitions
β βββ services/ # Business logic
β βββ types/ # TypeScript types and schemas
β βββ utils/ # Helper utilities
βββ auth_info_baileys/ # WhatsApp session storage
βββ admin.html # Admin panel interface
βββ test.html # Testing interface
- Runtime: Bun for high-performance JavaScript/TypeScript execution
- Framework: ElysiaJS for modern web API development
- Database: SQLite with Drizzle ORM for type-safe database operations
- WhatsApp: Baileys for WhatsApp Web protocol implementation
- Validation: Zod for runtime type checking and validation
- UI: Vanilla HTML/CSS/JS with modern design principles
# Development server with hot reload
bun run dev
# Production build
bun run build
# Start production server
bun run start
# Clean restart (clears auth data)
bun run start:clean
# Run tests
bun run test
# API testing
bun run test:api- Make changes to source files
- Test locally using the admin panel
- Validate with the test API script
- Build for production deployment
Enable debug logs:
DEBUG=baileys:* bun run startCheck connection status:
curl http://localhost:3000/status-
Build the application:
bun run build
-
Set environment variables:
export NODE_ENV=production export PORT=3000
-
Start the service:
bun run start
FROM oven/bun:1-alpine
WORKDIR /app
COPY package.json bun.lockb ./
RUN bun install --frozen-lockfile
COPY . .
RUN bun run build
EXPOSE 3000
CMD ["bun", "run", "start"]Using PM2:
pm2 start ecosystem.config.js// ecosystem.config.js
module.exports = {
apps: [{
name: 'whatsapp-otp-api',
script: 'bun',
args: 'run start',
instances: 1,
autorestart: true,
watch: false,
max_memory_restart: '1G',
env: {
NODE_ENV: 'production',
PORT: 3000
}
}]
}- Keep WhatsApp session files secure
- Regularly rotate session data
- Monitor for unauthorized access
- Implement rate limiting for production use
- Add API key authentication
- Validate all input parameters
- Encrypt sensitive configuration
- Use HTTPS in production
- Regular security audits
We welcome contributions! Please see src/locales/TRANSLATIONS.md for translation contributions.
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
- Follow TypeScript best practices
- Use meaningful variable names
- Add comments for complex logic
- Format with Prettier
This project is licensed under the MIT License - see the LICENSE file for details.
Connection Problems:
- Ensure WhatsApp Web is not open in other browsers
- Clear auth data and reconnect
- Check network connectivity
Message Delivery:
- Verify phone number format
- Check WhatsApp connection status
- Review error logs
Localization Issues:
- Verify locale parameter format
- Check available locales endpoint
- Validate translation files
- π Check the documentation
- π Report bugs via GitHub Issues
- π‘ Request features via GitHub Discussions
- π§ Contact support for urgent issues
Made with β€οΈ for modern web applications
Back to Top β’ Bahasa Indonesia β’ Contribute Translations