diff --git a/src/bot/utils/messaging.ts b/src/bot/utils/messaging.ts index 7d66200..e74000c 100644 --- a/src/bot/utils/messaging.ts +++ b/src/bot/utils/messaging.ts @@ -12,33 +12,27 @@ if (!API_URL || !INSTANCE_NAME || !API_KEY) { } // Send a message with optional mentions -export async function sendMessage(phone: string, message: string, mentions: string[] = []) { +export async function sendMessage(phone: string, message: string | {text: string}, mentions: string[] = []) { try { - let payload: any; + // Normalize message input to always have text property + const messageText = typeof message === 'string' ? message : message.text; + let payload: any = { + number: phone, + text: messageText + }; + if (mentions.length > 0) { - // Format with mentions - payload = { - number: phone, - options: { - delay: 1200, - presence: 'composing', - linkPreview: false, - mentions: { - everyOne: false, // Set to false since we're mentioning specific users, not everyone - mentioned: mentions.map(phone => phone.split('@')[0]) // Strip @s.whatsapp.net - } - }, - textMessage: { - text: message + // Add mentions if provided + payload.options = { + delay: 1200, + presence: 'composing', + linkPreview: false, + mentions: { + everyOne: false, + mentioned: mentions.map(phone => phone.split('@')[0]) } }; - } else { - // Simple message format - payload = { - number: phone, - text: message - }; } await axios.post(`${API_URL}/message/sendText/${INSTANCE_NAME}`, payload, {