feat: implement proper user mentions using full JIDs in messages

main
brobert (aider) 3 months ago
parent b57dc0e6a4
commit eae38cff2e

@ -28,8 +28,8 @@ export function handleTaskCommand(body: string, sender: string, groupId: string,
try { try {
assignedUser = normalizeUserIdentifier(assignedUserMatch[0]); assignedUser = normalizeUserIdentifier(assignedUserMatch[0]);
// Check if assigned user is in the community // Check if assigned user is in the community
if (!linkedGroups.has(`${assignedUser.replace('@', '')}@s.whatsapp.net`)) { if (!linkedGroups.has(assignedUser)) {
sendMessage(sender, `El usuario ${assignedUser} no está en la comunidad`); sendMessage(sender, `El usuario ${formatUserMention(assignedUser)} no está en la comunidad`);
return; return;
} }
} catch (error) { } catch (error) {

@ -11,13 +11,22 @@ if (!API_URL || !INSTANCE_NAME || !API_KEY) {
throw new Error('Required environment variables are not defined.'); throw new Error('Required environment variables are not defined.');
} }
// Send a message // Send a message with optional mentions
export async function sendMessage(phone: string, message: string) { export async function sendMessage(phone: string, message: string, mentions: string[] = []) {
try { try {
await axios.post(`${API_URL}/message/sendText/${INSTANCE_NAME}`, { const payload: any = {
number: phone, number: phone,
text: message, text: message,
}, { };
// Add mentions if provided
if (mentions.length > 0) {
payload.contextInfo = {
mentionedJid: mentions
};
}
await axios.post(`${API_URL}/message/sendText/${INSTANCE_NAME}`, payload, {
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
apikey: API_KEY, apikey: API_KEY,

@ -21,7 +21,7 @@ export function notifyTaskCreation(task: Task) {
const assigneeMessage = `📝 ${creatorMention} te ha asignado una nueva tarea:\n` + const assigneeMessage = `📝 ${creatorMention} te ha asignado una nueva tarea:\n` +
`ID: ${task.id}\nDescripción: ${task.description}` + `ID: ${task.id}\nDescripción: ${task.description}` +
(task.dueDate ? `\nFecha límite: ${task.dueDate}` : ''); (task.dueDate ? `\nFecha límite: ${task.dueDate}` : '');
sendMessage(task.assignedTo, assigneeMessage); sendMessage(task.assignedTo, assigneeMessage, [task.assignedTo]);
} }
} }

@ -1,7 +1,7 @@
export function normalizeUserIdentifier(input: string): string { export function normalizeUserIdentifier(input: string): string {
// Handle JID format (12345678@s.whatsapp.net) // Handle JID format (12345678@s.whatsapp.net)
if (input.includes('@s.whatsapp.net')) { if (input.includes('@s.whatsapp.net')) {
return `@${input.split('@')[0]}`; return input; // Return full JID
} }
// Remove @ prefix if present // Remove @ prefix if present
@ -15,7 +15,7 @@ export function normalizeUserIdentifier(input: string): string {
throw new Error('Número de teléfono inválido'); throw new Error('Número de teléfono inválido');
} }
return `@${phoneNumber}`; return `${phoneNumber}@s.whatsapp.net`;
} }
export function extractUserFromJid(jid: string): string { export function extractUserFromJid(jid: string): string {

Loading…
Cancel
Save