mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-12-09 01:49:37 -06:00
Merge pull request #1986 from dersonbsb2022/main
Some checks failed
Some checks failed
fix(evolutionbot): Fixing the correct message sending method so that messages are split.
This commit is contained in:
commit
d8b4378163
302
env.example
Normal file
302
env.example
Normal file
@ -0,0 +1,302 @@
|
||||
# ===========================================
|
||||
# EVOLUTION API - CONFIGURAÇÃO DE AMBIENTE
|
||||
# ===========================================
|
||||
|
||||
# ===========================================
|
||||
# SERVIDOR
|
||||
# ===========================================
|
||||
SERVER_NAME=evolution
|
||||
SERVER_TYPE=http
|
||||
SERVER_PORT=8080
|
||||
SERVER_URL=http://localhost:8080
|
||||
SERVER_DISABLE_DOCS=false
|
||||
SERVER_DISABLE_MANAGER=false
|
||||
|
||||
# ===========================================
|
||||
# CORS
|
||||
# ===========================================
|
||||
CORS_ORIGIN=*
|
||||
CORS_METHODS=POST,GET,PUT,DELETE
|
||||
CORS_CREDENTIALS=true
|
||||
|
||||
# ===========================================
|
||||
# SSL (opcional)
|
||||
# ===========================================
|
||||
SSL_CONF_PRIVKEY=
|
||||
SSL_CONF_FULLCHAIN=
|
||||
|
||||
# ===========================================
|
||||
# BANCO DE DADOS
|
||||
# ===========================================
|
||||
DATABASE_PROVIDER=postgresql
|
||||
DATABASE_CONNECTION_URI=postgresql://username:password@localhost:5432/evolution_api
|
||||
DATABASE_CONNECTION_CLIENT_NAME=evolution
|
||||
|
||||
# Configurações de salvamento de dados
|
||||
DATABASE_SAVE_DATA_INSTANCE=true
|
||||
DATABASE_SAVE_DATA_NEW_MESSAGE=true
|
||||
DATABASE_SAVE_MESSAGE_UPDATE=true
|
||||
DATABASE_SAVE_DATA_CONTACTS=true
|
||||
DATABASE_SAVE_DATA_CHATS=true
|
||||
DATABASE_SAVE_DATA_HISTORIC=true
|
||||
DATABASE_SAVE_DATA_LABELS=true
|
||||
DATABASE_SAVE_IS_ON_WHATSAPP=true
|
||||
DATABASE_SAVE_IS_ON_WHATSAPP_DAYS=7
|
||||
DATABASE_DELETE_MESSAGE=false
|
||||
|
||||
# ===========================================
|
||||
# REDIS
|
||||
# ===========================================
|
||||
CACHE_REDIS_ENABLED=true
|
||||
CACHE_REDIS_URI=redis://localhost:6379
|
||||
CACHE_REDIS_PREFIX_KEY=evolution-cache
|
||||
CACHE_REDIS_TTL=604800
|
||||
CACHE_REDIS_SAVE_INSTANCES=true
|
||||
|
||||
# Cache local (fallback)
|
||||
CACHE_LOCAL_ENABLED=true
|
||||
CACHE_LOCAL_TTL=86400
|
||||
|
||||
# ===========================================
|
||||
# AUTENTICAÇÃO
|
||||
# ===========================================
|
||||
AUTHENTICATION_API_KEY=BQYHJGJHJ
|
||||
AUTHENTICATION_EXPOSE_IN_FETCH_INSTANCES=false
|
||||
|
||||
# ===========================================
|
||||
# LOGS
|
||||
# ===========================================
|
||||
LOG_LEVEL=ERROR,WARN,DEBUG,INFO,LOG,VERBOSE,DARK,WEBHOOKS,WEBSOCKET
|
||||
LOG_COLOR=true
|
||||
LOG_BAILEYS=error
|
||||
|
||||
# ===========================================
|
||||
# INSTÂNCIAS
|
||||
# ===========================================
|
||||
DEL_INSTANCE=false
|
||||
DEL_TEMP_INSTANCES=true
|
||||
|
||||
# ===========================================
|
||||
# IDIOMA
|
||||
# ===========================================
|
||||
LANGUAGE=pt-BR
|
||||
|
||||
# ===========================================
|
||||
# WEBHOOK
|
||||
# ===========================================
|
||||
WEBHOOK_GLOBAL_URL=
|
||||
WEBHOOK_GLOBAL_ENABLED=false
|
||||
WEBHOOK_GLOBAL_WEBHOOK_BY_EVENTS=false
|
||||
|
||||
# Eventos de webhook
|
||||
WEBHOOK_EVENTS_APPLICATION_STARTUP=false
|
||||
WEBHOOK_EVENTS_INSTANCE_CREATE=false
|
||||
WEBHOOK_EVENTS_INSTANCE_DELETE=false
|
||||
WEBHOOK_EVENTS_QRCODE_UPDATED=false
|
||||
WEBHOOK_EVENTS_MESSAGES_SET=false
|
||||
WEBHOOK_EVENTS_MESSAGES_UPSERT=false
|
||||
WEBHOOK_EVENTS_MESSAGES_EDITED=false
|
||||
WEBHOOK_EVENTS_MESSAGES_UPDATE=false
|
||||
WEBHOOK_EVENTS_MESSAGES_DELETE=false
|
||||
WEBHOOK_EVENTS_SEND_MESSAGE=false
|
||||
WEBHOOK_EVENTS_SEND_MESSAGE_UPDATE=false
|
||||
WEBHOOK_EVENTS_CONTACTS_SET=false
|
||||
WEBHOOK_EVENTS_CONTACTS_UPDATE=false
|
||||
WEBHOOK_EVENTS_CONTACTS_UPSERT=false
|
||||
WEBHOOK_EVENTS_PRESENCE_UPDATE=false
|
||||
WEBHOOK_EVENTS_CHATS_SET=false
|
||||
WEBHOOK_EVENTS_CHATS_UPDATE=false
|
||||
WEBHOOK_EVENTS_CHATS_UPSERT=false
|
||||
WEBHOOK_EVENTS_CHATS_DELETE=false
|
||||
WEBHOOK_EVENTS_CONNECTION_UPDATE=false
|
||||
WEBHOOK_EVENTS_LABELS_EDIT=false
|
||||
WEBHOOK_EVENTS_LABELS_ASSOCIATION=false
|
||||
WEBHOOK_EVENTS_GROUPS_UPSERT=false
|
||||
WEBHOOK_EVENTS_GROUPS_UPDATE=false
|
||||
WEBHOOK_EVENTS_GROUP_PARTICIPANTS_UPDATE=false
|
||||
WEBHOOK_EVENTS_CALL=false
|
||||
WEBHOOK_EVENTS_TYPEBOT_START=false
|
||||
WEBHOOK_EVENTS_TYPEBOT_CHANGE_STATUS=false
|
||||
WEBHOOK_EVENTS_ERRORS=false
|
||||
WEBHOOK_EVENTS_ERRORS_WEBHOOK=
|
||||
|
||||
# Configurações de webhook
|
||||
WEBHOOK_REQUEST_TIMEOUT_MS=30000
|
||||
WEBHOOK_RETRY_MAX_ATTEMPTS=10
|
||||
WEBHOOK_RETRY_INITIAL_DELAY_SECONDS=5
|
||||
WEBHOOK_RETRY_USE_EXPONENTIAL_BACKOFF=true
|
||||
WEBHOOK_RETRY_MAX_DELAY_SECONDS=300
|
||||
WEBHOOK_RETRY_JITTER_FACTOR=0.2
|
||||
WEBHOOK_RETRY_NON_RETRYABLE_STATUS_CODES=400,401,403,404,422
|
||||
|
||||
# ===========================================
|
||||
# WEBSOCKET
|
||||
# ===========================================
|
||||
WEBSOCKET_ENABLED=true
|
||||
WEBSOCKET_GLOBAL_EVENTS=true
|
||||
WEBSOCKET_ALLOWED_HOSTS=
|
||||
|
||||
# ===========================================
|
||||
# RABBITMQ
|
||||
# ===========================================
|
||||
RABBITMQ_ENABLED=false
|
||||
RABBITMQ_GLOBAL_ENABLED=false
|
||||
RABBITMQ_PREFIX_KEY=
|
||||
RABBITMQ_EXCHANGE_NAME=evolution_exchange
|
||||
RABBITMQ_URI=
|
||||
RABBITMQ_FRAME_MAX=8192
|
||||
|
||||
# ===========================================
|
||||
# NATS
|
||||
# ===========================================
|
||||
NATS_ENABLED=false
|
||||
NATS_GLOBAL_ENABLED=false
|
||||
NATS_PREFIX_KEY=
|
||||
NATS_EXCHANGE_NAME=evolution_exchange
|
||||
NATS_URI=
|
||||
|
||||
# ===========================================
|
||||
# SQS
|
||||
# ===========================================
|
||||
SQS_ENABLED=false
|
||||
SQS_GLOBAL_ENABLED=false
|
||||
SQS_GLOBAL_FORCE_SINGLE_QUEUE=false
|
||||
SQS_GLOBAL_PREFIX_NAME=global
|
||||
SQS_ACCESS_KEY_ID=
|
||||
SQS_SECRET_ACCESS_KEY=
|
||||
SQS_ACCOUNT_ID=
|
||||
SQS_REGION=
|
||||
SQS_MAX_PAYLOAD_SIZE=1048576
|
||||
|
||||
# ===========================================
|
||||
# PUSHER
|
||||
# ===========================================
|
||||
PUSHER_ENABLED=false
|
||||
PUSHER_GLOBAL_ENABLED=false
|
||||
PUSHER_GLOBAL_APP_ID=
|
||||
PUSHER_GLOBAL_KEY=
|
||||
PUSHER_GLOBAL_SECRET=
|
||||
PUSHER_GLOBAL_CLUSTER=
|
||||
PUSHER_GLOBAL_USE_TLS=false
|
||||
|
||||
# ===========================================
|
||||
# WHATSAPP BUSINESS
|
||||
# ===========================================
|
||||
WA_BUSINESS_TOKEN_WEBHOOK=evolution
|
||||
WA_BUSINESS_URL=https://graph.facebook.com
|
||||
WA_BUSINESS_VERSION=v18.0
|
||||
WA_BUSINESS_LANGUAGE=en
|
||||
|
||||
# ===========================================
|
||||
# CONFIGURAÇÕES DE SESSÃO
|
||||
# ===========================================
|
||||
CONFIG_SESSION_PHONE_CLIENT=Evolution API
|
||||
CONFIG_SESSION_PHONE_NAME=Chrome
|
||||
|
||||
# ===========================================
|
||||
# QR CODE
|
||||
# ===========================================
|
||||
QRCODE_LIMIT=30
|
||||
QRCODE_COLOR=#198754
|
||||
|
||||
# ===========================================
|
||||
# INTEGRAÇÕES
|
||||
# ===========================================
|
||||
|
||||
# Typebot
|
||||
TYPEBOT_ENABLED=false
|
||||
TYPEBOT_API_VERSION=old
|
||||
TYPEBOT_SEND_MEDIA_BASE64=false
|
||||
|
||||
# Chatwoot
|
||||
CHATWOOT_ENABLED=false
|
||||
CHATWOOT_MESSAGE_DELETE=false
|
||||
CHATWOOT_MESSAGE_READ=false
|
||||
CHATWOOT_BOT_CONTACT=true
|
||||
CHATWOOT_IMPORT_DATABASE_CONNECTION_URI=
|
||||
CHATWOOT_IMPORT_PLACEHOLDER_MEDIA_MESSAGE=false
|
||||
|
||||
# OpenAI
|
||||
OPENAI_ENABLED=false
|
||||
OPENAI_API_KEY_GLOBAL=
|
||||
|
||||
# Dify
|
||||
DIFY_ENABLED=false
|
||||
|
||||
# N8N
|
||||
N8N_ENABLED=false
|
||||
|
||||
# EvoAI
|
||||
EVOAI_ENABLED=false
|
||||
|
||||
# Flowise
|
||||
FLOWISE_ENABLED=false
|
||||
|
||||
# ===========================================
|
||||
# S3 / MINIO
|
||||
# ===========================================
|
||||
S3_ENABLED=false
|
||||
S3_ACCESS_KEY=
|
||||
S3_SECRET_KEY=
|
||||
S3_ENDPOINT=
|
||||
S3_BUCKET=
|
||||
S3_PORT=9000
|
||||
S3_USE_SSL=false
|
||||
S3_REGION=
|
||||
S3_SKIP_POLICY=false
|
||||
S3_SAVE_VIDEO=false
|
||||
|
||||
# ===========================================
|
||||
# MÉTRICAS
|
||||
# ===========================================
|
||||
PROMETHEUS_METRICS=false
|
||||
METRICS_AUTH_REQUIRED=false
|
||||
METRICS_USER=
|
||||
METRICS_PASSWORD=
|
||||
METRICS_ALLOWED_IPS=
|
||||
|
||||
# ===========================================
|
||||
# TELEMETRIA
|
||||
# ===========================================
|
||||
TELEMETRY_ENABLED=true
|
||||
TELEMETRY_URL=
|
||||
|
||||
# ===========================================
|
||||
# PROXY
|
||||
# ===========================================
|
||||
PROXY_HOST=
|
||||
PROXY_PORT=
|
||||
PROXY_PROTOCOL=
|
||||
PROXY_USERNAME=
|
||||
PROXY_PASSWORD=
|
||||
|
||||
# ===========================================
|
||||
# CONVERSOR DE ÁUDIO
|
||||
# ===========================================
|
||||
API_AUDIO_CONVERTER=
|
||||
API_AUDIO_CONVERTER_KEY=
|
||||
|
||||
# ===========================================
|
||||
# FACEBOOK
|
||||
# ===========================================
|
||||
FACEBOOK_APP_ID=
|
||||
FACEBOOK_CONFIG_ID=
|
||||
FACEBOOK_USER_TOKEN=
|
||||
|
||||
# ===========================================
|
||||
# SENTRY
|
||||
# ===========================================
|
||||
SENTRY_DSN=
|
||||
|
||||
# ===========================================
|
||||
# EVENT EMITTER
|
||||
# ===========================================
|
||||
EVENT_EMITTER_MAX_LISTENERS=50
|
||||
|
||||
# ===========================================
|
||||
# PROVIDER
|
||||
# ===========================================
|
||||
PROVIDER_ENABLED=false
|
||||
PROVIDER_HOST=
|
||||
PROVIDER_PORT=5656
|
||||
PROVIDER_PREFIX=evolution
|
||||
@ -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,56 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Split message by double line breaks and return array of message parts
|
||||
*/
|
||||
private splitMessageByDoubleLineBreaks(message: string): string[] {
|
||||
return message.split('\n\n').filter((part) => part.trim().length > 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a single message with proper typing indicators and delays
|
||||
*/
|
||||
private async sendSingleMessage(
|
||||
instance: any,
|
||||
remoteJid: string,
|
||||
message: string,
|
||||
settings: any,
|
||||
linkPreview: boolean = true,
|
||||
): Promise<void> {
|
||||
const timePerChar = settings?.timePerChar ?? 0;
|
||||
const minDelay = 1000;
|
||||
const maxDelay = 20000;
|
||||
const delay = Math.min(Math.max(message.length * timePerChar, minDelay), maxDelay);
|
||||
|
||||
this.logger.debug(`[BaseChatbot] Sending single message with linkPreview: ${linkPreview}`);
|
||||
|
||||
if (instance.integration === Integration.WHATSAPP_BAILEYS) {
|
||||
await instance.client.presenceSubscribe(remoteJid);
|
||||
await instance.client.sendPresenceUpdate('composing', remoteJid);
|
||||
}
|
||||
|
||||
await new Promise<void>((resolve) => {
|
||||
setTimeout(async () => {
|
||||
await instance.textMessage(
|
||||
{
|
||||
number: remoteJid.split('@')[0],
|
||||
delay: settings?.delayMessage || 1000,
|
||||
text: message,
|
||||
linkPreview,
|
||||
},
|
||||
false,
|
||||
);
|
||||
resolve();
|
||||
}, delay);
|
||||
});
|
||||
|
||||
if (instance.integration === Integration.WHATSAPP_BAILEYS) {
|
||||
await instance.client.sendPresenceUpdate('paused', remoteJid);
|
||||
}
|
||||
}
|
||||
|
||||
@ -265,67 +315,24 @@ 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;
|
||||
const maxDelay = 20000;
|
||||
|
||||
if (splitMessages) {
|
||||
const multipleMessages = text.split('\n\n');
|
||||
for (let index = 0; index < multipleMessages.length; index++) {
|
||||
const message = multipleMessages[index];
|
||||
if (!message.trim()) continue;
|
||||
const messageParts = this.splitMessageByDoubleLineBreaks(text);
|
||||
|
||||
const delay = Math.min(Math.max(message.length * timePerChar, minDelay), maxDelay);
|
||||
this.logger.debug(`[BaseChatbot] Splitting message into ${messageParts.length} parts`);
|
||||
|
||||
if (instance.integration === Integration.WHATSAPP_BAILEYS) {
|
||||
await instance.client.presenceSubscribe(remoteJid);
|
||||
await instance.client.sendPresenceUpdate('composing', remoteJid);
|
||||
}
|
||||
for (let index = 0; index < messageParts.length; index++) {
|
||||
const message = messageParts[index];
|
||||
|
||||
await new Promise<void>((resolve) => {
|
||||
setTimeout(async () => {
|
||||
await instance.textMessage(
|
||||
{
|
||||
number: remoteJid.split('@')[0],
|
||||
delay: settings?.delayMessage || 1000,
|
||||
text: message,
|
||||
},
|
||||
false,
|
||||
);
|
||||
resolve();
|
||||
}, delay);
|
||||
});
|
||||
|
||||
if (instance.integration === Integration.WHATSAPP_BAILEYS) {
|
||||
await instance.client.sendPresenceUpdate('paused', remoteJid);
|
||||
}
|
||||
this.logger.debug(`[BaseChatbot] Sending message part ${index + 1}/${messageParts.length}`);
|
||||
await this.sendSingleMessage(instance, remoteJid, message, settings, linkPreview);
|
||||
}
|
||||
|
||||
this.logger.debug(`[BaseChatbot] All message parts sent successfully`);
|
||||
} else {
|
||||
const delay = Math.min(Math.max(text.length * timePerChar, minDelay), maxDelay);
|
||||
|
||||
if (instance.integration === Integration.WHATSAPP_BAILEYS) {
|
||||
await instance.client.presenceSubscribe(remoteJid);
|
||||
await instance.client.sendPresenceUpdate('composing', remoteJid);
|
||||
}
|
||||
|
||||
await new Promise<void>((resolve) => {
|
||||
setTimeout(async () => {
|
||||
await instance.textMessage(
|
||||
{
|
||||
number: remoteJid.split('@')[0],
|
||||
delay: settings?.delayMessage || 1000,
|
||||
text: text,
|
||||
},
|
||||
false,
|
||||
);
|
||||
resolve();
|
||||
}, delay);
|
||||
});
|
||||
|
||||
if (instance.integration === Integration.WHATSAPP_BAILEYS) {
|
||||
await instance.client.sendPresenceUpdate('paused', remoteJid);
|
||||
}
|
||||
this.logger.debug(`[BaseChatbot] Sending single message`);
|
||||
await this.sendSingleMessage(instance, remoteJid, text, settings, linkPreview);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -128,7 +128,7 @@ export class DifyService extends BaseChatbotService<Dify, DifySetting> {
|
||||
const conversationId = response?.data?.conversation_id;
|
||||
|
||||
if (message) {
|
||||
await this.sendMessageWhatsApp(instance, remoteJid, message, settings);
|
||||
await this.sendMessageWhatsApp(instance, remoteJid, message, settings, true);
|
||||
}
|
||||
|
||||
await this.prismaRepository.integrationSession.update({
|
||||
@ -210,7 +210,7 @@ export class DifyService extends BaseChatbotService<Dify, DifySetting> {
|
||||
const conversationId = response?.data?.conversation_id;
|
||||
|
||||
if (message) {
|
||||
await this.sendMessageWhatsApp(instance, remoteJid, message, settings);
|
||||
await this.sendMessageWhatsApp(instance, remoteJid, message, settings, true);
|
||||
}
|
||||
|
||||
await this.prismaRepository.integrationSession.update({
|
||||
@ -298,7 +298,7 @@ export class DifyService extends BaseChatbotService<Dify, DifySetting> {
|
||||
await instance.client.sendPresenceUpdate('paused', remoteJid);
|
||||
|
||||
if (answer) {
|
||||
await this.sendMessageWhatsApp(instance, remoteJid, answer, settings);
|
||||
await this.sendMessageWhatsApp(instance, remoteJid, answer, settings, true);
|
||||
}
|
||||
|
||||
await this.prismaRepository.integrationSession.update({
|
||||
|
||||
@ -195,7 +195,7 @@ export class EvoaiService extends BaseChatbotService<Evoai, EvoaiSetting> {
|
||||
this.logger.debug(`[EvoAI] Extracted message to send: ${message}`);
|
||||
|
||||
if (message) {
|
||||
await this.sendMessageWhatsApp(instance, remoteJid, message, settings);
|
||||
await this.sendMessageWhatsApp(instance, remoteJid, message, settings, true);
|
||||
}
|
||||
} catch (error) {
|
||||
this.logger.error(
|
||||
|
||||
@ -126,15 +126,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);
|
||||
}
|
||||
@ -145,10 +140,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("'")) {
|
||||
@ -157,17 +148,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`);
|
||||
}
|
||||
|
||||
@ -142,7 +142,7 @@ export class FlowiseService extends BaseChatbotService<FlowiseModel> {
|
||||
|
||||
if (message) {
|
||||
// Use the base class method to send the message to WhatsApp
|
||||
await this.sendMessageWhatsApp(instance, remoteJid, message, settings);
|
||||
await this.sendMessageWhatsApp(instance, remoteJid, message, settings, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -78,7 +78,7 @@ export class N8nService extends BaseChatbotService<N8n, N8nSetting> {
|
||||
const message = response?.data?.output || response?.data?.answer;
|
||||
|
||||
// Use base class method instead of custom implementation
|
||||
await this.sendMessageWhatsApp(instance, remoteJid, message, settings);
|
||||
await this.sendMessageWhatsApp(instance, remoteJid, message, settings, true);
|
||||
|
||||
await this.prismaRepository.integrationSession.update({
|
||||
where: {
|
||||
|
||||
@ -86,6 +86,7 @@ export class OpenaiService extends BaseChatbotService<OpenaiBot, OpenaiSetting>
|
||||
remoteJid,
|
||||
"Sorry, I couldn't transcribe your audio message. Could you please type your message instead?",
|
||||
settings,
|
||||
true,
|
||||
);
|
||||
return;
|
||||
}
|
||||
@ -236,7 +237,7 @@ export class OpenaiService extends BaseChatbotService<OpenaiBot, OpenaiSetting>
|
||||
// Send the response
|
||||
if (message) {
|
||||
this.logger.log('Sending message to WhatsApp');
|
||||
await this.sendMessageWhatsApp(instance, remoteJid, message, settings);
|
||||
await this.sendMessageWhatsApp(instance, remoteJid, message, settings, true);
|
||||
} else {
|
||||
this.logger.error('No message to send to WhatsApp');
|
||||
}
|
||||
|
||||
@ -318,7 +318,7 @@ export class TypebotService extends BaseChatbotService<TypebotModel, any> {
|
||||
} else if (formattedText.includes('[buttons]')) {
|
||||
await this.processButtonMessage(instance, formattedText, session.remoteJid);
|
||||
} else {
|
||||
await this.sendMessageWhatsApp(instance, session.remoteJid, formattedText, settings);
|
||||
await this.sendMessageWhatsApp(instance, session.remoteJid, formattedText, settings, true);
|
||||
}
|
||||
|
||||
sendTelemetry('/message/sendText');
|
||||
@ -393,7 +393,7 @@ export class TypebotService extends BaseChatbotService<TypebotModel, any> {
|
||||
} else if (formattedText.includes('[buttons]')) {
|
||||
await this.processButtonMessage(instance, formattedText, session.remoteJid);
|
||||
} else {
|
||||
await this.sendMessageWhatsApp(instance, session.remoteJid, formattedText, settings);
|
||||
await this.sendMessageWhatsApp(instance, session.remoteJid, formattedText, settings, true);
|
||||
}
|
||||
|
||||
sendTelemetry('/message/sendText');
|
||||
@ -642,15 +642,21 @@ export class TypebotService extends BaseChatbotService<TypebotModel, any> {
|
||||
|
||||
if (!content) {
|
||||
if (unknownMessage) {
|
||||
await this.sendMessageWhatsApp(waInstance, remoteJid, unknownMessage, {
|
||||
delayMessage,
|
||||
expire,
|
||||
keywordFinish,
|
||||
listeningFromMe,
|
||||
stopBotFromMe,
|
||||
keepOpen,
|
||||
await this.sendMessageWhatsApp(
|
||||
waInstance,
|
||||
remoteJid,
|
||||
unknownMessage,
|
||||
});
|
||||
{
|
||||
delayMessage,
|
||||
expire,
|
||||
keywordFinish,
|
||||
listeningFromMe,
|
||||
stopBotFromMe,
|
||||
keepOpen,
|
||||
unknownMessage,
|
||||
},
|
||||
true,
|
||||
);
|
||||
sendTelemetry('/message/sendText');
|
||||
}
|
||||
return;
|
||||
@ -801,15 +807,21 @@ export class TypebotService extends BaseChatbotService<TypebotModel, any> {
|
||||
if (!data?.messages || data.messages.length === 0) {
|
||||
if (!content) {
|
||||
if (unknownMessage) {
|
||||
await this.sendMessageWhatsApp(waInstance, remoteJid, unknownMessage, {
|
||||
delayMessage,
|
||||
expire,
|
||||
keywordFinish,
|
||||
listeningFromMe,
|
||||
stopBotFromMe,
|
||||
keepOpen,
|
||||
await this.sendMessageWhatsApp(
|
||||
waInstance,
|
||||
remoteJid,
|
||||
unknownMessage,
|
||||
});
|
||||
{
|
||||
delayMessage,
|
||||
expire,
|
||||
keywordFinish,
|
||||
listeningFromMe,
|
||||
stopBotFromMe,
|
||||
keepOpen,
|
||||
unknownMessage,
|
||||
},
|
||||
true,
|
||||
);
|
||||
sendTelemetry('/message/sendText');
|
||||
}
|
||||
return;
|
||||
@ -903,15 +915,21 @@ export class TypebotService extends BaseChatbotService<TypebotModel, any> {
|
||||
|
||||
if (!content) {
|
||||
if (unknownMessage) {
|
||||
await this.sendMessageWhatsApp(waInstance, remoteJid, unknownMessage, {
|
||||
delayMessage,
|
||||
expire,
|
||||
keywordFinish,
|
||||
listeningFromMe,
|
||||
stopBotFromMe,
|
||||
keepOpen,
|
||||
await this.sendMessageWhatsApp(
|
||||
waInstance,
|
||||
remoteJid,
|
||||
unknownMessage,
|
||||
});
|
||||
{
|
||||
delayMessage,
|
||||
expire,
|
||||
keywordFinish,
|
||||
listeningFromMe,
|
||||
stopBotFromMe,
|
||||
keepOpen,
|
||||
unknownMessage,
|
||||
},
|
||||
true,
|
||||
);
|
||||
sendTelemetry('/message/sendText');
|
||||
}
|
||||
return;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user