|
|
|
@ -48,10 +48,15 @@ export async function handleTaskCommand(body: string, sender: string, groupId: s
|
|
|
|
|
const dueDateMatch = description.match(/\d{4}-\d{2}-\d{2}/);
|
|
|
|
|
const dueDate = dueDateMatch ? dueDateMatch[0] : null;
|
|
|
|
|
|
|
|
|
|
const cleanDescription = description
|
|
|
|
|
.replace(/@\w+/g, '')
|
|
|
|
|
.replace(/\d{4}-\d{2}-\d{2}/g, '')
|
|
|
|
|
.trim();
|
|
|
|
|
// Extract and clean description - remove mentions and dates
|
|
|
|
|
let cleanDescription = description;
|
|
|
|
|
if (assignedUserMatch) {
|
|
|
|
|
cleanDescription = cleanDescription.replace(assignedUserMatch[0], '').trim();
|
|
|
|
|
}
|
|
|
|
|
if (dueDateMatch) {
|
|
|
|
|
cleanDescription = cleanDescription.replace(dueDateMatch[0], '').trim();
|
|
|
|
|
}
|
|
|
|
|
cleanDescription = cleanDescription.trim();
|
|
|
|
|
|
|
|
|
|
if (!action || action === 'mostrar') {
|
|
|
|
|
// Handle bare /tarea or /tarea mostrar
|
|
|
|
@ -73,16 +78,23 @@ export async function handleTaskCommand(body: string, sender: string, groupId: s
|
|
|
|
|
dueDate: dueDate || undefined
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
let message = `✅ Tarea creada:\nID: ${task.id}\nDescripción: ${task.description}`;
|
|
|
|
|
if (task.assignedTo) message += `\nAsignada a: ${task.assignedTo}`;
|
|
|
|
|
if (task.dueDate) message += `\nFecha límite: ${task.dueDate}`;
|
|
|
|
|
message += `\nCreada: ${task.createdAt}`;
|
|
|
|
|
// Format the message with proper text property
|
|
|
|
|
const message = {
|
|
|
|
|
text: `✅ Tarea creada:\nID: ${task.id}\nDescripción: ${task.description}` +
|
|
|
|
|
(task.assignedTo ? `\nAsignada a: ${formatUserMention(task.assignedTo)}` : '') +
|
|
|
|
|
(task.dueDate ? `\nFecha límite: ${task.dueDate}` : '') +
|
|
|
|
|
`\nCreada: ${task.createdAt}`
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Send confirmation privately to creator
|
|
|
|
|
sendMessage(sender, message);
|
|
|
|
|
sendMessage(sender, message.text);
|
|
|
|
|
// Also notify assignee if different from creator
|
|
|
|
|
if (assignedUser && assignedUser !== `@${sender.split('@')[0]}`) {
|
|
|
|
|
sendMessage(assignedUser, `📝 Se te ha asignado una nueva tarea:\n${message}`, [assignedUser.split('@')[0]]);
|
|
|
|
|
const assigneeMessage = {
|
|
|
|
|
text: `📝 Se te ha asignado una nueva tarea:\n${message.text}`,
|
|
|
|
|
mentions: [assignedUser]
|
|
|
|
|
};
|
|
|
|
|
sendMessage(assignedUser, assigneeMessage.text, assigneeMessage.mentions);
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('Error creating task:', error);
|
|
|
|
|