Skip to content

Latest commit

 

History

History
111 lines (86 loc) · 2.67 KB

File metadata and controls

111 lines (86 loc) · 2.67 KB

WAHA Setup – Come ricevere messaggi WhatsApp in Laravel

Prerequisiti

  • Docker installato (Docker Desktop su Windows)
  • Laravel che gira su php artisan serve (locale) o su Railway (production)

1. Avvia WAHA

docker compose -f docker-compose.waha.yml up -d

Apri il dashboard: http://localhost:3000/dashboard

2. Collega WhatsApp

  1. Nel dashboard WAHA, crea una sessione chiamata default
  2. Scannerizza il QR code con il tuo telefono (WhatsApp → Impostazioni → Dispositivi collegati)
  3. Attendi che lo stato diventi "WORKING"

3. Configura il webhook verso Laravel

Sviluppo (Laravel in locale su http://localhost:8000)

curl -X POST http://localhost:3000/api/sessions/default \
  -H "Content-Type: application/json" \
  -d '{
    "config": {
      "webhooks": [
        {
          "url": "http://host.docker.internal:8000/api/whatsapp/webhook",
          "events": ["message"]
        }
      ]
    }
  }'

host.docker.internal permette al container Docker di raggiungere il tuo localhost.

Produzione (Laravel su Railway)

curl -X POST http://localhost:3000/api/sessions/default \
  -H "Content-Type: application/json" \
  -d '{
    "config": {
      "webhooks": [
        {
          "url": "https://tuoapp.up.railway.app/api/whatsapp/webhook",
          "events": ["message"]
        }
      ]
    }
  }'

4. Test

Manda un messaggio WhatsApp o un'immagine al numero collegato. Il messaggio appare automaticamente in WA Inbox (/imported-products).

5. Payload WAHA (formato)

WAHA invia POST con questo formato:

{
  "event": "message",
  "session": "default",
  "payload": {
    "id": "true_123456789@c.us_XXXX",
    "timestamp": 1667561485,
    "from": "123456789@c.us",
    "fromMe": false,
    "to": "123456789@c.us",
    "body": "Surfinia P14 €3.50",
    "hasMedia": true,
    "media": {
      "url": "http://localhost:3000/api/files/XXXX.jpg",
      "mimetype": "image/jpeg"
    }
  }
}

Il controller Laravel riconosce automaticamente il formato WAHA e lo converte in ImportedProduct.

6. Comandi utili

# Fermare WAHA
docker compose -f docker-compose.waha.yml down

# Vedere i log
docker compose -f docker-compose.waha.yml logs -f

# Riavviare
docker compose -f docker-compose.waha.yml restart

Vantaggi rispetto a openwa-bridge.js

  • Niente codice Node da mantenere: WAHA è un container Docker pronto
  • Dashboard web: gestisci sessioni e QR dal browser
  • Persistenza sessione: il volume Docker salva la sessione, non riscannerizzi il QR ad ogni restart
  • API REST completa: puoi anche inviare messaggi via HTTP
  • Swagger docs: API documentata su http://localhost:3000/swagger