- **User validation integration**: Normalization and `ensureUserExists` are now fully integrated in the main message handling flow (`src/server.ts`).
@ -103,10 +103,9 @@ Estado: la tabla response_queue ya está creada e incluida en los tests de DB.
- **Database isolation in unit tests**: Implemented using in-memory instances to avoid conflicts between tests.
### Incomplete / Missing Core Functionality
- **User/Group Validation Integration:** Although normalization (`normalizeWhatsAppId`) and user creation (`ensureUserExists`) functions exist, they are **not yet integrated** into the main request handling flow in `src/server.ts` to validate senders or automatically add users on first message. Similarly, the active group cache from `group-sync.ts` is **not yet used** in `src/server.ts` to filter messages from inactive/unknown groups.
- **Filtro de grupos activos:** La sincronización existe y hay caché; queda por reforzar el uso del filtro de grupos activos en `src/server.ts` si se requiere un bloqueo más estricto.
- **Core Command Logic:** Actual processing of `/tarea nueva` (parsing args, calling `TaskService`) is missing in `CommandService`. Other commands (`mostrar`, `completar`) not implemented.
- **Task Service Implementation:**`TaskService` needs updating to handle `created_by`, assignments, and potentially methods for listing/completing tasks.
- **Response Sending:**`ResponseQueue` does not yet send messages back via the Evolution API.
- **Database Migrations:** No system in place to manage schema changes.
- **Robust Error Handling:** Comprehensive error handling, logging, and transaction management need improvement, especially around API calls and DB operations.
@ -158,21 +157,20 @@ bun test
- [x] **Integrate Validation in Server:** (`src/server.ts`) Use normalization, `ensureUserExists`, and active group check before processing commands.
- [x] **Implement DB isolation in tests:** (`tests/unit/services/group-sync.test.ts`) Use in-memory instances to avoid conflicts.
- [ ] **Trigger Queue Processing:** (`src/server.ts`) Call `ResponseQueue.process()` after command handling.
- [ ] **Persist Response Queue in Database:** (`src/services/response-queue.ts`, `src/db.ts`) Add table for queued responses to avoid loss on server restart (important for reliability).
### Phase 3: Comandos adicionales y refinamientos (Alta prioridad)
- [ ] Implementar `/tarea mostrar [group|mine]` para listar pendientes.
- [ ] Implementar `/tarea completar <task_id>` con validaciones básicas.
- [ ] Soportar mensajes de texto extendido y captions de media (además de conversation).
### Phase 4: Further Commands & Refinements (Medium Priority)
### Phase 4: Fiabilidad de la cola y observabilidad (Media)
- [ ] Añadir reintentos con backoff exponencial y jitter.
- [ ] Recuperar ítems en estado `processing` tras reinicios (lease o expiración y requeue).
- [ ] Métricas y logging mejorado (contadores de enviados/fallidos, tiempos).
- [ ] Limpieza/retención de historiales.
### Phase 5: Advanced Features (Low Priority)
- [ ] Add task reminders system.
@ -183,7 +181,7 @@ bun test
## 🔑 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.
* **Response Queue Persistence:** Currently in-memory; consider persisting in DB to prevent message loss on restarts (added to Phase 3 roadmap).
* **Cola de respuestas:** Persistente en DB; pendiente añadir reintentos/backoff y limpieza/retención.
* **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.