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); + } }