# 🚀 Quick Start - WhatsApp Self-Hosted Gateway

Panduan cepat 5 menit untuk setup WhatsApp Gateway self-hosted di MikhMon.

---

## ⚡ Instalasi Super Cepat

### Windows:

1. **Install Node.js** (jika belum):
   - Download: https://nodejs.org/
   - Install versi LTS
   - Restart command prompt

2. **Buka Command Prompt** di folder MikhMon:
   ```cmd
   cd C:\xampp\htdocs\mikhmon\whatsapp-gateway
   ```

3. **Jalankan installer**:
   ```cmd
   install.bat
   ```

4. **Edit konfigurasi**:
   - Buka file `.env` dengan notepad
   - Copy API_KEY yang ada
   - Buka `mikhmon/include/whatsapp_config.php`
   - Paste API_KEY di sana

5. **Start gateway**:
   ```cmd
   npm start
   ```

6. **Scan QR Code**:
   - Buka browser: http://localhost/mikhmon/settings/whatsapp_gateway_admin.php
   - Tunggu QR code muncul
   - Scan dengan WhatsApp

7. **Selesai!** ✅

---

### Linux/macOS:

1. **Install Node.js** (jika belum):
   ```bash
   # Ubuntu/Debian
   curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
   sudo apt-get install -y nodejs
   
   # macOS (dengan Homebrew)
   brew install node
   ```

2. **Masuk ke folder**:
   ```bash
   cd /var/www/html/mikhmon/whatsapp-gateway
   ```

3. **Jalankan installer**:
   ```bash
   chmod +x install.sh
   ./install.sh
   ```

4. **Edit konfigurasi**:
   ```bash
   nano .env
   # Copy API_KEY
   
   nano ../include/whatsapp_config.php
   # Paste API_KEY di SELFHOSTED_API_KEY
   ```

5. **Start gateway**:
   ```bash
   npm start
   ```

6. **Scan QR Code**:
   - Buka browser: http://localhost/mikhmon/settings/whatsapp_gateway_admin.php
   - Scan dengan WhatsApp

7. **Selesai!** ✅

---

## 🎯 Test Kirim Pesan

### Via Admin Panel:
1. Buka: http://localhost/mikhmon/settings/whatsapp_gateway_admin.php
2. Scroll ke "Test Message"
3. Input nomor: 08123456789
4. Klik "Send Test Message"
5. Cek WhatsApp! ✅

### Via Generate Voucher:
1. Login ke MikhMon
2. Buka **Hotspot → Generate Users**
3. Pilih profile
4. Centang **"Kirim ke WhatsApp"**
5. Input nomor customer
6. Klik **Generate**
7. Voucher terkirim ke WhatsApp! ✅

---

## 🔧 Production Setup (PM2)

Untuk production, gunakan PM2 agar gateway jalan terus:

```bash
# Install PM2
npm install -g pm2

# Start dengan PM2
cd whatsapp-gateway
npm run pm2

# Check status
pm2 status

# View logs
pm2 logs mikhmon-wa-gateway

# Auto-start on boot
pm2 startup
pm2 save
```

---

## 🐛 Troubleshooting Cepat

### 1. QR Code tidak muncul?
```bash
# Restart gateway
pm2 restart mikhmon-wa-gateway
# atau
npm start
```

### 2. Pesan tidak terkirim?
- Cek status: http://localhost:3000/api/status
- Pastikan status: "connected"
- Pastikan API key sama di .env dan whatsapp_config.php

### 3. Gateway crash?
```bash
# Lihat error
pm2 logs mikhmon-wa-gateway

# Restart
pm2 restart mikhmon-wa-gateway
```

### 4. Port 3000 sudah dipakai?
Edit `.env`:
```env
PORT=3001
```

Edit `whatsapp_config.php`:
```php
define('SELFHOSTED_API_URL', 'http://localhost:3001/api/send');
```

---

## 📊 Monitoring

### Check Status:
```bash
# Via browser
http://localhost:3000/health

# Via curl
curl http://localhost:3000/health
```

### View Logs:
```bash
# Gateway logs
pm2 logs mikhmon-wa-gateway

# Message logs
tail -f ../logs/whatsapp_log.txt
```

---

## 🎉 Selesai!

Gateway WhatsApp self-hosted Anda sudah jalan!

**Keuntungan:**
- ✅ GRATIS - tidak perlu bayar bulanan
- ✅ UNLIMITED - tidak ada batasan pesan
- ✅ CEPAT - langsung dari server Anda
- ✅ PRIVACY - data tidak lewat pihak ketiga

**Next Steps:**
1. Setup PM2 untuk production
2. Test kirim voucher via WhatsApp
3. Setup bot commands untuk customer
4. Monitor via admin panel

**Dokumentasi Lengkap:**
- WHATSAPP_SELFHOSTED_GUIDE.md (panduan detail)
- whatsapp-gateway/README.md (technical docs)

**Enjoy! 🚀**

