A complete guide from setup to sending messages via API
- 📦 Requirements
- 📥 Step 1: Install Termux
- ⚙️ Step 2: Initial Termux Setup
- 🌐 Step 3: Give Storage Access
- 📂 Step 4: Create Project Directory
- 📚 Step 5: Install Required Packages
- 🧠 Step 6: Create index.js File
- 🚀 Step 7: Run the Script
- 🔗 Step 8: Scan QR to Connect WhatsApp
- 📡 Step 9: Find Your IP Address
- 🧪 Step 10: Test APIs via Postman
- 📌 API Endpoints Summary
- 📁 Accessing Termux Files
- 📤 Exporting Project to Storage
- 🔒 Notes & Troubleshooting
- Android phone
- Internet connection (Wi-Fi preferred)
- Termux app (download from F-Droid or GitHub)
- WhatsApp account (must not be active on other devices)
Download the latest Termux APK from:
👉 https://f-droid.org/packages/com.termux/
Do not use the Play Store version (it's outdated).
Open Termux and run:
pkg update && pkg upgrade -y
pkg install nodejs git ffmpeg -yCheck versions:
node -v
npm -vTo allow access to shared folders:
termux-setup-storageTap Allow when prompted.
mkdir whatsapp-server
cd whatsapp-servernpm init -y
npm install express @whiskeysockets/baileys qrcode-terminal node-fetch mime-typesNote: node-fetch is ESM-only now, so we will dynamically import it later.
Inside whatsapp-server folder, create the main server file:
nano index.jsPaste the full working script I gave you [or ask again for it].
Save and exit with: CTRL + X → Y → Enter
node index.jsYou'll see:
🚀 WhatsApp API server running at http://localhost:3000
📱 Scan this QR Code in WhatsApp:
- Open WhatsApp → Menu → Linked Devices → Link New Device
- Scan the QR shown in Termux
- Your session is now active!
In Termux, run:
ip aFind the inet address under wlan0 (e.g., 192.168.0.178)
Install or use one of these alternatives:
pkg install net-toolsThen run:
ifconfigLook for wlan0 and under it:
inet addr:192.168.1.103 Bcast:192.168.1.255 Mask:255.255.255.0
- Go to Settings → Wi-Fi
- Tap on the connected Wi-Fi network
- Scroll to see the IP address (might be under "Advanced")
Use the IP address + port:
http://192.168.0.178:3000/send-message
{
"number": "919999999999",
"message": "Hello from Termux!"
}Set header:
Content-Type: application/json
| Endpoint | Method | Description | Example Body JSON |
|---|---|---|---|
/send-message |
POST | Send a text message to a user | json { "number": "919999999999", "message": "Hello from Termux!" } |
/send-image |
POST | Send an image by URL | json { "number": "919999999999", "imageUrl": "https://example.com/image.jpg", "caption": "Here is your image" } |
/send-pdf |
POST | Send a PDF file | json { "number": "919999999999", "pdfUrl": "https://example.com/sample.pdf", "filename": "Document.pdf" } |
/send-to-group |
POST | Send text to a WhatsApp group | json { "groupId": "1234567890-1234567890@g.us", "message": "Hello group!" } |
/send-button-message |
POST | Send interactive buttons | json { "number": "919999999999", "text": "Choose an option:", "buttons": [ { "index": 1, "quickReplyButton": { "displayText": "Option A", "id": "opt_a" } }, { "index": 2, "quickReplyButton": { "displayText": "Option B", "id": "opt_b" } }, { "index": 3, "urlButton": { "displayText": "Visit Site", "url": "https://example.com" } } ] } |
/status |
GET | Check if WhatsApp is connected | No body required |
To access your Termux project on Android:
cp -r ~/whatsapp-server ~/storage/downloads/Now go to Internal Storage > Downloads via file manager.
Connect your phone via USB, or use an app like:
- ZArchiver to zip the folder
- Solid Explorer to move files easily
- QR will expire if not scanned quickly.
- Baileys stores session in
authfolder — do not delete it. - WhatsApp Web may log out if used on another device.
- You must always run
node index.jsmanually (or automate with Termux boot if needed). - If
fetchis not working, use:
const fetch = (...args) => import('node-fetch').then(({default: fetch}) => fetch(...args));Install:
pkg install termux-apiThen add your node index.js to .bashrc or use Termux:Boot app.
You've built a full WhatsApp API Server on your phone using Termux!
Let me know if you'd like this as:
- 📝 Notion page
- 💻 GitHub README
Or if you'd like to add:
- File uploads
- Auto responder
- Web dashboard
Just say the word.