Clon demo-seguros: puerto 8003, sin n8n, nombres adaptados
This commit is contained in:
1 parent
799bfe9ec7
commit
c81dab926c
10 files changed
+41
-313
No files matched your search
+7
-9
@@ -2,19 +2,17 @@
|
||||
OPENAI_API_KEY=sk-...
|
||||
|
||||
# ─── Google Sheets ────────────────────────────────────────
|
||||
GOOGLE_SHEET_ID=<ID del sheet — viene de la URL del Sheet>
|
||||
GOOGLE_SHEET_NAME=Concentrado de Seguros
|
||||
# JSON completo de la service account (en una sola línea)
|
||||
GOOGLE_SERVICE_ACCOUNT_JSON={"type":"service_account","project_id":"wk-bot-489515",...}
|
||||
GOOGLE_SHEET_ID=<ID del sheet del cliente demo>
|
||||
GOOGLE_SHEET_NAME=SEGUROS
|
||||
GOOGLE_SERVICE_ACCOUNT_JSON={"type":"service_account",...}
|
||||
|
||||
# ─── Redis ────────────────────────────────────────────────
|
||||
REDIS_URL=redis://wk-seguros-redis:6379
|
||||
REDIS_URL=redis://demo-seguros-redis:6379
|
||||
|
||||
# ─── EvolutionAPI ─────────────────────────────────────────
|
||||
EVOLUTION_API_URL=http://evo-r8gs8s848s44ww00cwgkoooo.191.101.233.43.sslip.io:8081
|
||||
EVOLUTION_API_KEY=yiewm3RifaGcl2G5465XWo3bBbDsARSh
|
||||
EVOLUTION_INSTANCE=wk-seguros
|
||||
EVOLUTION_API_URL=http://10.0.10.5:8080
|
||||
EVOLUTION_API_KEY=<api key de evolution>
|
||||
EVOLUTION_INSTANCE=demo-seguros
|
||||
|
||||
# ─── Seguridad ────────────────────────────────────────────
|
||||
# Números autorizados para usar el bot (formato: 521XXXXXXXXXX,521YYYYYYYYY)
|
||||
NUMEROS_AUTORIZADOS=521XXXXXXXXXX
|
||||
@@ -6,9 +6,8 @@ leyendo un Google Sheet en tiempo real. NO genera PDFs — solo responde texto.
|
||||
|
||||
## Flujo del Sistema
|
||||
```
|
||||
WhatsApp → EvolutionAPI (instancia: wk-seguros)
|
||||
→ n8n (webhook trigger)
|
||||
→ FastAPI :8002 (este proyecto)
|
||||
WhatsApp → EvolutionAPI (instancia: demo-seguros)
|
||||
→ FastAPI :8003 (este proyecto)
|
||||
→ GPT-4o-mini (clasificar intención del mensaje)
|
||||
→ Google Sheets (leer datos reales)
|
||||
→ Texto estructurado → WhatsApp
|
||||
@@ -18,16 +17,15 @@ WhatsApp → EvolutionAPI (instancia: wk-seguros)
|
||||
- **VPS:** 191.101.233.43 (Hostinger Ubuntu 24.04)
|
||||
- **Panel:** Coolify v4 — http://191.101.233.43:8000
|
||||
- **EvolutionAPI:** http://evo-r8gs8s848s44ww00cwgkoooo.191.101.233.43.sslip.io:8081
|
||||
- **n8n:** http://n8n-zo844044skw0k4k04oc8oo0w.191.101.233.43.sslip.io:8081
|
||||
- **Puerto FastAPI:** 8002
|
||||
- **Redis:** contenedor `wk-seguros-redis` (aislado del bot de cotizaciones)
|
||||
- **Puerto FastAPI:** 8003
|
||||
- **Redis:** contenedor `demo-seguros-redis` (aislado del bot de cotizaciones)
|
||||
|
||||
## Estructura del Proyecto
|
||||
```
|
||||
/wk-seguros/
|
||||
/demo-seguros/
|
||||
├── CLAUDE.md ← este archivo
|
||||
├── Dockerfile
|
||||
├── docker-compose.yml ← incluye wk-seguros-redis
|
||||
├── docker-compose.yml ← incluye demo-seguros-redis
|
||||
├── .env.example
|
||||
├── requirements.txt
|
||||
└── src/
|
||||
|
||||
+2
-8
@@ -1,21 +1,15 @@
|
||||
FROM python:3.11-slim
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Instalar dependencias del sistema necesarias para dateparser
|
||||
RUN apt-get update && apt-get install -y \
|
||||
gcc \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Copiar e instalar dependencias Python
|
||||
COPY requirements.txt .
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
# Copiar código fuente
|
||||
COPY src/ ./src/
|
||||
|
||||
# Puerto de la aplicación
|
||||
EXPOSE 8002
|
||||
EXPOSE 8003
|
||||
|
||||
# Comando de arranque
|
||||
CMD ["uvicorn", "src.main:app", "--host", "0.0.0.0", "--port", "8002"]
|
||||
CMD ["uvicorn", "src.main:app", "--host", "0.0.0.0", "--port", "8003"]
|
||||
@@ -1,4 +1,4 @@
|
||||
# WK Seguros Bot
|
||||
# Demo Seguros Bot
|
||||
|
||||
Bot de WhatsApp para consulta de vencimientos de pólizas vehiculares.
|
||||
**WK Financing Solutions** — Carlos Paulino Sanchez Cazares
|
||||
@@ -8,23 +8,23 @@ Bot de WhatsApp para consulta de vencimientos de pólizas vehiculares.
|
||||
## Arquitectura
|
||||
|
||||
```
|
||||
WhatsApp → EvolutionAPI (wk-seguros) → n8n → FastAPI :8002
|
||||
WhatsApp → EvolutionAPI (demo-seguros) → FastAPI :8003
|
||||
→ GPT-4o-mini → Google Sheets → Respuesta texto → WhatsApp
|
||||
```
|
||||
|
||||
## Requisitos previos
|
||||
|
||||
- [ ] Instancia `wk-seguros` creada en EvolutionAPI con número conectado
|
||||
- [ ] Instancia `demo-seguros` creada en EvolutionAPI con número conectado
|
||||
- [ ] Sheet de seguros compartido con `wk-bot-sheets@wk-bot-489515.iam.gserviceaccount.com`
|
||||
- [ ] Workflow de n8n apuntando a `http://wk-seguros-api:8002/api/v1/webhook`
|
||||
- [ ] Webhook de EvolutionAPI apuntando a `http://demo-seguros-api:8003/api/v1/webhook`
|
||||
- [ ] Variables de entorno configuradas (ver `.env.example`)
|
||||
|
||||
## Setup local (desarrollo)
|
||||
|
||||
```bash
|
||||
# 1. Clonar el repo y entrar al directorio
|
||||
git clone <repo> wk-seguros
|
||||
cd wk-seguros
|
||||
git clone <repo> demo-seguros
|
||||
cd demo-seguros
|
||||
|
||||
# 2. Copiar y llenar variables de entorno
|
||||
cp .env.example .env
|
||||
@@ -34,23 +34,23 @@ cp .env.example .env
|
||||
pip install -r requirements.txt
|
||||
|
||||
# 4. Correr en modo desarrollo
|
||||
uvicorn src.main:app --reload --port 8002
|
||||
uvicorn src.main:app --reload --port 8003
|
||||
```
|
||||
|
||||
## Deployment en VPS (producción)
|
||||
|
||||
```bash
|
||||
# En el VPS via SSH
|
||||
cd /opt/wk-seguros
|
||||
cd /opt/demo-seguros
|
||||
|
||||
# Build y levantar contenedores
|
||||
docker-compose up -d --build
|
||||
|
||||
# Ver logs en tiempo real
|
||||
docker-compose logs -f wk-seguros-api
|
||||
docker-compose logs -f demo-seguros-api
|
||||
|
||||
# Verificar que está corriendo
|
||||
curl http://localhost:8002/health
|
||||
curl http://localhost:8003/health
|
||||
```
|
||||
|
||||
## Endpoints
|
||||
@@ -58,7 +58,7 @@ curl http://localhost:8002/health
|
||||
| Método | Ruta | Descripción |
|
||||
|---|---|---|
|
||||
| GET | `/health` | Verificación de salud |
|
||||
| POST | `/api/v1/webhook` | Recibe mensajes de n8n |
|
||||
| POST | `/api/v1/webhook` | Recibe mensajes de EvolutionAPI |
|
||||
|
||||
## Variables de entorno
|
||||
|
||||
|
||||
+10
-9
@@ -1,29 +1,30 @@
|
||||
version: "3.9"
|
||||
services:
|
||||
wk-seguros-api:
|
||||
demo-seguros-api:
|
||||
build: .
|
||||
container_name: wk-seguros-api
|
||||
container_name: demo-seguros-api
|
||||
ports:
|
||||
- "8002:8002"
|
||||
- "8003:8003"
|
||||
env_file:
|
||||
- .env
|
||||
volumes:
|
||||
- ./src:/app/src
|
||||
- ./web:/app/web
|
||||
depends_on:
|
||||
- wk-seguros-redis
|
||||
- demo-seguros-redis
|
||||
restart: unless-stopped
|
||||
networks:
|
||||
- default
|
||||
- evo-network
|
||||
wk-seguros-redis:
|
||||
demo-seguros-redis:
|
||||
image: redis:7-alpine
|
||||
container_name: wk-seguros-redis
|
||||
container_name: demo-seguros-redis
|
||||
restart: unless-stopped
|
||||
volumes:
|
||||
- wk-seguros-redis-data:/data
|
||||
- demo-seguros-redis-data:/data
|
||||
networks:
|
||||
- default
|
||||
volumes:
|
||||
wk-seguros-redis-data:
|
||||
demo-seguros-redis-data:
|
||||
networks:
|
||||
evo-network:
|
||||
external: true
|
||||
|
||||
+3
-3
@@ -20,7 +20,7 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
# ─── App FastAPI ──────────────────────────────────────────────────────────────
|
||||
app = FastAPI(
|
||||
title="WK Seguros Bot",
|
||||
title="Demo Seguros Bot",
|
||||
description="Bot de consulta de vencimientos de seguros vehiculares — WK Financing Solutions",
|
||||
version="1.2.0",
|
||||
)
|
||||
@@ -44,12 +44,12 @@ app.include_router(reminders_router, prefix="/api/v1")
|
||||
@app.get("/health")
|
||||
async def health_check():
|
||||
"""Endpoint de salud para verificar que el servicio está corriendo."""
|
||||
return {"status": "ok", "service": "wk-seguros-bot"}
|
||||
return {"status": "ok", "service": "demo-seguros-bot"}
|
||||
|
||||
|
||||
@app.on_event("startup")
|
||||
async def startup():
|
||||
logger.info("🚀 WK Seguros Bot iniciado en puerto 8002")
|
||||
logger.info("🚀 Demo Seguros Bot iniciado en puerto 8003")
|
||||
reminders_service.iniciar_scheduler()
|
||||
|
||||
|
||||
|
||||
@@ -238,7 +238,7 @@ async def generar_recordatorio(mes: int, anio: int) -> str:
|
||||
seccion_vencer, total_vencer = _formatear_seccion(por_vencer, "vencer")
|
||||
|
||||
# Armar mensaje final
|
||||
mensaje = f"""📅 Recordatorio WK Seguros — {nombre_mes} {anio}
|
||||
mensaje = f"""📅 Recordatorio Demo Seguros — {nombre_mes} {anio}
|
||||
|
||||
💳 POR PAGAR ESTE MES
|
||||
─────────────────────
|
||||
|
||||
@@ -20,7 +20,7 @@ def _get_redis() -> redis.Redis:
|
||||
global _cliente_redis
|
||||
if _cliente_redis is None:
|
||||
_cliente_redis = redis.from_url(
|
||||
os.environ.get("REDIS_URL", "redis://wk-seguros-redis:6379"),
|
||||
os.environ.get("REDIS_URL", "redis://demo-seguros-redis:6379"),
|
||||
decode_responses=True,
|
||||
)
|
||||
return _cliente_redis
|
||||
|
||||
@@ -1,142 +0,0 @@
|
||||
{
|
||||
"name": "WK Seguros Bot",
|
||||
"nodes": [
|
||||
{
|
||||
"parameters": {
|
||||
"httpMethod": "POST",
|
||||
"path": "wk-seguros",
|
||||
"responseMode": "responseNode",
|
||||
"options": {}
|
||||
},
|
||||
"id": "node-webhook-001",
|
||||
"name": "Webhook",
|
||||
"type": "n8n-nodes-base.webhook",
|
||||
"typeVersion": 2,
|
||||
"position": [250, 300]
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"mode": "rules",
|
||||
"rules": {
|
||||
"values": [
|
||||
{
|
||||
"conditions": {
|
||||
"options": {
|
||||
"caseSensitive": true,
|
||||
"leftValue": "",
|
||||
"typeValidation": "strict"
|
||||
},
|
||||
"conditions": [
|
||||
{
|
||||
"leftValue": "={{ true }}",
|
||||
"rightValue": true,
|
||||
"operator": {
|
||||
"type": "boolean",
|
||||
"operation": "true"
|
||||
}
|
||||
}
|
||||
],
|
||||
"combinator": "and"
|
||||
},
|
||||
"renameOutput": true,
|
||||
"outputKey": "ON"
|
||||
},
|
||||
{
|
||||
"conditions": {
|
||||
"options": {
|
||||
"caseSensitive": true,
|
||||
"leftValue": "",
|
||||
"typeValidation": "strict"
|
||||
},
|
||||
"conditions": [
|
||||
{
|
||||
"leftValue": "={{ false }}",
|
||||
"rightValue": false,
|
||||
"operator": {
|
||||
"type": "boolean",
|
||||
"operation": "false"
|
||||
}
|
||||
}
|
||||
],
|
||||
"combinator": "and"
|
||||
},
|
||||
"renameOutput": true,
|
||||
"outputKey": "OFF"
|
||||
}
|
||||
]
|
||||
},
|
||||
"options": {}
|
||||
},
|
||||
"id": "node-switch-002",
|
||||
"name": "Switch",
|
||||
"type": "n8n-nodes-base.switch",
|
||||
"typeVersion": 3,
|
||||
"position": [500, 300]
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"method": "POST",
|
||||
"url": "http://localhost:8002/webhook",
|
||||
"sendBody": true,
|
||||
"specifyBody": "json",
|
||||
"jsonBody": "={{ JSON.stringify($json) }}",
|
||||
"options": {}
|
||||
},
|
||||
"id": "node-fastapi-003",
|
||||
"name": "FastAPI",
|
||||
"type": "n8n-nodes-base.httpRequest",
|
||||
"typeVersion": 4.2,
|
||||
"position": [750, 300]
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"respondWith": "noData",
|
||||
"options": {}
|
||||
},
|
||||
"id": "node-respond-004",
|
||||
"name": "Respond",
|
||||
"type": "n8n-nodes-base.respondToWebhook",
|
||||
"typeVersion": 1,
|
||||
"position": [1000, 300]
|
||||
}
|
||||
],
|
||||
"connections": {
|
||||
"Webhook": {
|
||||
"main": [
|
||||
[
|
||||
{
|
||||
"node": "Switch",
|
||||
"type": "main",
|
||||
"index": 0
|
||||
}
|
||||
]
|
||||
]
|
||||
},
|
||||
"Switch": {
|
||||
"main": [
|
||||
[
|
||||
{
|
||||
"node": "FastAPI",
|
||||
"type": "main",
|
||||
"index": 0
|
||||
}
|
||||
]
|
||||
]
|
||||
},
|
||||
"FastAPI": {
|
||||
"main": [
|
||||
[
|
||||
{
|
||||
"node": "Respond",
|
||||
"type": "main",
|
||||
"index": 0
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
||||
},
|
||||
"active": false,
|
||||
"settings": {
|
||||
"executionOrder": "v1"
|
||||
}
|
||||
}
|
||||
@@ -1,121 +0,0 @@
|
||||
{
|
||||
"name": "WK Seguros Bot",
|
||||
"nodes": [
|
||||
{
|
||||
"parameters": {
|
||||
"httpMethod": "POST",
|
||||
"path": "wk-seguros",
|
||||
"responseMode": "responseNode",
|
||||
"options": {}
|
||||
},
|
||||
"id": "1a2b3c4d-0001-0001-0001-000000000001",
|
||||
"name": "Webhook",
|
||||
"type": "n8n-nodes-base.webhook",
|
||||
"typeVersion": 2,
|
||||
"position": [250, 300]
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"mode": "expression",
|
||||
"output": "={{ $('Switch').params.value1 }}",
|
||||
"rules": {
|
||||
"values": [
|
||||
{
|
||||
"conditions": {
|
||||
"options": {
|
||||
"caseSensitive": true,
|
||||
"leftValue": "",
|
||||
"typeValidation": "strict"
|
||||
},
|
||||
"conditions": [
|
||||
{
|
||||
"leftValue": "={{ true }}",
|
||||
"rightValue": true,
|
||||
"operator": {
|
||||
"type": "boolean",
|
||||
"operation": "true"
|
||||
}
|
||||
}
|
||||
],
|
||||
"combinator": "and"
|
||||
},
|
||||
"renameOutput": true,
|
||||
"outputKey": "ON"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"id": "1a2b3c4d-0002-0002-0002-000000000002",
|
||||
"name": "Switch",
|
||||
"type": "n8n-nodes-base.switch",
|
||||
"typeVersion": 3,
|
||||
"position": [500, 300]
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"method": "POST",
|
||||
"url": "http://localhost:8002/webhook",
|
||||
"sendBody": true,
|
||||
"contentType": "json",
|
||||
"body": "={{ JSON.stringify($json) }}",
|
||||
"options": {}
|
||||
},
|
||||
"id": "1a2b3c4d-0003-0003-0003-000000000003",
|
||||
"name": "FastAPI",
|
||||
"type": "n8n-nodes-base.httpRequest",
|
||||
"typeVersion": 4.2,
|
||||
"position": [750, 300]
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"respondWith": "json",
|
||||
"responseBody": "={{ JSON.stringify($json) }}",
|
||||
"options": {}
|
||||
},
|
||||
"id": "1a2b3c4d-0004-0004-0004-000000000004",
|
||||
"name": "Respond",
|
||||
"type": "n8n-nodes-base.respondToWebhook",
|
||||
"typeVersion": 1,
|
||||
"position": [1000, 300]
|
||||
}
|
||||
],
|
||||
"connections": {
|
||||
"Webhook": {
|
||||
"main": [
|
||||
[
|
||||
{
|
||||
"node": "Switch",
|
||||
"type": "main",
|
||||
"index": 0
|
||||
}
|
||||
]
|
||||
]
|
||||
},
|
||||
"Switch": {
|
||||
"main": [
|
||||
[
|
||||
{
|
||||
"node": "FastAPI",
|
||||
"type": "main",
|
||||
"index": 0
|
||||
}
|
||||
]
|
||||
]
|
||||
},
|
||||
"FastAPI": {
|
||||
"main": [
|
||||
[
|
||||
{
|
||||
"node": "Respond",
|
||||
"type": "main",
|
||||
"index": 0
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
||||
},
|
||||
"active": false,
|
||||
"settings": {
|
||||
"executionOrder": "v1"
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user