fix: ensure all messages include required text property

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

@ -12,32 +12,26 @@ 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;
if (mentions.length > 0) { let payload: any = {
// Format with mentions
payload = {
number: phone, number: phone,
options: { text: messageText
};
if (mentions.length > 0) {
// Add mentions if provided
payload.options = {
delay: 1200, delay: 1200,
presence: 'composing', presence: 'composing',
linkPreview: false, linkPreview: false,
mentions: { mentions: {
everyOne: false, // Set to false since we're mentioning specific users, not everyone everyOne: false,
mentioned: mentions.map(phone => phone.split('@')[0]) // Strip @s.whatsapp.net mentioned: mentions.map(phone => phone.split('@')[0])
} }
},
textMessage: {
text: message
}
};
} else {
// Simple message format
payload = {
number: phone,
text: message
}; };
} }

Loading…
Cancel
Save