Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WA Bot — WhatsApp API

Bot WhatsApp sederhana berbasis whatsapp-web.js dengan web dashboard untuk scan QR. Fitur utama: balas /ping dengan pong.


Struktur Project

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

Cara Jalankan (Local)

# 1. Install dependencies
npm install

# 2. Jalankan bot
npm start

Buka browser ke http://localhost:3000 → scan QR dengan WhatsApp di HP.


Deploy ke VPS

1. Prerequisites VPS (Ubuntu/Debian)

# 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

2. Upload Project ke VPS

# 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 --production

3. Konfigurasi Environment

cp .env.example .env
nano .env   # Edit PORT jika perlu

4. Jalankan dengan PM2

# Mulai bot
pm2 start src/index.js --name "wa-bot"

# Auto-start saat reboot
pm2 startup
pm2 save

# Cek log
pm2 logs wa-bot

5. Setup Nginx Reverse Proxy (Opsional)

server {
    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

Perintah Bot

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!');
  // }
});

API Endpoints

Method URL Keterangan
GET / Dashboard web (QR code)
GET /api/status Status bot + QR data URI
POST /api/logout Logout & hapus sesi

Notes

  • 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.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages