fix: improve task assignment with flexible user identifier handling

main
brobert (aider) 3 months ago
parent 585f073697
commit b57dc0e6a4

@ -22,12 +22,20 @@ export function handleTaskCommand(body: string, sender: string, groupId: string,
// Extract WhatsApp mention (format: @<phone_number>) // Extract WhatsApp mention (format: @<phone_number>)
const assignedUserMatch = description.match(/@\d+/); const assignedUserMatch = description.match(/@\d+/);
const assignedUser = assignedUserMatch ? assignedUserMatch[0] : null; let assignedUser = null;
// Validate phone number format if (assignedUserMatch) {
if (assignedUser && !/^@\d{8,}$/.test(assignedUser)) { try {
sendMessage(sender, 'Formato de mención inválido. Usa @ seguido del número de teléfono'); assignedUser = normalizeUserIdentifier(assignedUserMatch[0]);
return; // Check if assigned user is in the community
if (!linkedGroups.has(`${assignedUser.replace('@', '')}@s.whatsapp.net`)) {
sendMessage(sender, `El usuario ${assignedUser} no está en la comunidad`);
return;
}
} catch (error) {
sendMessage(sender, `Formato de mención inválido: ${error.message}`);
return;
}
} }
const dueDateMatch = description.match(/\d{4}-\d{2}-\d{2}/); const dueDateMatch = description.match(/\d{4}-\d{2}-\d{2}/);
@ -51,7 +59,7 @@ export function handleTaskCommand(body: string, sender: string, groupId: string,
} }
} else if (action === 'nueva') { } else if (action === 'nueva') {
try { try {
const finalAssignedUser = assignedUser || `@${sender.split('@')[0]}`; const finalAssignedUser = assignedUser || normalizeUserIdentifier(sender);
const task = createTask(sender, { const task = createTask(sender, {
description: cleanDescription, description: cleanDescription,
assignedTo: finalAssignedUser, assignedTo: finalAssignedUser,

@ -1,4 +1,9 @@
export function normalizeUserIdentifier(input: string): string { export function normalizeUserIdentifier(input: string): string {
// Handle JID format (12345678@s.whatsapp.net)
if (input.includes('@s.whatsapp.net')) {
return `@${input.split('@')[0]}`;
}
// Remove @ prefix if present // Remove @ prefix if present
const cleanInput = input.startsWith('@') ? input.slice(1) : input; const cleanInput = input.startsWith('@') ? input.slice(1) : input;

Loading…
Cancel
Save