From bff4c99876daf3c0a9176af231f1e8bc46cfb67b Mon Sep 17 00:00:00 2001 From: borja Date: Sun, 7 Sep 2025 16:26:09 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20hacer=20din=C3=A1mico=20el=20mensaje=20?= =?UTF-8?q?del=20l=C3=ADmite=20por=20minuto=20y=20README?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: aider (openrouter/openai/gpt-5) --- README.md | 6 +++--- src/server.ts | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c2ceb8d..6ac8302 100644 --- a/README.md +++ b/README.md @@ -99,9 +99,9 @@ Consulta .env.example para un listado comentado con valores de ejemplo. - Objetivo: trazabilidad de cambios. - Implica: tabla task_events; eventos en crear/asignar/tomar/soltar/completar; consulta “historial”. -8) Rate limiting (operación segura) +8) Rate limiting (operación segura) — completado - Objetivo: proteger ante abuso o loops. -- Implica: token bucket por usuario/grupo; configuración de límites. +- Implementado: token bucket por usuario con límites configurables (RATE_LIMIT_PER_MIN, RATE_LIMIT_BURST) y aviso con cooldown. 9) Sincronización de miembros (opcional) - Objetivo: conocer miembros activos por grupo para features avanzadas. @@ -114,7 +114,7 @@ Consulta .env.example para un listado comentado con valores de ejemplo. ## 🔑 Key Considerations & Caveats * **WhatsApp ID Normalization:** Crucial for consistently identifying users and groups. Needs careful implementation to handle edge cases. (Utility function exists). * **Response Latency:** Sending responses requires an API call back to Evolution. Ensure the `ResponseQueue` processing is efficient. -* **Cola de respuestas:** Persistente en DB; pendiente añadir reintentos/backoff y limpieza/retención. +* **Cola de respuestas:** Persistente en DB; con reintentos (backoff exponencial + jitter), recuperación tras reinicios y limpieza/retención configurables. * **Group Sync:** The current full sync might be slow or rate-limited with many groups. Delta updates are recommended long-term. * **Error Handling:** Failures in command processing or response sending should be logged clearly and potentially reported back to the user. Database operations should use transactions for atomicity (especially task+assignment creation). * **State Management:** The current design is stateless. Complex interactions might require state persistence later. diff --git a/src/server.ts b/src/server.ts index f60add6..30a1340 100644 --- a/src/server.ts +++ b/src/server.ts @@ -225,7 +225,7 @@ export class WebhookServer { if (RateLimiter.shouldNotify(normalizedSenderId)) { await ResponseQueue.add([{ recipient: normalizedSenderId, - message: 'Has superado el límite de 15 comandos por minuto. Inténtalo de nuevo en un momento.' + message: `Has superado el límite de ${((() => { const v = Number(process.env.RATE_LIMIT_PER_MIN); return Number.isFinite(v) && v > 0 ? v : 15; })())} comandos por minuto. Inténtalo de nuevo en un momento.` }]); } return;