mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-12-09 01:49:37 -06:00
fix(evolutionbot): implement splitMessages and linkPreview functionality
- Replace instance.textMessage() with sendMessageWhatsApp() method - Enable message splitting by double line breaks (\n\n) - Add proper delay and typing indicators between split messages - Fix linkPreview parameter passing to base class methods - Support linkPreview: false/true from webhook response - Remove unnecessary debug logs for cleaner output Fixes: EvolutionBot was not respecting splitMessages and linkPreview configurations
This commit is contained in:
parent
4726c4727d
commit
b0ca79cd11
@ -180,6 +180,7 @@ export abstract class BaseChatbotService<BotType = any, SettingsType = any> {
|
|||||||
remoteJid: string,
|
remoteJid: string,
|
||||||
message: string,
|
message: string,
|
||||||
settings: SettingsType,
|
settings: SettingsType,
|
||||||
|
linkPreview: boolean = true,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
if (!message) return;
|
if (!message) return;
|
||||||
|
|
||||||
@ -202,7 +203,7 @@ export abstract class BaseChatbotService<BotType = any, SettingsType = any> {
|
|||||||
if (mediaType) {
|
if (mediaType) {
|
||||||
// Send accumulated text before sending media
|
// Send accumulated text before sending media
|
||||||
if (textBuffer.trim()) {
|
if (textBuffer.trim()) {
|
||||||
await this.sendFormattedText(instance, remoteJid, textBuffer.trim(), settings, splitMessages);
|
await this.sendFormattedText(instance, remoteJid, textBuffer.trim(), settings, splitMessages, linkPreview);
|
||||||
textBuffer = '';
|
textBuffer = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -252,7 +253,7 @@ export abstract class BaseChatbotService<BotType = any, SettingsType = any> {
|
|||||||
|
|
||||||
// Send any remaining text
|
// Send any remaining text
|
||||||
if (textBuffer.trim()) {
|
if (textBuffer.trim()) {
|
||||||
await this.sendFormattedText(instance, remoteJid, textBuffer.trim(), settings, splitMessages);
|
await this.sendFormattedText(instance, remoteJid, textBuffer.trim(), settings, splitMessages, linkPreview);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -265,6 +266,7 @@ export abstract class BaseChatbotService<BotType = any, SettingsType = any> {
|
|||||||
text: string,
|
text: string,
|
||||||
settings: any,
|
settings: any,
|
||||||
splitMessages: boolean,
|
splitMessages: boolean,
|
||||||
|
linkPreview: boolean = true,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const timePerChar = settings?.timePerChar ?? 0;
|
const timePerChar = settings?.timePerChar ?? 0;
|
||||||
const minDelay = 1000;
|
const minDelay = 1000;
|
||||||
@ -290,6 +292,7 @@ export abstract class BaseChatbotService<BotType = any, SettingsType = any> {
|
|||||||
number: remoteJid.split('@')[0],
|
number: remoteJid.split('@')[0],
|
||||||
delay: settings?.delayMessage || 1000,
|
delay: settings?.delayMessage || 1000,
|
||||||
text: message,
|
text: message,
|
||||||
|
linkPreview,
|
||||||
},
|
},
|
||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
@ -316,6 +319,7 @@ export abstract class BaseChatbotService<BotType = any, SettingsType = any> {
|
|||||||
number: remoteJid.split('@')[0],
|
number: remoteJid.split('@')[0],
|
||||||
delay: settings?.delayMessage || 1000,
|
delay: settings?.delayMessage || 1000,
|
||||||
text: text,
|
text: text,
|
||||||
|
linkPreview,
|
||||||
},
|
},
|
||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
|
|||||||
@ -115,15 +115,10 @@ export class EvolutionBotService extends BaseChatbotService<EvolutionBot, Evolut
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
this.logger.debug(`[EvolutionBot] Sending request to endpoint: ${endpoint}`);
|
|
||||||
this.logger.debug(`[EvolutionBot] Request payload: ${JSON.stringify(sanitizedPayload, null, 2)}`);
|
|
||||||
|
|
||||||
const response = await axios.post(endpoint, payload, {
|
const response = await axios.post(endpoint, payload, {
|
||||||
headers,
|
headers,
|
||||||
});
|
});
|
||||||
|
|
||||||
this.logger.debug(`[EvolutionBot] Response received - Status: ${response.status}`);
|
|
||||||
|
|
||||||
if (instance.integration === Integration.WHATSAPP_BAILEYS) {
|
if (instance.integration === Integration.WHATSAPP_BAILEYS) {
|
||||||
await instance.client.sendPresenceUpdate('paused', remoteJid);
|
await instance.client.sendPresenceUpdate('paused', remoteJid);
|
||||||
}
|
}
|
||||||
@ -134,10 +129,6 @@ export class EvolutionBotService extends BaseChatbotService<EvolutionBot, Evolut
|
|||||||
// Validate linkPreview is boolean and default to true for backward compatibility
|
// Validate linkPreview is boolean and default to true for backward compatibility
|
||||||
const linkPreview = typeof rawLinkPreview === 'boolean' ? rawLinkPreview : true;
|
const linkPreview = typeof rawLinkPreview === 'boolean' ? rawLinkPreview : true;
|
||||||
|
|
||||||
this.logger.debug(
|
|
||||||
`[EvolutionBot] Processing response - Message length: ${message?.length || 0}, LinkPreview: ${linkPreview}`,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (message && typeof message === 'string' && message.startsWith("'") && message.endsWith("'")) {
|
if (message && typeof message === 'string' && message.startsWith("'") && message.endsWith("'")) {
|
||||||
const innerContent = message.slice(1, -1);
|
const innerContent = message.slice(1, -1);
|
||||||
if (!innerContent.includes("'")) {
|
if (!innerContent.includes("'")) {
|
||||||
@ -146,17 +137,8 @@ export class EvolutionBotService extends BaseChatbotService<EvolutionBot, Evolut
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (message) {
|
if (message) {
|
||||||
// Send message directly with validated linkPreview option
|
// Use the base class method that handles splitMessages functionality
|
||||||
await instance.textMessage(
|
await this.sendMessageWhatsApp(instance, remoteJid, message, settings, linkPreview);
|
||||||
{
|
|
||||||
number: remoteJid.split('@')[0],
|
|
||||||
delay: settings?.delayMessage || 1000,
|
|
||||||
text: message,
|
|
||||||
linkPreview, // Always boolean, defaults to true
|
|
||||||
},
|
|
||||||
false,
|
|
||||||
);
|
|
||||||
this.logger.debug(`[EvolutionBot] Message sent successfully with linkPreview: ${linkPreview}`);
|
|
||||||
} else {
|
} else {
|
||||||
this.logger.warn(`[EvolutionBot] No message content received from bot response`);
|
this.logger.warn(`[EvolutionBot] No message content received from bot response`);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user