diff --git a/src/server.ts b/src/server.ts index 5c92e67..0ae4eb7 100644 --- a/src/server.ts +++ b/src/server.ts @@ -39,22 +39,23 @@ export class WebhookServer { } if (process.env.NODE_ENV !== 'test') { - console.log('ℹ️ Incoming webhook request:', { - method: request.method, - path: url.pathname, - time: new Date().toISOString() - }); + console.log('ℹ️ Incoming webhook request:') + // console.log('ℹ️ Incoming webhook request:', { + // method: request.method, + // path: url.pathname, + // time: new Date().toISOString() + // }); } // 1. Method validation if (request.method !== 'POST') { - return new Response('Method not allowed', { status: 405 }); + return new Response('🚫 Method not allowed', { status: 405 }); } // 2. Content-Type validation const contentType = request.headers.get('content-type'); if (!contentType?.includes('application/json')) { - return new Response('Invalid content type', { status: 400 }); + return new Response('🚫 Invalid content type', { status: 400 }); } try { @@ -62,13 +63,13 @@ export class WebhookServer { const payload = await request.json() as WebhookPayload; if (!payload.event || !payload.instance) { - return new Response('Invalid payload', { status: 400 }); + return new Response('🚫 Invalid payload', { status: 400 }); } // 4. Verify instance matches (skip in test environment unless TEST_VERIFY_INSTANCE is set) if ((process.env.NODE_ENV !== 'test' || process.env.TEST_VERIFY_INSTANCE) && payload.instance !== process.env.EVOLUTION_API_INSTANCE) { - return new Response('Invalid instance', { status: 403 }); + return new Response('🚫 Invalid instance', { status: 403 }); } // 5. Route events @@ -114,7 +115,7 @@ export class WebhookServer { // Parse command components const commandParts = messageText.trim().split(/\s+/); const command = commandParts[0].toLowerCase(); - + if (commandParts.length < 2) { console.log('⚠️ Invalid /tarea command - missing action'); return; @@ -123,7 +124,7 @@ export class WebhookServer { const action = commandParts[1].toLowerCase(); let descriptionParts = []; let dueDate = ''; - + // Process remaining parts for (let i = 2; i < commandParts.length; i++) { const part = commandParts[i]; @@ -132,7 +133,7 @@ export class WebhookServer { const date = new Date(part); const today = new Date(); today.setHours(0, 0, 0, 0); - + if (date >= today) { dueDate = part; } else {