Bot WhatsApp sederhana berbasis whatsapp-web.js dengan web dashboard untuk scan QR. Fitur utama: balas /ping dengan pong.
wa-m2/
├── src/
│ └── index.js ← Bot + Express server
├── public/
│ └── index.html ← Web dashboard (QR scanner)
├── session/ ← Auto-generated (simpan sesi WA)
├── package.json
├── .env.example
├── .gitignore
└── README.md
# 1. Install dependencies
npm install
# 2. Jalankan bot
npm startBuka browser ke http://localhost:3000 → scan QR dengan WhatsApp di HP.
# Update system
sudo apt update && sudo apt upgrade -y
# Install Node.js 18+
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt install -y nodejs
# Install Chromium (untuk Puppeteer/whatsapp-web.js)
sudo apt install -y chromium-browser
# Install PM2 (process manager)
sudo npm install -g pm2# Dari local machine, zip & upload
zip -r wa-m2.zip wa-m2/ --exclude "*/node_modules/*" --exclude "*/session/*"
scp wa-m2.zip user@IP_VPS:~/
# Di VPS
unzip wa-m2.zip
cd wa-m2
npm install --productioncp .env.example .env
nano .env # Edit PORT jika perlu# Mulai bot
pm2 start src/index.js --name "wa-bot"
# Auto-start saat reboot
pm2 startup
pm2 save
# Cek log
pm2 logs wa-botserver {
listen 80;
server_name yourdomain.com;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}sudo systemctl restart nginx| Command | Response |
|---|---|
/ping |
pong |
Untuk menambah perintah baru, edit bagian Command Handler di src/index.js:
client.on('message', async (message) => {
const body = message.body.trim();
if (body === '/ping') {
await message.reply('pong');
}
// Tambah command baru di sini:
// if (body === '/hello') {
// await message.reply('world!');
// }
});| Method | URL | Keterangan |
|---|---|---|
GET |
/ |
Dashboard web (QR code) |
GET |
/api/status |
Status bot + QR data URI |
POST |
/api/logout |
Logout & hapus sesi |
- Sesi tersimpan di folder
session/— tidak perlu scan ulang setelah restart jika sesi masih valid. - Jangan commit folder
session/ke Git (sudah ada di.gitignore). - Pastikan VPS punya RAM minimal 512MB untuk Puppeteer.