{"id":30232412,"url":"https://github.com/idmja/wapi","last_synced_at":"2025-08-15T00:00:49.427Z","repository":{"id":307287648,"uuid":"1027898579","full_name":"idMJA/WApi","owner":"idMJA","description":"🔐 Modern WhatsApp OTP API built with Bun, TypeScript, and Baileys. Features persistent sessions, multi-language support, real-time admin panel, and robust message delivery with SQLite + Drizzle ORM storage.","archived":false,"fork":false,"pushed_at":"2025-07-30T11:32:11.000Z","size":41,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-08-11T20:47:23.040Z","etag":null,"topics":["api","authentication","baileys","bun","drizzle-orm","multi-language","sms-alternative","typescript","whatsapp"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/idMJA.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-07-28T17:45:12.000Z","updated_at":"2025-07-31T03:41:30.000Z","dependencies_parsed_at":"2025-07-30T14:02:55.227Z","dependency_job_id":"9606331a-4a65-44dd-b874-28c78a038835","html_url":"https://github.com/idMJA/WApi","commit_stats":null,"previous_names":["idmja/wapi"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/idMJA/WApi","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/idMJA%2FWApi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/idMJA%2FWApi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/idMJA%2FWApi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/idMJA%2FWApi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/idMJA","download_url":"https://codeload.github.com/idMJA/WApi/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/idMJA%2FWApi/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270500676,"owners_count":24595163,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-14T02:00:10.309Z","response_time":75,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","authentication","baileys","bun","drizzle-orm","multi-language","sms-alternative","typescript","whatsapp"],"created_at":"2025-08-15T00:00:46.136Z","updated_at":"2025-08-15T00:00:49.342Z","avatar_url":"https://github.com/idMJA.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# WhatsApp OTP API\n\n\u003cdiv align=\"center\"\u003e\n  \u003ch3\u003e🚀 Modern WhatsApp OTP Service with Baileys Integration\u003c/h3\u003e\n  \u003cp\u003eProduction-ready API for sending OTP messages via WhatsApp Web protocol with multilingual support\u003c/p\u003e\n  \n  ![TypeScript](https://img.shields.io/badge/TypeScript-007ACC?style=for-the-badge\u0026logo=typescript\u0026logoColor=white)\n  ![Bun](https://img.shields.io/badge/Bun-000000?style=for-the-badge\u0026logo=bun\u0026logoColor=white)\n  ![ElysiaJS](https://img.shields.io/badge/ElysiaJS-8B5CF6?style=for-the-badge\u0026logo=elysia\u0026logoColor=white)\n  ![WhatsApp](https://img.shields.io/badge/WhatsApp-25D366?style=for-the-badge\u0026logo=whatsapp\u0026logoColor=white)\n\u003c/div\u003e\n\n---\n\n## ✨ Features\n\n### 🔐 Authentication \u0026 Session Management\n- **Persistent WhatsApp Sessions** - Automatic session restore using Baileys\n- **QR Code Generation** - Simple web interface for WhatsApp Web connection\n- **Auth State Management** - SQLite database with Drizzle ORM for reliable session storage\n\n### 📱 OTP Delivery System\n- **Smart Number Formatting** - Automatic international format conversion\n- **Reliable Message Delivery** - Robust error handling with fallback mechanisms\n- **Template Customization** - Configurable OTP message templates\n\n### 🌍 Internationalization\n- **Multi-language Support** - Indonesian and English localization\n- **Runtime Language Switching** - Dynamic locale configuration per request\n- **Extensible Translation System** - Easy addition of new languages\n\n### 🎨 Admin Interface\n- **Modern Dark Theme** - Next.js-inspired professional design\n- **Real-time Status** - Live connection status and message statistics\n- **Responsive Design** - Mobile-friendly admin panel\n\n### 🛡️ Type Safety \u0026 Validation\n- **Full TypeScript Coverage** - End-to-end type safety\n- **Zod Schema Validation** - Runtime request validation\n- **Error Boundaries** - Comprehensive error handling\n\n---\n\n## 🚀 Quick Start\n\n### Prerequisites\n- **Bun** \u003e= 1.2.0\n- **Node.js** \u003e= 18.0.0 (for compatibility)\n- **SQLite** (included with Bun)\n\n### Installation\n\n```bash\n# Clone the repository\ngit clone https://github.com/idMJA/WApi.git\ncd WApi\n\n# Install dependencies\nbun install\n\n# Start the server\nbun run start\n```\n\n### First Setup\n\n1. **Start the service**:\n   ```bash\n   bun run start\n   ```\n\n2. **Connect WhatsApp**:\n   - Open `http://localhost:3000/admin.html`\n   - Scan the QR code with WhatsApp on your phone\n   - Wait for connection confirmation\n\n3. **Test the API**:\n   ```bash\n   curl -X POST http://localhost:3000/send-otp \\\n     -H \"Content-Type: application/json\" \\\n     -d '{\n       \"phoneNumber\": \"+6281234567890\",\n       \"otp\": \"123456\",\n       \"websiteName\": \"MyApp\",\n       \"locale\": \"id\"\n     }'\n   ```\n\n---\n\n## 📖 API Documentation\n\n### Base URL\n```\nhttp://localhost:3000\n```\n\n### Endpoints\n\n#### 🔐 Authentication\n\n##### `GET /qr`\nGenerate QR code for WhatsApp Web connection.\n\n**Response:**\n```json\n{\n  \"success\": true,\n  \"qr\": \"data:image/png;base64,...\"\n}\n```\n\n##### `GET /status`\nCheck WhatsApp connection status.\n\n**Response:**\n```json\n{\n  \"success\": true,\n  \"status\": \"connected\",\n  \"phoneNumber\": \"+6281234567890\"\n}\n```\n\n#### 📱 OTP Services\n\n##### `POST /send-otp`\nSend OTP message via WhatsApp.\n\n**Request Body:**\n```json\n{\n  \"phoneNumber\": \"+6281234567890\",\n  \"otp\": \"123456\",\n  \"websiteName\": \"MyApp\",\n  \"locale\": \"id\"\n}\n```\n\n**Response:**\n```json\n{\n  \"success\": true,\n  \"message\": \"OTP sent successfully\"\n}\n```\n\n**Parameters:**\n- `phoneNumber` (string, required) - Target phone number in international format\n- `otp` (string, required) - OTP code to send\n- `websiteName` (string, optional) - Name of your application\n- `locale` (string, optional) - Language locale (`id` or `en`, defaults to `id`)\n\n#### 🌍 Localization\n\n##### `GET /locales`\nGet all available locales.\n\n**Response:**\n```json\n{\n  \"success\": true,\n  \"locales\": [\"id\", \"en\"]\n}\n```\n\n##### `GET /locales/:locale`\nGet translations for specific locale.\n\n**Response:**\n```json\n{\n  \"success\": true,\n  \"translations\": {\n    \"otpMessage\": \"Kode OTP Anda untuk {websiteName} adalah: {otp}. Kode ini berlaku selama 5 menit.\",\n    \"defaultWebsiteName\": \"Aplikasi Kami\"\n  }\n}\n```\n\n---\n\n## 🛠️ Configuration\n\n### Environment Variables\n\nCreate a `.env` file in the root directory:\n\n```env\n# Server Configuration\nPORT=3000\nNODE_ENV=production\n\n# Database\nDATABASE_URL=./auth_info_baileys/auth.db\n\n# Localization\nDEFAULT_LOCALE=id\n\n# WhatsApp Configuration\nWHATSAPP_SESSION_PATH=./auth_info_baileys\n```\n\n### Custom Localization\n\nTo add a new language:\n\n1. Create a new language file in `src/locales/languages/`:\n   ```typescript\n   // src/locales/languages/fr.ts\n   export const fr = {\n     otpMessage: \"Votre code OTP pour {websiteName} est: {otp}. Ce code expire dans 5 minutes.\",\n     defaultWebsiteName: \"Notre Application\"\n   };\n   ```\n\n2. Update the locale types:\n   ```typescript\n   // src/locales/types.ts\n   export type Locale = 'id' | 'en' | 'fr';\n   ```\n\n3. Register the language:\n   ```typescript\n   // src/locales/languages/index.ts\n   export { fr } from './fr';\n   ```\n\n---\n\n## 🏗️ Architecture\n\n### Project Structure\n```\n├── src/\n│   ├── config/          # Configuration management\n│   ├── controllers/     # Request handlers\n│   ├── db/             # Database and auth state\n│   ├── locales/        # Internationalization\n│   ├── routes/         # API route definitions\n│   ├── services/       # Business logic\n│   ├── types/          # TypeScript types and schemas\n│   └── utils/          # Helper utilities\n├── auth_info_baileys/  # WhatsApp session storage\n├── admin.html          # Admin panel interface\n└── test.html          # Testing interface\n```\n\n### Tech Stack\n\n- **Runtime**: Bun for high-performance JavaScript/TypeScript execution\n- **Framework**: ElysiaJS for modern web API development\n- **Database**: SQLite with Drizzle ORM for type-safe database operations\n- **WhatsApp**: Baileys for WhatsApp Web protocol implementation\n- **Validation**: Zod for runtime type checking and validation\n- **UI**: Vanilla HTML/CSS/JS with modern design principles\n\n---\n\n## 🔧 Development\n\n### Scripts\n\n```bash\n# Development server with hot reload\nbun run dev\n\n# Production build\nbun run build\n\n# Start production server\nbun run start\n\n# Clean restart (clears auth data)\nbun run start:clean\n\n# Run tests\nbun run test\n\n# API testing\nbun run test:api\n```\n\n### Development Workflow\n\n1. **Make changes** to source files\n2. **Test locally** using the admin panel\n3. **Validate** with the test API script\n4. **Build** for production deployment\n\n### Debugging\n\nEnable debug logs:\n```bash\nDEBUG=baileys:* bun run start\n```\n\nCheck connection status:\n```bash\ncurl http://localhost:3000/status\n```\n\n---\n\n## 🚀 Deployment\n\n### Production Deployment\n\n1. **Build the application**:\n   ```bash\n   bun run build\n   ```\n\n2. **Set environment variables**:\n   ```bash\n   export NODE_ENV=production\n   export PORT=3000\n   ```\n\n3. **Start the service**:\n   ```bash\n   bun run start\n   ```\n\n### Docker Deployment\n\n```dockerfile\nFROM oven/bun:1-alpine\n\nWORKDIR /app\nCOPY package.json bun.lockb ./\nRUN bun install --frozen-lockfile\n\nCOPY . .\nRUN bun run build\n\nEXPOSE 3000\nCMD [\"bun\", \"run\", \"start\"]\n```\n\n### Process Management\n\nUsing PM2:\n```bash\npm2 start ecosystem.config.js\n```\n\n```javascript\n// ecosystem.config.js\nmodule.exports = {\n  apps: [{\n    name: 'whatsapp-otp-api',\n    script: 'bun',\n    args: 'run start',\n    instances: 1,\n    autorestart: true,\n    watch: false,\n    max_memory_restart: '1G',\n    env: {\n      NODE_ENV: 'production',\n      PORT: 3000\n    }\n  }]\n}\n```\n\n---\n\n## 🛡️ Security Considerations\n\n### Authentication\n- Keep WhatsApp session files secure\n- Regularly rotate session data\n- Monitor for unauthorized access\n\n### API Security\n- Implement rate limiting for production use\n- Add API key authentication\n- Validate all input parameters\n\n### Data Protection\n- Encrypt sensitive configuration\n- Use HTTPS in production\n- Regular security audits\n\n---\n\n## 🤝 Contributing\n\nWe welcome contributions! Please see [src/locales/TRANSLATIONS.md](src/locales/TRANSLATIONS.md) for translation contributions.\n\n### Development Setup\n1. Fork the repository\n2. Create a feature branch\n3. Make your changes\n4. Add tests if applicable\n5. Submit a pull request\n\n### Code Style\n- Follow TypeScript best practices\n- Use meaningful variable names\n- Add comments for complex logic\n- Format with Prettier\n\n---\n\n## 📝 License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n---\n\n## 🆘 Support\n\n### Common Issues\n\n**Connection Problems:**\n- Ensure WhatsApp Web is not open in other browsers\n- Clear auth data and reconnect\n- Check network connectivity\n\n**Message Delivery:**\n- Verify phone number format\n- Check WhatsApp connection status\n- Review error logs\n\n**Localization Issues:**\n- Verify locale parameter format\n- Check available locales endpoint\n- Validate translation files\n\n### Getting Help\n\n- 📚 Check the documentation\n- 🐛 Report bugs via GitHub Issues\n- 💡 Request features via GitHub Discussions\n- 📧 Contact support for urgent issues\n\n---\n\n\u003cdiv align=\"center\"\u003e\n  \u003cp\u003eMade with ❤️ for modern web applications\u003c/p\u003e\n  \u003cp\u003e\n    \u003ca href=\"#whatsapp-otp-api\"\u003eBack to Top\u003c/a\u003e •\n    \u003ca href=\"README_ID.md\"\u003eBahasa Indonesia\u003c/a\u003e •\n    \u003ca href=\"src/locales/TRANSLATIONS.md\"\u003eContribute Translations\u003c/a\u003e\n  \u003c/p\u003e\n\u003c/div\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fidmja%2Fwapi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fidmja%2Fwapi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fidmja%2Fwapi/lists"}