# Configuración — SKEEN Derma Experts

**Versión:** 2.0  
**Fecha:** 16 de julio de 2026

---

## 1. Variables de Entorno

### 1.1 Bridge SKEEN (`/root/skeen-roadmap-hermes/hermes/.env`)

```env
# Nan Builders (IA)
NAN_API_KEY=sk-gJ8OWbZVGeWy9ns_H00cxA
NAN_BASE_URL=https://api.nan.builders/v1
NAN_MODEL=qwen3.6

# WACRM
WACRM_URL=http://localhost:3000
WACRM_API_KEY=wacrm_live_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

# Bridge
BRIDGE_PORT=8090
NODE_ENV=production
```

### 1.2 WACRM (`/root/skeen-wacrm/.env.local`)

```env
# Supabase (self-hosted on localhost)
NEXT_PUBLIC_SUPABASE_URL=http://localhost:8000
NEXT_PUBLIC_SUPABASE_ANON_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoiYW5vbiIsImlzcyI6InN1cGFiYXNlIiwiaWF0IjoxNjQxNzY5MjAwLCJleHAiOjE3OTk1MzU2MDB9.pnl22qqc0WMyNRwqdXq7cEq1hw_YTrdTgWHd0TPsHPU
SUPABASE_SERVICE_ROLE_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoic2VydmljZV9yb2xlIiwiaXNzIjoic3VwYWJhc2UiLCJpYXQiOjE2NDE3NjkyMDAsImV4cCI6MTc5OTUzNTYwMH0.XA05Pgn-gkEKaZEaHYFc9DAyP45uNJdsl8DL9axUxbc

# Encryption key for WACRM (64 hex chars)
ENCRYPTION_KEY=8bbf201d9d60488a1e86e5396b31e22d8bbf201d9d60488a1e86e5396b31e22d

# WhatsApp / Meta (pending client data)
WHATSAPP_PHONE_NUMBER_ID=PENDING_PHONE_ID
WHATSAPP_BUSINESS_ACCOUNT_ID=PENDING_WABA_ID
WHATSAPP_ACCESS_TOKEN=PENDING_TOKEN
WHATSAPP_VERIFY_TOKEN=skeen_webhook_verify_2026

# Meta App Secret for webhook signature verification
META_APP_SECRET=skeen_meta_app_secret_2026_demo

# Application
NEXT_PUBLIC_APP_URL=http://localhost:3000
NODE_ENV=production
```

### 1.3 Odoo (`/root/skeen-odoo/odoo.conf`)

```ini
[options]
addons_path = /root/skeen-odoo/addons,/root/skeen-odoo/odoo/addons
admin_passwd = skeen_admin_2026
csv_internal_sep = ,
data_dir = /var/lib/odoo
db_host = localhost
db_maxconn = 64
db_name = skeen_odoo
db_password = skeen_dev_2026
db_port = 5432
db_sslmode = prefer
db_user = skeen
demo = {}
email_from = False
geoip_database = /usr/share/GeoIP/GeoLite2-City.mmdb
http_enable = True
http_interface =
http_port = 8069
import_partial =
limit_memory_hard = 2684354560
limit_memory_soft = 2147483648
limit_request = 8192
limit_time_cpu = 60
limit_time_real = 120
limit_time_real_cron = -1
list_db = True
log_db = False
log_db_level = warning
log_handler = :INFO
log_level = info
logfile =
longpolling_port = 8072
max_cron_threads = 2
osv_memory_age_limit = False
osv_memory_count_limit = False
pg_path =
pidfile =
proxy_mode = True
reportgz = False
screencasts =
screenshots = /tmp/odoo_screenshots
server_wide_modules = base,web
smtp_password = False
smtp_port = 25
smtp_server = localhost
smtp_ssl = False
smtp_ssl_certificate_filename = False
smtp_ssl_private_key_filename = False
smtp_user = False
test_file =
test_tags = None
translate_modules = ['all']
unaccent = False
upgrade_path =
without_demo = False
workers = 0
```

