fix: properly parse command action and due date in webhook handler

main
borja (aider) 3 months ago
parent 62e8a38525
commit 163c2b183f

@ -112,13 +112,22 @@ export class WebhookServer {
// Parse command components // Parse command components
const commandParts = messageText.trim().split(/\s+/); const commandParts = messageText.trim().split(/\s+/);
const command = commandParts[0].toLowerCase(); 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 = ''; let dueDate = '';
const dueDateMatch = args.match(/due:(\d{4}-\d{2}-\d{2})/i); const dateRegex = /(\d{4}-\d{2}-\d{2})/;
if (dueDateMatch) { const dateIndex = commandParts.findIndex(p => dateRegex.test(p));
dueDate = dueDateMatch[1];
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:', { console.log('🔍 Detected /tarea command:', {
@ -128,11 +137,15 @@ export class WebhookServer {
rawMessage: messageText 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:', { console.log('✅ Successfully parsed command:', {
action, action,
description, description,
dueDate: dueDate || 'none', dueDate: dueDate || 'none',
mentionCount: mentions.length mentionCount: data.contextInfo?.mentionedJid?.length || 0
}); });
const responses = await CommandService.handle({ const responses = await CommandService.handle({

Loading…
Cancel
Save