# WhatsApp Web QR deployment

This gateway uses the unofficial Baileys WhatsApp Web protocol. Use a dedicated WhatsApp account and ensure its use complies with WhatsApp's terms. The gateway must remain running: its encrypted login credentials are stored in `gateway/storage/auth`.

## 1. Install Node.js 22

```bash
curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -
sudo apt install -y nodejs
```

## 2. Configure Laravel

In `/var/www/whatsapp.plugoza.com/.env`, add a long random secret. The same exact value is used below.

```env
APP_URL=https://whatsapp.plugoza.com
SANCTUM_STATEFUL_DOMAINS=whatsapp.plugoza.com
WHATSAPP_GATEWAY_URL=http://127.0.0.1:3001
WHATSAPP_GATEWAY_SECRET=replace-with-a-long-random-secret
```

Generate a safe secret with:

```bash
openssl rand -hex 32
```

## 3. Configure and install the gateway

```bash
cd /var/www/whatsapp.plugoza.com
sudo cp gateway/.env.example gateway/.env
sudo nano gateway/.env
sudo npm --prefix gateway install --omit=dev
sudo mkdir -p gateway/storage/auth
sudo chown -R www-data:www-data gateway/storage
```

Set both `GATEWAY_SECRET` and Laravel's `WHATSAPP_GATEWAY_SECRET` to the same value. Keep `LARAVEL_WEBHOOK_URL=https://whatsapp.plugoza.com/api/internal/whatsapp/events`.

## 4. Start it as a service

```bash
sudo cp deploy/whatsapp-hub-gateway.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable --now whatsapp-hub-gateway
sudo systemctl status whatsapp-hub-gateway
```

For logs:

```bash
sudo journalctl -u whatsapp-hub-gateway -f
```

## 5. Final Laravel commands

```bash
cd /var/www/whatsapp.plugoza.com
sudo -u www-data php artisan optimize:clear
sudo -u www-data php artisan migrate:fresh --seed --force
sudo -u www-data php artisan config:cache
```

Open `/register` once to create the first administrator. Sign in, open `/dashboard`, enter a name, select **Generate QR code**, and scan it from WhatsApp: **Settings → Linked devices → Link a device**.

Do not expose port 3001 to the internet. It listens locally and Laravel calls it through `127.0.0.1`.
