|
|
|
@ -153,26 +153,63 @@ export class CommandService {
|
|
|
|
|
|
|
|
|
|
|
|
const mentionsForSending = assignmentUserIds.map(uid => `${uid}@s.whatsapp.net`);
|
|
|
|
const mentionsForSending = assignmentUserIds.map(uid => `${uid}@s.whatsapp.net`);
|
|
|
|
|
|
|
|
|
|
|
|
const assignedLabels = await Promise.all(
|
|
|
|
// Resolver nombres útiles
|
|
|
|
|
|
|
|
const creatorName = await ContactsService.getDisplayName(createdBy);
|
|
|
|
|
|
|
|
const groupName = groupIdToUse ? GroupSyncService.activeGroupsCache.get(groupIdToUse) : null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const assignedDisplayNames = await Promise.all(
|
|
|
|
assignmentUserIds.map(async uid => {
|
|
|
|
assignmentUserIds.map(async uid => {
|
|
|
|
const name = await ContactsService.getDisplayName(uid);
|
|
|
|
const name = await ContactsService.getDisplayName(uid);
|
|
|
|
return `@${name || uid}`;
|
|
|
|
return name || uid;
|
|
|
|
})
|
|
|
|
})
|
|
|
|
);
|
|
|
|
);
|
|
|
|
const assignedList = assignedLabels.join(' ');
|
|
|
|
|
|
|
|
const resp =
|
|
|
|
|
|
|
|
`✅ Tarea ${taskId} creada: "${description || '(sin descripción)'}"` +
|
|
|
|
|
|
|
|
(dueDate ? ` (vence ${dueDate})` : '') +
|
|
|
|
|
|
|
|
(assignedList ? ` — asignados: ${assignedList}` : '');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Responder siempre por privado al creador (DM)
|
|
|
|
const responses: CommandResponse[] = [];
|
|
|
|
const recipient = createdBy;
|
|
|
|
|
|
|
|
|
|
|
|
// 1) Ack al creador, salvo que él sea el único asignado
|
|
|
|
|
|
|
|
const creatorIsOnlyAssignee = assignmentUserIds.length === 1 && assignmentUserIds[0] === createdBy;
|
|
|
|
|
|
|
|
if (!creatorIsOnlyAssignee) {
|
|
|
|
|
|
|
|
responses.push({
|
|
|
|
|
|
|
|
recipient: createdBy,
|
|
|
|
|
|
|
|
message:
|
|
|
|
|
|
|
|
`✅ Tarea ${taskId} creada:\n` +
|
|
|
|
|
|
|
|
`• ${description || '(sin descripción)'}\n` +
|
|
|
|
|
|
|
|
(dueDate ? `• Vence: ${dueDate}\n` : '') +
|
|
|
|
|
|
|
|
(assignedDisplayNames.length ? `• Asignados: ${assignedDisplayNames.join(', ')}` : '')
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return [{
|
|
|
|
// 2) DM a cada asignado
|
|
|
|
recipient,
|
|
|
|
for (const uid of assignmentUserIds) {
|
|
|
|
message: resp,
|
|
|
|
responses.push({
|
|
|
|
|
|
|
|
recipient: uid,
|
|
|
|
|
|
|
|
message:
|
|
|
|
|
|
|
|
`🆕 Nueva tarea:\n` +
|
|
|
|
|
|
|
|
`• ${description || '(sin descripción)'}\n` +
|
|
|
|
|
|
|
|
(dueDate ? `• Vence: ${dueDate}\n` : '') +
|
|
|
|
|
|
|
|
`• Asignada por: ${creatorName || createdBy}` +
|
|
|
|
|
|
|
|
(groupName ? `\n• Grupo: ${groupName}` : '')
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 3) Opcional: mensaje al grupo con menciones para visibilidad
|
|
|
|
|
|
|
|
if (groupIdToUse && process.env.NOTIFY_GROUP_ON_CREATE === 'true') {
|
|
|
|
|
|
|
|
const assignNamesForGroup = await Promise.all(
|
|
|
|
|
|
|
|
assignmentUserIds.map(async uid => '@' + (await ContactsService.getDisplayName(uid) || uid))
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
responses.push({
|
|
|
|
|
|
|
|
recipient: groupIdToUse,
|
|
|
|
|
|
|
|
message:
|
|
|
|
|
|
|
|
`📝 Tarea ${taskId} creada por ${creatorName || createdBy}:\n` +
|
|
|
|
|
|
|
|
`• ${description || '(sin descripción)'}\n` +
|
|
|
|
|
|
|
|
(dueDate ? `• Vence: ${dueDate}\n` : '') +
|
|
|
|
|
|
|
|
(assignNamesForGroup.length ? `• Asignados: ${assignNamesForGroup.join(' ')}` : ''),
|
|
|
|
mentions: mentionsForSending.length > 0 ? mentionsForSending : undefined
|
|
|
|
mentions: mentionsForSending.length > 0 ? mentionsForSending : undefined
|
|
|
|
}];
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return responses;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static async handle(context: CommandContext): Promise<CommandResponse[]> {
|
|
|
|
static async handle(context: CommandContext): Promise<CommandResponse[]> {
|
|
|
|
|