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,
|
||||
message: string,
|
||||
settings: SettingsType,
|
||||
linkPreview: boolean = true,
|
||||
): Promise<void> {
|
||||
if (!message) return;
|
||||
|
||||
@ -202,7 +203,7 @@ export abstract class BaseChatbotService<BotType = any, SettingsType = any> {
|
||||
if (mediaType) {
|
||||
// Send accumulated text before sending media
|
||||
if (textBuffer.trim()) {
|
||||
await this.sendFormattedText(instance, remoteJid, textBuffer.trim(), settings, splitMessages);
|
||||
await this.sendFormattedText(instance, remoteJid, textBuffer.trim(), settings, splitMessages, linkPreview);
|
||||
textBuffer = '';
|
||||
}
|
||||
|
||||
@ -252,7 +253,7 @@ export abstract class BaseChatbotService<BotType = any, SettingsType = any> {
|
||||
|
||||
// Send any remaining text
|
||||
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,
|
||||
settings: any,
|
||||
splitMessages: boolean,
|
||||
linkPreview: boolean = true,
|
||||
): Promise<void> {
|
||||
const timePerChar = settings?.timePerChar ?? 0;
|
||||
const minDelay = 1000;
|
||||
@ -290,6 +292,7 @@ export abstract class BaseChatbotService<BotType = any, SettingsType = any> {
|
||||
number: remoteJid.split('@')[0],
|
||||
delay: settings?.delayMessage || 1000,
|
||||
text: message,
|
||||
linkPreview,
|
||||
},
|
||||
false,
|
||||
);
|
||||
@ -316,6 +319,7 @@ export abstract class BaseChatbotService<BotType = any, SettingsType = any> {
|
||||
number: remoteJid.split('@')[0],
|
||||
delay: settings?.delayMessage || 1000,
|
||||
text: text,
|
||||
linkPreview,
|
||||
},
|
||||
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, {
|
||||
headers,
|
||||
});
|
||||
|
||||
this.logger.debug(`[EvolutionBot] Response received - Status: ${response.status}`);
|
||||
|
||||
if (instance.integration === Integration.WHATSAPP_BAILEYS) {
|
||||
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
|
||||
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("'")) {
|
||||
const innerContent = message.slice(1, -1);
|
||||
if (!innerContent.includes("'")) {
|
||||
@ -146,17 +137,8 @@ export class EvolutionBotService extends BaseChatbotService<EvolutionBot, Evolut
|
||||
}
|
||||
|
||||
if (message) {
|
||||
// Send message directly with validated linkPreview option
|
||||
await instance.textMessage(
|
||||
{
|
||||
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}`);
|
||||
// Use the base class method that handles splitMessages functionality
|
||||
await this.sendMessageWhatsApp(instance, remoteJid, message, settings, linkPreview);
|
||||
} else {
|
||||
this.logger.warn(`[EvolutionBot] No message content received from bot response`);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user