### 1.4 Scripts de Inicio (`/root/skeen-start-all.sh`)

```bash
export SUPABASE_URL="http://localhost:8000"
export SUPABASE_SERVICE_ROLE_KEY="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoic2VydmljZV9yb2xlIiwiaXNzIjoic3VwYWJhc2UiLCJpYXQiOjE2NDE3NjkyMDAsImV4cCI6MTc5OTUzNTYwMH0.XA05Pgn-gkEKaZEaHYFc9DAyP45uNJdsl8DL9axUxbc"
```

---

## 2. Credenciales y Accesos

| Servicio | URL | Usuario | Contraseña | Notas |
|----------|-----|---------|------------|-------|
| Odoo | http://localhost:8069 | admin | skeen_admin_2026 | DB: skeen_odoo |
| Frontend | http://localhost:5173 | admin | SkeenAdmin2026! | Usuario seed |
| WACRM | http://localhost:3000 | ivan@horuxfin.com | (definida por usuario) | Registro manual |
| Supabase Studio | http://localhost:8000 | supabase | (definida en .env) | Dashboard |
| PostgreSQL Odoo | localhost:5432 | skeen | skeen_dev_2026 | DB: skeen_odoo |
| PostgreSQL Supabase | localhost:5433 | postgres | (definida en .env) | Docker |

---

## 3. Endpoints Importantes

### 3.1 Odoo REST API (`skeen_whatsapp`)

| Endpoint | Método | Descripción | Auth |
|----------|--------|-------------|------|
| `/skeen/api/v1/available_slots` | POST | Slots disponibles | API Key |
| `/skeen/api/v1/create_appointment` | POST | Crear cita | API Key |
| `/skeen/api/v1/patient_balance` | POST | Saldo paciente | API Key |
| `/skeen/api/v1/wallet_redeem` | POST | Redimir puntos | API Key |
| `/skeen/api/v1/cancel_appointment` | POST | Cancelar cita | API Key |

### 3.2 Odoo Frontend API (`skeen/frontend/v1/*`)

| Endpoint | Método | Descripción | Auth |
|----------|--------|-------------|------|
| `/skeen/frontend/v1/health` | GET | Health check | None |
| `/skeen/frontend/v1/auth/login` | POST | Login | None |
| `/skeen/frontend/v1/auth/me` | GET | Usuario actual | JWT |
| `/skeen/frontend/v1/appointments` | GET/POST | Citas | JWT |
| `/skeen/frontend/v1/appointments/<id>` | GET/PUT/DELETE | Cita individual | JWT |
| `/skeen/frontend/v1/services` | GET/POST | Servicios | JWT |
| `/skeen/frontend/v1/services/<id>` | PUT | Actualizar servicio | JWT |
| `/skeen/frontend/v1/patients` | GET/POST | Pacientes | JWT |
| `/skeen/frontend/v1/patients/<id>` | GET/PUT | Paciente individual | JWT |
| `/skeen/frontend/v1/wallets` | GET | Monederos | JWT |
| `/skeen/frontend/v1/sales` | GET/POST | Ventas | JWT |
| `/skeen/frontend/v1/inventory` | GET | Inventario | JWT |
| `/skeen/frontend/v1/wacrm/contacts` | GET | Contactos WACRM | JWT |
| `/skeen/frontend/v1/wacrm/conversations` | GET | Conversaciones WACRM | JWT |
| `/skeen/frontend/v1/wacrm/messages` | GET | Mensajes WACRM | JWT |
| `/skeen/frontend/v1/wacrm/deals` | GET | Deals WACRM | JWT |
| `/skeen/frontend/v1/wacrm/sync` | POST | Sincronizar WACRM→Odoo | JWT |

### 3.3 WACRM API (`/api/v1/*`)

