diff --git a/src/server.ts b/src/server.ts index 2a79e39..ab80fe9 100644 --- a/src/server.ts +++ b/src/server.ts @@ -38,13 +38,11 @@ export class WebhookServer { return new Response('OK', { status: 200 }); } - // Debug logging for all incoming requests - // console.log('ℹ️ Incoming request:', { - // method: request.method, - // path: url.pathname, - // headers: Object.fromEntries(request.headers), - // query: Object.fromEntries(url.searchParams) - // }); + console.log('ℹ️ Incoming webhook request:', { + method: request.method, + path: url.pathname, + time: new Date().toISOString() + }); // 1. Method validation if (request.method !== 'POST') { @@ -91,13 +89,20 @@ export class WebhookServer { return new Response('OK', { status: 200 }); } catch (error) { + console.error('❌ Error processing webhook:', { + error: error instanceof Error ? error.message : String(error), + stack: error instanceof Error ? error.stack : undefined, + time: new Date().toISOString() + }); return new Response('Invalid request', { status: 400 }); } } private static async handleMessageUpsert(data: any) { - // Basic message validation - if (!data?.key?.remoteJid || !data.message || !data.message.conversation) return; + if (!data?.key?.remoteJid || !data.message || !data.message.conversation) { + console.log('⚠️ Invalid message format - missing required fields'); + return; + } // Forward to command service only if: // 1. It's a text message (has conversation field) @@ -116,15 +121,18 @@ export class WebhookServer { dueDate = dueDateMatch[1]; } - console.log('📝 /tarea command received:', { + console.log('🔍 Detected /tarea command:', { timestamp: new Date().toISOString(), - sender: data.key.participant, + from: data.key.participant, group: data.key.remoteJid, - command: command, - arguments: args, + rawMessage: messageText + }); + + console.log('✅ Successfully parsed command:', { + action, + description, dueDate: dueDate || 'none', - mentions: data.contextInfo?.mentionedJid || [], - fullMessage: messageText + mentionCount: mentions.length }); const responses = await CommandService.handle({