fix: handle group JIDs properly in user normalization

main
brobert (aider) 3 months ago
parent 3a5991ade5
commit e6b062a2b6

@ -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');
}

@ -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

Loading…
Cancel
Save