diff --git a/src/server.ts b/src/server.ts index d0061aa..373f15f 100644 --- a/src/server.ts +++ b/src/server.ts @@ -322,6 +322,23 @@ export class WebhookServer { } } + // Etapa 3: Gating en modo 'enforce' — ignorar mensajes de grupos no permitidos + if (isGroupId(remoteJid)) { + try { (AllowedGroups as any).dbInstance = WebhookServer.dbInstance; } catch {} + const gatingMode2 = String(process.env.GROUP_GATING_MODE || 'off').toLowerCase(); + if (gatingMode2 === 'enforce') { + try { + const allowed = AllowedGroups.isAllowed(remoteJid); + if (!allowed) { + try { Metrics.inc('messages_blocked_group_total'); } catch {} + return; + } + } catch { + // Si falla el check por cualquier motivo, ser conservadores y permitir + } + } + } + // Check/ensure group exists (allow DMs always) if (isGroupId(data.key.remoteJid) && !GroupSyncService.isGroupActive(data.key.remoteJid)) { // En tests, mantener comportamiento anterior: ignorar mensajes de grupos inactivos