From 163c2b183f9b5ba36b775ecac4383b9e43a72e95 Mon Sep 17 00:00:00 2001 From: "borja (aider)" Date: Fri, 28 Mar 2025 16:20:22 +0100 Subject: [PATCH] fix: properly parse command action and due date in webhook handler --- src/server.ts | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/server.ts b/src/server.ts index ab80fe9..253d0f8 100644 --- a/src/server.ts +++ b/src/server.ts @@ -112,13 +112,22 @@ export class WebhookServer { // Parse command components const commandParts = messageText.trim().split(/\s+/); const command = commandParts[0].toLowerCase(); - const args = commandParts.slice(1).join(' '); - // Extract due date if present (format: /tarea [due:YYYY-MM-DD] description) + // Extract due date if present (format: YYYY-MM-DD) let dueDate = ''; - const dueDateMatch = args.match(/due:(\d{4}-\d{2}-\d{2})/i); - if (dueDateMatch) { - dueDate = dueDateMatch[1]; + const dateRegex = /(\d{4}-\d{2}-\d{2})/; + const dateIndex = commandParts.findIndex(p => dateRegex.test(p)); + + if (dateIndex >= 0) { + const dateStr = commandParts[dateIndex]; + const date = new Date(dateStr); + const today = new Date(); + today.setHours(0, 0, 0, 0); + + if (date >= today) { + dueDate = dateStr; + commandParts.splice(dateIndex, 1); // Remove date from parts + } } console.log('🔍 Detected /tarea command:', { @@ -128,11 +137,15 @@ export class WebhookServer { rawMessage: messageText }); + // Extract action (first word after /tarea) + const action = commandParts.length > 1 ? commandParts[1] : 'none'; + const description = commandParts.slice(2).join(' '); + console.log('✅ Successfully parsed command:', { action, description, dueDate: dueDate || 'none', - mentionCount: mentions.length + mentionCount: data.contextInfo?.mentionedJid?.length || 0 }); const responses = await CommandService.handle({