diff --git a/src/services/taskService.ts b/src/services/taskService.ts index 4450e5f..f2faa1a 100644 --- a/src/services/taskService.ts +++ b/src/services/taskService.ts @@ -4,8 +4,16 @@ import { notifyTaskCreation, notifyTaskAssignment, notifyTaskCompletion } from ' // Create a new task export function createTask(sender: string, params: CreateTaskParams) { - const createdBy = normalizeUserIdentifier(sender); - const assignedTo = params.assignedTo ? normalizeUserIdentifier(params.assignedTo) : null; + let createdBy = sender; + let assignedTo = params.assignedTo || null; + + // Only normalize if it's a user JID, not a group JID + if (!createdBy.endsWith('@g.us')) { + createdBy = normalizeUserIdentifier(createdBy); + } + if (assignedTo && !assignedTo.endsWith('@g.us')) { + assignedTo = normalizeUserIdentifier(assignedTo); + } if (!params.description || params.description.trim().length < 3) { throw new Error('La descripción de la tarea debe tener al menos 3 caracteres'); } diff --git a/src/utils/userUtils.ts b/src/utils/userUtils.ts index ad5efb0..7b87b44 100644 --- a/src/utils/userUtils.ts +++ b/src/utils/userUtils.ts @@ -1,17 +1,20 @@ export function normalizeUserIdentifier(input: string): string { console.log('Normalizing user identifier:', input); - // Handle JID format (12345678@s.whatsapp.net) + // Handle group JID format (120363418564126395@g.us) + if (input.endsWith('@g.us')) { + return input; // Return group JID as-is + } + + // Handle user JID format (12345678@s.whatsapp.net) if (input.includes('@s.whatsapp.net')) { const [phone, domain] = input.split('@'); const cleanPhone = phone.replace(/\D/g, ''); return `${cleanPhone}@${domain}`; } - // Remove @ prefix if present + // Handle raw input (phone number or @mention) const cleanInput = input.startsWith('@') ? input.slice(1) : input; - - // Remove any non-numeric characters const phoneNumber = cleanInput.replace(/\D/g, ''); // Validate phone number length