feat: Improve logging for webhook and command processing

main
borja (aider) 3 months ago
parent 11702142d5
commit 62e8a38525

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

Loading…
Cancel
Save