| Endpoint | Método | Descripción | Auth |
|----------|--------|-------------|------|
| `/api/v1/messages` | POST | Enviar mensaje | Bearer Token |
| `/api/v1/messages/simulate` | POST | Simular mensaje (demo) | Bearer Token |
| `/api/v1/contacts` | GET/POST | Contactos | Bearer Token |
| `/api/v1/conversations` | GET | Conversaciones | Bearer Token |
| `/api/v1/webhooks` | GET/POST | Webhooks | Bearer Token |
| `/api/whatsapp/webhook` | POST | Webhook Meta | Verify Token |

### 3.4 Bridge SKEEN (`:8090`)

| Endpoint | Método | Descripción |
|----------|--------|-------------|
| `/health` | GET | Health check |
| `/webhook/wacrm` | POST | Webhook WACRM → Hermes |

---

## 4. Configuración de Hermes

### 4.1 Gateway

```bash
# Ver estado
hermes gateway status

# Iniciar
hermes gateway run

# Instalar como servicio
hermes gateway install
sudo hermes gateway install --system
```

### 4.2 Serve (Dashboard/API)

```bash
hermes serve --host 0.0.0.0 --port 9119 --skip-build
```

### 4.3 Skills Instalados

```bash
hermes skills list
```

Skills disponibles:
- `skeen-rag`
- `skeen-agendar`
- `skeen-pagos`
- `skeen-monedero`
- `skeen-recordatorios`

---

## 5. Configuración de Meta WhatsApp Cloud API

### 5.1 Crear App en Meta Developers

1. Ir a https://developers.facebook.com
2. Crear app tipo "Business"
3. Agregar producto "WhatsApp"
4. Obtener:
   - Phone Number ID
   - WhatsApp Business Account ID (WABA ID)
   - Access Token (permanente, System User)
   - App Secret

### 5.2 Configurar Webhook en Meta

| Campo | Valor |
|-------|-------|
| Callback URL | `https://crm.skeen.mx/api/whatsapp/webhook` |
| Verify Token | `skeen_webhook_verify_2026` |
| Subscription fields | `messages`, `message_template_status_update` |

### 5.3 Configurar WACRM

En WACRM Dashboard → Settings → WhatsApp:

| Campo | Valor |
|-------|-------|
| Phone Number ID | De Meta Developers |
| Access Token | Token permanente |
| Business Account ID | WABA ID |
| Verify Token | `skeen_webhook_verify_2026` |

### 5.4 Templates de WhatsApp

Templates a subir y aprobar en Meta Business Manager:

| Template | Categoría | Uso |
|----------|-----------|-----|
| `bienvenida_skeen` | UTILITY | Primer contacto |
| `confirmacion_cita` | UTILITY | Confirmación de agendamiento |
| `recordatorio_cita` | UTILITY | Recordatorio 24h antes |
| `followup_tratamiento` | UTILITY | Seguimiento post-tratamiento |
| `reengage_skeen` | MARKETING | Re-engagement pacientes inactivos |
| `comprobante_pago` | UTILITY | Confirmación de pago recibido |

---

## 6. Configuración de Supabase

### 6.1 Docker Compose

```bash
cd /root/skeen-supabase/docker
docker compose up -d
docker compose ps
```

### 6.2 Variables de Entorno Clave

```env
POSTGRES_PASSWORD=your_password
JWT_SECRET=your_jwt_secret
ANON_KEY=your_anon_jwt
SERVICE_ROLE_KEY=your_service_role_jwt
DASHBOARD_USERNAME=supabase
DASHBOARD_PASSWORD=your_dashboard_password
```

### 6.3 Acceso a Base de Datos

```bash
# Desde host
psql -h localhost -p 5433 -U postgres -d postgres

# Desde contenedor
docker exec supabase-db psql -U postgres -d postgres
```

---

## 7. Configuración de nginx

### 7.1 Frontend React

