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
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;
if (mentions.length > 0) {
// Format with mentions
payload = {
let payload: any = {
number: phone,
options: {
text: messageText
};
if (mentions.length > 0) {
// Add mentions if provided
payload.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
everyOne: false,
mentioned: mentions.map(phone => phone.split('@')[0])
}
},
textMessage: {
text: message
}
};
} else {
// Simple message format
payload = {
number: phone,
text: message
};
}

Loading…
Cancel
Save