whatsapp-web-api-rest
is an easy-to-use Docker REST API wrapper for Baileys - Lightweight full-featured TypeScript/JavaScript WhatsApp Web API built with NestJS. It allows you to interact with WhatsApp using endpoints to enable message sending, simulate actions, fetch contacts, and more.
- π Send WhatsApp messages via API
- π€ Simulate user actions (e.g. composing, recording audio)
- π² Fetch chats, contacts, labels, and WhatsApp states
- π Manage webhooks for real-time updates
- π Server-Sent Events (SSE) for live message updates
- β‘οΈ RESTful design based on NestJS
docker run --restart unless-stopped -dp 8085:8085 --name whatsapp-web-api-rest blakegt/whatsapp-web-api-rest:latest
Clone the repository:
git clone https://github.com/BlakePro/whatsapp-web-api-rest.git
Install dependencies:
cd whatsapp-web-api-rest
npm install or pnpm i
Start the server:
npm run dev or pnpm dev
-
GET
/Start whatsApp session
Returns an HTML page displaying QR code for authentication
curl -i http://localhost:8085
or open in your browser http://localhost:8085 -
POST
/messageSend message text, media, location, poll, contact
Request Body:
application/json
curl -X POST http://localhost:8085/message \ -H "Content-Type: application/json" -d {...body}
Body examples:
-
Text:
{ "chatId": "5215512345678@c.us", "text": "Hello!", }
-
Media (document):
{ "chatId": "5215512345678@c.us", "media": { "type": "document", "filename": "My name of the file", "caption": "Hey! This is a pdf doc", "mimetype": "application/pdf", "data": "JVBERi0xLjMKJbrfrO..." // base64 } }
-
Media (video):
{ "chatId": "5215512345678@c.us", "media": { "type": "video", "caption": "Hey! This is a video", "data": "JVBERi0xLjMKJbrfrO..." // base64 } }
-
Media (audio):
{ "chatId": "5215512345678@c.us", "media": { "type": "audio", "caption": "Hey! This is an audio", "ptt": false, // Set to true if you want it to appear as a voice note "data": "JVBERi0xLjMKJbrfrO..." // base64 } }
-
Media (sticker):
{ "chatId": "5215512345678@c.us", "media": { "type": "sticker", "mimetype": "image/webp", "data": "JVBERi0xLjMKJbrfrO..." // base64 } }
-
Location:
{ "chatId": "5215512345678@c.us", "location": { "name": "Googleplex", "address": "1600 Amphitheatre Pkwy", "url": "https: //google.com", "latitude": 37.422, "longitude": -122.084 } }
-
Contact:
{ "chatId": "5215512345678@c.us", "contact": { "firstname": "Blake", "lastname": "Pro", "email": "blakegt@gmail.com", "phone": "5215512345678" } }
-
Poll:
{ "chatId": "5215512345678@c.us", "poll": { "name": "Do you like Apple?", "options": [ "Yes", "No", "Maybe" ], "allowMultipleAnswers": false } }
-
-
POST
/simulateSimulate an action (presence)
- chatId: The chat number ID
- action: The action to simulate: unavailable | available | composing | recording | paused
{ "chatId": "5215512345678@c.us", "action": "composing", }
curl http://localhost:8085/simulate
-
GET
/profile/status/:chatIdGet the status of a person/group
- chatId: The chat number ID
curl http://localhost:8085/profile/status/:chatId
-
GET
/profile/picture/:chatIdGet profile url picture of a person/group
- chatId: The chat number ID
curl http://localhost:8085/picture/status/:chatId
-
GET
/chatsFetches all available chats
curl http://localhost:8085/chats
-
GET
/contactsFetches all available contacts
curl http://localhost:8085/contacts
-
GET
/number/:numberIdCheck if a given ID is on WhatsApp
- number: The phone number
curl http://localhost:8085/number/:number
-
GET
/logoutLogs out from the current WhatsApp session
curl http://localhost:8085/logout
-
GET
/webhooksFetches the list of registered webhook URLs
curl http://localhost:8085/webhooks
-
POST
/webhooksCreate a new webhook URL Request Body:
application/json
curl -X POST http://localhost:8085/webhooks \ -H "Content-Type: application/json" \ -d { "url": "https://your-webhook-url.com" }
-
DELETE
/webhooks/:indexIdRemove the webhook by the index in the list
curl -X DELETE http://localhost:8085/webhooks/:indexId
-
Create a folder in your computer and enter
-
Init the project
npm init
orpnpm i
-
Install express.js
npm i express.js
orpnpm i express.js
-
Create a file index.js
-
Copy and paste in index.js and run in terminal
node index.js
const express = require('express'); const app = express(); const port = 3005; const limit = '50mb'; // Use express.json() middleware to parse JSON bodies app.use(express.json({ limit })); app.use(express.urlencoded({ extended: true, limit })); // Define a POST endpoint app.post('/', async (req, res) => { const url = `${req.protocol}://${req.get('host')}${req.url}`; const bodyPayload = req.body; const message = bodyPayload?.message; const media = bodyPayload?.media; const from = message?.from; console.log(from) // Body payload data const payload = { chatId: from, text: 'Response from webhook' } // Send message to endpoint await fetch(`${url}/message`, { method: 'POST', body: JSON.stringify(payload), headers: { "Content-Type": "application/json", }, }) res.send({}); }); // Start the server app.listen(port, () => { console.log(`Server running at http://localhost:${port}`); });
Feel free to contribute by creating issues or submitting pull requests. All contributions are welcome!
This project is not affiliated, associated, authorized, endorsed by, or in any way officially connected with WhatsApp or any of its subsidiaries or its affiliates. The official WhatsApp website can be found at whatsapp.com. "WhatsApp" as well as related names, marks, emblems and images are registered trademarks of their respective owners. Also it is not guaranteed you will not be blocked by using this method. WhatsApp does not allow bots or unofficial clients on their platform, so this shouldn't be considered totally safe.
This project is licensed under the MIT License.