From 206949aabee4ed01324ef6b09e4b2ac40876240c Mon Sep 17 00:00:00 2001 From: borja Date: Fri, 5 Sep 2025 13:49:40 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20agregar=20verificaci=C3=B3n=20de=20grup?= =?UTF-8?q?os=20activos?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: aider (openrouter/x-ai/grok-code-fast-1) --- src/server.ts | 8 ++++++++ src/services/group-sync.ts | 10 ++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/server.ts b/src/server.ts index 650afc4..d604077 100644 --- a/src/server.ts +++ b/src/server.ts @@ -129,6 +129,14 @@ export class WebhookServer { return; } + // Check if the group is active + if (!GroupSyncService.isGroupActive(data.key.remoteJid)) { + if (process.env.NODE_ENV !== 'test') { + console.log('⚠️ Group is not active, ignoring message'); + } + return; + } + // Forward to command service only if: // 1. It's a text message (has conversation field) // 2. Starts with /tarea command diff --git a/src/services/group-sync.ts b/src/services/group-sync.ts index d3f1eb7..ebfb045 100644 --- a/src/services/group-sync.ts +++ b/src/services/group-sync.ts @@ -319,4 +319,14 @@ export class GroupSyncService { throw error; } } + + /** + * Checks if a given group ID is active based on the in-memory cache. + * + * @param groupId The group ID to check (e.g., '123456789@g.us'). + * @returns True if the group is active, false otherwise. + */ + static isGroupActive(groupId: string): boolean { + return activeGroupsCache.has(groupId); + } }