A robust WhatsApp Gateway based on Baileys and Express.js, featuring:
- QR code login for WhatsApp
- Send text messages, files, and images via REST API
- Logout and generate new QR sessions
- Modular and scalable code structure
- 🔐 WhatsApp login via QR Code
- ✉️ Send text messages
- 📁 Send files and documents
- 🖼️ Send images with captions
- 📢 Bulk messaging capability
- 🚪 Session logout and refresh
- 📦 API ready for frontend integration
git clone https://github.com/username/baileys-wa-gateway.git
cd baileys-wa-gateway
npm install
node server.js
# or for development:
nodemon server.js
Get QR code for WhatsApp login
Send text message to a WhatsApp number
Request Body:
{
"number": "6281234567890",
"message": "Hello from WhatsApp API!"
}
Send text messages to multiple numbers
Request Body:
{
"messages": [
{ "number": "6281234567890", "message": "Message 1" },
{ "number": "6289876543210", "message": "Message 2" }
]
}
Send file to a WhatsApp number
Request Body:
{
"number": "6281234567890",
"filePath": "https://example.com/file.pdf",
"caption": "Here's the PDF file"
}
Send files to multiple numbers
Request Body:
{
"files": [
{
"number": "6281234567890",
"filePath": "https://example.com/file1.pdf",
"caption": "File 1"
},
{
"number": "6289876543210",
"filePath": "https://example.com/file2.pdf",
"caption": "File 2"
}
]
}
Send image to a WhatsApp number
Request Body:
{
"number": "6281234567890",
"imagePath": "https://example.com/image.jpg",
"caption": "Check this image"
}
Send images to multiple numbers
Request Body:
{
"images": [
{
"number": "6281234567890",
"imagePath": "https://example.com/image1.jpg",
"caption": "Image 1"
},
{
"number": "6289876543210",
"imagePath": "https://example.com/image2.jpg",
"caption": "Image 2"
}
]
}
Logout WhatsApp session and generate new QR
.
├── app.js # Express application setup
├── server.js # Entry point (server + WA socket)
├── routes/
│ └── whatsappRoutes.js # API routes for QR, messages, logout
├── controllers/
│ └── messageController.js # Message handling logic
├── services/
│ └── whatsappService.js # WhatsApp session management
├── auth/ # WhatsApp session storage
├── public/ # Static files (optional)
├── .env # Environment configuration
├── package.json
└── README.md
Create .env
file in root directory:
PORT=4567
Install with:
npm install express qrcode-terminal @whiskeysockets/baileys fs-extra pino dotenv
- Muhamad Alfito Santosa - @alfitosantosa
This project is licensed under the MIT License - see the LICENSE file for details.