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 {
assignedUser = normalizeUserIdentifier(assignedUserMatch[0]);
// 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`);
if (!linkedGroups.has(assignedUser)) {
sendMessage(sender, `El usuario ${formatUserMention(assignedUser)} no está en la comunidad`);
return;
}
} catch (error) {

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

@ -21,7 +21,7 @@ export function notifyTaskCreation(task: Task) {
const assigneeMessage = `📝 ${creatorMention} te ha asignado una nueva tarea:\n` +
`ID: ${task.id}\nDescripción: ${task.description}` +
(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 {
// Handle JID format (12345678@s.whatsapp.net)
if (input.includes('@s.whatsapp.net')) {
return `@${input.split('@')[0]}`;
return input; // Return full JID
}
// Remove @ prefix if present
@ -15,7 +15,7 @@ export function normalizeUserIdentifier(input: string): string {
throw new Error('Número de teléfono inválido');
}
return `@${phoneNumber}`;
return `${phoneNumber}@s.whatsapp.net`;
}
export function extractUserFromJid(jid: string): string {

Loading…
Cancel
Save