|
|
@ -113,23 +113,36 @@ export class WebhookServer {
|
|
|
|
const commandParts = messageText.trim().split(/\s+/);
|
|
|
|
const commandParts = messageText.trim().split(/\s+/);
|
|
|
|
const command = commandParts[0].toLowerCase();
|
|
|
|
const command = commandParts[0].toLowerCase();
|
|
|
|
|
|
|
|
|
|
|
|
// Extract due date if present (format: YYYY-MM-DD)
|
|
|
|
if (commandParts.length < 2) {
|
|
|
|
|
|
|
|
console.log('⚠️ Invalid /tarea command - missing action');
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const action = commandParts[1].toLowerCase();
|
|
|
|
|
|
|
|
let descriptionParts = [];
|
|
|
|
let dueDate = '';
|
|
|
|
let dueDate = '';
|
|
|
|
const dateRegex = /(\d{4}-\d{2}-\d{2})/;
|
|
|
|
|
|
|
|
const dateIndex = commandParts.findIndex(p => dateRegex.test(p));
|
|
|
|
// Process remaining parts
|
|
|
|
|
|
|
|
for (let i = 2; i < commandParts.length; i++) {
|
|
|
|
if (dateIndex >= 0) {
|
|
|
|
const part = commandParts[i];
|
|
|
|
const dateStr = commandParts[dateIndex];
|
|
|
|
// Check for date (YYYY-MM-DD)
|
|
|
|
const date = new Date(dateStr);
|
|
|
|
if (/^\d{4}-\d{2}-\d{2}$/.test(part)) {
|
|
|
|
const today = new Date();
|
|
|
|
const date = new Date(part);
|
|
|
|
today.setHours(0, 0, 0, 0);
|
|
|
|
const today = new Date();
|
|
|
|
|
|
|
|
today.setHours(0, 0, 0, 0);
|
|
|
|
if (date >= today) {
|
|
|
|
|
|
|
|
dueDate = dateStr;
|
|
|
|
if (date >= today) {
|
|
|
|
commandParts.splice(dateIndex, 1); // Remove date from parts
|
|
|
|
dueDate = part;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
descriptionParts.push(part); // Keep past dates in description
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
descriptionParts.push(part);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const description = descriptionParts.join(' ');
|
|
|
|
|
|
|
|
|
|
|
|
console.log('🔍 Detected /tarea command:', {
|
|
|
|
console.log('🔍 Detected /tarea command:', {
|
|
|
|
timestamp: new Date().toISOString(),
|
|
|
|
timestamp: new Date().toISOString(),
|
|
|
|
from: data.key.participant,
|
|
|
|
from: data.key.participant,
|
|
|
@ -137,10 +150,6 @@ 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,
|
|
|
|