diff --git a/src/server.ts b/src/server.ts index fdfb429..706ac6e 100644 --- a/src/server.ts +++ b/src/server.ts @@ -3,6 +3,7 @@ import { CommandService } from './services/command'; import { GroupSyncService } from './services/group-sync'; import { ResponseQueue } from './services/response-queue'; import { WebhookManager } from './services/webhook-manager'; +import { normalizeWhatsAppId } from './utils/whatsapp'; // Bun is available globally when running under Bun runtime declare global { @@ -107,6 +108,15 @@ export class WebhookServer { return; } + // Normalize sender ID for consistency and validation + const normalizedSenderId = normalizeWhatsAppId(data.key.participant); + if (!normalizedSenderId) { + if (process.env.NODE_ENV !== 'test') { + console.log('⚠️ Invalid sender ID, ignoring message'); + } + return; + } + // Forward to command service only if: // 1. It's a text message (has conversation field) // 2. Starts with /tarea command