|
|
|
@ -9,9 +9,16 @@ export function handleTaskCommand(body: string, sender: string, groupId: string,
|
|
|
|
|
const [action, ...args] = command.split(' ');
|
|
|
|
|
const description = args.join(' ');
|
|
|
|
|
|
|
|
|
|
const assignedUserMatch = description.match(/@\w+/);
|
|
|
|
|
// Extract WhatsApp mention (format: @<phone_number>)
|
|
|
|
|
const assignedUserMatch = description.match(/@\d+/);
|
|
|
|
|
const assignedUser = assignedUserMatch ? assignedUserMatch[0] : null;
|
|
|
|
|
|
|
|
|
|
// Validate phone number format
|
|
|
|
|
if (assignedUser && !/^@\d{8,}$/.test(assignedUser)) {
|
|
|
|
|
sendMessage(sender, 'Formato de mención inválido. Usa @ seguido del número de teléfono');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const dueDateMatch = description.match(/\d{4}-\d{2}-\d{2}/);
|
|
|
|
|
const dueDate = dueDateMatch ? dueDateMatch[0] : null;
|
|
|
|
|
|
|
|
|
@ -40,17 +47,23 @@ export function handleTaskCommand(body: string, sender: string, groupId: string,
|
|
|
|
|
sendMessage(sender, `❌ Error al crear la tarea: ${error.message}`);
|
|
|
|
|
}
|
|
|
|
|
} else if (action === 'asignar') {
|
|
|
|
|
const taskId = args[0];
|
|
|
|
|
if (assignedUser) {
|
|
|
|
|
assignTask(parseInt(taskId), assignedUser);
|
|
|
|
|
sendMessage(sender, `Tarea ${taskId} asignada a ${assignedUser}`);
|
|
|
|
|
} else {
|
|
|
|
|
sendMessage(sender, 'Debes mencionar a un usuario para asignar la tarea. Ejemplo: /tarea asignar 1 @usuario');
|
|
|
|
|
try {
|
|
|
|
|
const taskId = validateTaskId(args[0]);
|
|
|
|
|
if (!assignedUser) {
|
|
|
|
|
throw new Error('Debes mencionar a un usuario para asignar la tarea. Ejemplo: /tarea asignar 1 @12345678');
|
|
|
|
|
}
|
|
|
|
|
} else if (action === 'lista' || (!action && args.length === 1 && !isNaN(Number(args[0])))) {
|
|
|
|
|
|
|
|
|
|
assignTask(taskId, assignedUser);
|
|
|
|
|
sendMessage(sender, `✅ Tarea ${taskId} asignada a ${assignedUser}`);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('Error assigning task:', error);
|
|
|
|
|
sendMessage(sender, `❌ Error al asignar tarea: ${error.message}`);
|
|
|
|
|
}
|
|
|
|
|
} else if (action === 'lista' || (!action && args.length === 1)) {
|
|
|
|
|
// Handle both /tarea lista 14 and /tarea 14
|
|
|
|
|
const taskId = args[0];
|
|
|
|
|
const task = getTaskById(parseInt(taskId));
|
|
|
|
|
try {
|
|
|
|
|
const taskId = validateTaskId(args[0]);
|
|
|
|
|
const task = getTaskById(taskId);
|
|
|
|
|
|
|
|
|
|
if (!task) {
|
|
|
|
|
sendMessage(sender, `Tarea ${taskId} no encontrada`);
|
|
|
|
|