```nginx
server {
    listen 80;
    server_name skeen.consultoria-as.com;
    root /var/www/skeen-frontend;
    index index.html;

    location / {
        try_files $uri $uri/ /index.html;
    }

    location /api/odoo {
        proxy_pass http://localhost:8069;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

    location /api/wacrm {
        proxy_pass http://localhost:3000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}
```

### 7.2 WACRM (subdominio)

```nginx
server {
    listen 80;
    server_name skeencrm.consultoria-as.com;

    location / {
        proxy_pass http://localhost:3000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}
```

---

## 8. Configuración de Cloudflare Tunnel

Para exponer servicios sin abrir puertos en el firewall:

```bash
# Instalar cloudflared
curl -fsSL https://pkg.cloudflare.com/cloudflared.repo | sudo tee /etc/apt/sources.list.d/cloudflared.list
sudo apt update && sudo apt install cloudflared

# Autenticar
cloudflared tunnel login

# Crear tunnel
cloudflared tunnel create skeen-tunnel

# Configurar DNS
cloudflared tunnel route dns skeen-tunnel skeen.consultoria-as.com

# Ejecutar tunnel
cloudflared tunnel run --token YOUR_TUNNEL_TOKEN
```

**Nota:** El tunnel ya está configurado en esta VM con el token proporcionado.

---

## 9. Configuración de systemd (Producción)

### 9.1 Odoo

```ini
[Unit]
Description=Odoo 17 SKEEN
After=network.target postgresql.service

[Service]
Type=simple
User=root
Environment=SUPABASE_URL=http://localhost:8000
Environment=SUPABASE_SERVICE_ROLE_KEY=your_key
ExecStart=/root/odoo-venv/bin/python /root/skeen-odoo/odoo-bin -c /root/skeen-odoo/odoo.conf
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target
```

### 9.2 WACRM

```ini
[Unit]
Description=WACRM SKEEN
After=network.target

[Service]
Type=simple
User=root
WorkingDirectory=/root/skeen-wacrm
Environment=NODE_ENV=production
ExecStart=/usr/bin/npm start
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target
```

### 9.3 Bridge SKEEN

```ini
[Unit]
Description=Bridge Webhook SKEEN
After=network.target

[Service]
Type=simple
User=root
WorkingDirectory=/root/skeen-roadmap-hermes/hermes
Environment=NODE_ENV=production
ExecStart=/usr/bin/node webhook-bridge.js
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target
```

---

## 10. Configuración de Backups

```bash
# Backup PostgreSQL Odoo
pg_dump -U skeen -h localhost skeen_odoo > /root/backups/odoo_$(date +%Y%m%d_%H%M%S).sql

# Backup PostgreSQL Supabase
docker exec supabase-db pg_dump -U postgres postgres > /root/backups/supabase_$(date +%Y%m%d_%H%M%S).sql

# Backup archivos
tar -czf /root/backups/skeen-files_$(date +%Y%m%d_%H%M%S).tar.gz \
  /root/skeen-frontend \
  /root/skeen-wacrm \
  /root/skeen-odoo/addons/skeen_* \
  /root/skeen-roadmap-hermes \
  /root/migracion
```

---

## 11. Checklist de Configuración para Go-Live

- [ ] Número WhatsApp Business verificado por Meta
- [ ] Meta App ID + Secret configurados
- [ ] Access Token permanente generado
- [ ] Phone Number ID y WABA ID configurados en WACRM
- [ ] Templates de WhatsApp aprobados por Meta
- [ ] Dominio skeen.mx apuntando a la VM
- [ ] SSL certificado instalado (Let's Encrypt)
- [ ] Firewall configurado (solo 80, 443, 22)
- [ ] Backups automatizados configurados
- [ ] Monitoreo Uptime Kuma activo
- [ ] API keys de WACRM generadas y configuradas
- [ ] Variables de entorno en producción
- [ ] systemd services habilitados
- [ ] Logs rotando correctamente
