A RESTful API server that integrates with WhatsApp Web using whatsapp-web.js.
- Authentication with WhatsApp via QR code scanning
- Send text messages
- Send media (images, documents, etc.)
- Retrieve chat lists
- Session persistence using LocalAuth
- Clone this repository:
git clone https://github.com/azizemad-coder/whatsapp-server
- Install dependencies:
pnpm install - Create a
.envfile in the root directory with:PORT=3000
- Start the server:
node server.js - Open
http://localhost:3000/qrcodein your browser - Scan the QR code with your WhatsApp mobile app
- Once authenticated, you can use the API endpoints
GET /qrcode- Get the QR code for WhatsApp authentication
-
POST /send-message- Send a text message{ "number": "1234567890", // Phone number with country code "message": "Hello from WhatsApp API" } -
POST /send-media- Send media (image, document, etc.){ "number": "1234567890", // Phone number with country code "url": "https://example.com/image.jpg", // URL of media "caption": "Optional caption" // Optional }
GET /chats- Get all chatsGET /contact/:number- Get information about a specific contact (replace :number with phone number)
GET /groups- Get all groupsGET /group-messages/:groupId- Get recent messages from a specific group- Optional query parameter:
limit(default: 20) - Number of messages to retrieve
- Optional query parameter:
- WhatsApp does not officially support bots or unofficial clients. Use at your own risk.
- This API server relies on the WhatsApp Web interface, which may change without notice.
- Always ensure your use of WhatsApp automation complies with WhatsApp's Terms of Service.
MIT