fix: ensure all messages include required text property

main
borja (aider) 3 months ago
parent 57bab18ae8
commit f22c60bff7

@ -12,33 +12,27 @@ if (!API_URL || !INSTANCE_NAME || !API_KEY) {
} }
// Send a message with optional mentions // 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 { 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) { if (mentions.length > 0) {
// Format with mentions // Add mentions if provided
payload = { payload.options = {
number: phone, delay: 1200,
options: { presence: 'composing',
delay: 1200, linkPreview: false,
presence: 'composing', mentions: {
linkPreview: false, everyOne: false,
mentions: { mentioned: mentions.map(phone => phone.split('@')[0])
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
} }
}; };
} else {
// Simple message format
payload = {
number: phone,
text: message
};
} }
await axios.post(`${API_URL}/message/sendText/${INSTANCE_NAME}`, payload, { await axios.post(`${API_URL}/message/sendText/${INSTANCE_NAME}`, payload, {

Loading…
Cancel
Save