diff --git a/bun.lockb b/bun.lockb new file mode 100755 index 0000000..d6c986c Binary files /dev/null and b/bun.lockb differ diff --git a/database.db b/database.db new file mode 100644 index 0000000..e69de29 diff --git a/src/bot/utils/messaging.ts b/src/bot/utils/messaging.ts index 71a8756..e14d6f4 100644 --- a/src/bot/utils/messaging.ts +++ b/src/bot/utils/messaging.ts @@ -8,41 +8,42 @@ const INSTANCE_NAME = process.env.INSTANCE_NAME; const API_KEY = process.env.API_KEY; 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 with optional mentions -export async function sendMessage(phone: string, message: string | {text: string}, mentions: string[] = []) { - try { - // Normalize message input to always have text property - const messageText = typeof message === 'string' ? message : message.text; - - // Build payload according to API specification - const payload = { - number: phone, - textMessage: { - text: messageText - }, - options: { - delay: 1200, - presence: 'composing', - linkPreview: false, - ...(mentions.length > 0 && { - mentions: { - everyOne: false, - mentioned: mentions.map(phone => phone.split('@')[0]) - } - }) - } - }; +export async function sendMessage(phone: string, message: string | { text: string }, mentions: string[] = []) { + try { + // Normalize message input to always have text property + const messageText = typeof message === 'string' ? message : message.text; + console.log(`el phone es ${phone} y el mensaje es ${message}`) + // Build payload according to API specification + const payload = { + number: phone, + text: messageText, + textMessage: { + text: messageText + }, + options: { + delay: 1200, + presence: 'composing', + linkPreview: false, + ...(mentions.length > 0 && { + mentions: { + everyOne: false, + mentioned: mentions.map(phone => phone.split('@')[0]) + } + }) + } + }; - await axios.post(`${API_URL}/message/sendText/${INSTANCE_NAME}`, payload, { - headers: { - 'Content-Type': 'application/json', - apikey: API_KEY, - }, - }); - } catch (error) { - console.error('Error sending message:', error); - } + await axios.post(`${API_URL}/message/sendText/${INSTANCE_NAME}`, payload, { + headers: { + 'Content-Type': 'application/json', + apikey: API_KEY, + }, + }); + } catch (error) { + console.error('Error sending message:', error); + } }