From 96d3ec20178fd20152b061be7d82f4c71a46660a Mon Sep 17 00:00:00 2001 From: Marco Buono Date: Wed, 23 Jul 2025 16:06:14 -0300 Subject: [PATCH 1/5] fix: avoid corrupting URLs with query strings --- .../channel/whatsapp/whatsapp.baileys.service.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts index de31b503..03870285 100644 --- a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts +++ b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts @@ -2504,7 +2504,9 @@ export class BaileysStartupService extends ChannelStartupService { imageBuffer = Buffer.from(base64Data, 'base64'); } else { const timestamp = new Date().getTime(); - const url = `${image}?timestamp=${timestamp}`; + const parsedURL = new URL(image); + parsedURL.searchParams.set('timestamp', timestamp.toString()); + const url = parsedURL.toString(); let config: any = { responseType: 'arraybuffer' }; @@ -2725,7 +2727,9 @@ export class BaileysStartupService extends ChannelStartupService { if (isURL(audio)) { const timestamp = new Date().getTime(); - const url = `${audio}?timestamp=${timestamp}`; + const parsedURL = new URL(audio); + parsedURL.searchParams.set('timestamp', timestamp.toString()); + const url = parsedURL.toString(); const config: any = { responseType: 'stream' }; @@ -3591,7 +3595,9 @@ export class BaileysStartupService extends ChannelStartupService { let pic: WAMediaUpload; if (isURL(picture)) { const timestamp = new Date().getTime(); - const url = `${picture}?timestamp=${timestamp}`; + const parsedURL = new URL(picture); + parsedURL.searchParams.set('timestamp', timestamp.toString()); + const url = parsedURL.toString(); let config: any = { responseType: 'arraybuffer' }; @@ -3873,7 +3879,9 @@ export class BaileysStartupService extends ChannelStartupService { let pic: WAMediaUpload; if (isURL(picture.image)) { const timestamp = new Date().getTime(); - const url = `${picture.image}?timestamp=${timestamp}`; + const parsedURL = new URL(picture.image); + parsedURL.searchParams.set('timestamp', timestamp.toString()); + const url = parsedURL.toString(); let config: any = { responseType: 'arraybuffer' }; From 5191438acfcbbd8badade3ca7906ac56510d37e6 Mon Sep 17 00:00:00 2001 From: Willian Coqueiro Date: Fri, 25 Jul 2025 12:02:17 +0000 Subject: [PATCH 2/5] fix: update error handling messages and correct group parameter in createContact method --- .../integrations/channel/whatsapp/whatsapp.baileys.service.ts | 2 ++ .../integrations/chatbot/chatwoot/services/chatwoot.service.ts | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts index f454473a..2bedac37 100644 --- a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts +++ b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts @@ -1059,6 +1059,8 @@ export class BaileysStartupService extends ChannelStartupService { 'failed to decrypt message', 'SessionError', 'Invalid PreKey ID', + 'No session record', + 'No session found to decrypt message' ].some((err) => param?.includes?.(err)), ) ) { diff --git a/src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts b/src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts index 5561ee6f..badaba13 100644 --- a/src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts +++ b/src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts @@ -681,7 +681,7 @@ export class ChatwootService { instance, body.key.participant.split('@')[0], filterInbox.id, - isGroup, + false, body.pushName, picture_url.profilePictureUrl || null, body.key.participant, From 23f54d1d96771b3cf3f712f28b4c9c71cf03dd34 Mon Sep 17 00:00:00 2001 From: Willian Coqueiro Date: Fri, 25 Jul 2025 12:13:56 +0000 Subject: [PATCH 3/5] lint --- .../integrations/channel/whatsapp/whatsapp.baileys.service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts index 2bedac37..6bdbef15 100644 --- a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts +++ b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts @@ -1060,7 +1060,7 @@ export class BaileysStartupService extends ChannelStartupService { 'SessionError', 'Invalid PreKey ID', 'No session record', - 'No session found to decrypt message' + 'No session found to decrypt message', ].some((err) => param?.includes?.(err)), ) ) { From 7f8293f4c657b89f1b9aa472e6f9f1cd065f43cf Mon Sep 17 00:00:00 2001 From: Davidson Gomes Date: Tue, 29 Jul 2025 09:16:19 -0300 Subject: [PATCH 4/5] changelog: v2.3.1 --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a1bc86d6..818602b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # 2.3.1 (develop) +### Feature + +* Add BaileysMessageProcessor for improved message handling and integrate rxjs for asynchronous processing +* Enhance message processing with retry logic for error handling + ### Fixed * Update Baileys Version @@ -8,6 +13,8 @@ * Add unreadMessages in the response * Phone number as message ID for Evo AI * Fix upload to s3 when media message +* Simplify edited message check in BaileysStartupService +* Avoid corrupting URLs with query strings # 2.3.0 (2025-06-17 09:19) From b5c67774dc033dbd66411d334cadfb9458e207bf Mon Sep 17 00:00:00 2001 From: Davidson Gomes Date: Tue, 29 Jul 2025 09:20:08 -0300 Subject: [PATCH 5/5] chore: remove CONFIG_SESSION_PHONE_VERSION and update related code - Removed the CONFIG_SESSION_PHONE_VERSION environment variable from the configuration and Docker files. - Updated the BaileysStartupService to directly fetch the latest WhatsApp Web version without relying on the removed environment variable. - Adjusted the index router to reflect the changes in the WhatsApp Web version retrieval. --- CHANGELOG.md | 1 + Docker/swarm/evolution_api_v2.yaml | 1 - .../whatsapp/whatsapp.baileys.service.ts | 21 ++++++++++--------- src/api/routes/index.router.ts | 3 +-- src/config/env.config.ts | 3 +-- 5 files changed, 14 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 818602b0..383282ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ * Fix upload to s3 when media message * Simplify edited message check in BaileysStartupService * Avoid corrupting URLs with query strings +* Removed CONFIG_SESSION_PHONE_VERSION environment variable # 2.3.0 (2025-06-17 09:19) diff --git a/Docker/swarm/evolution_api_v2.yaml b/Docker/swarm/evolution_api_v2.yaml index c4cd30d6..4055dfa3 100644 --- a/Docker/swarm/evolution_api_v2.yaml +++ b/Docker/swarm/evolution_api_v2.yaml @@ -94,7 +94,6 @@ services: - WEBHOOK_EVENTS_ERRORS_WEBHOOK= - CONFIG_SESSION_PHONE_CLIENT=Evolution API V2 - CONFIG_SESSION_PHONE_NAME=Chrome - #- CONFIG_SESSION_PHONE_VERSION=2.3000.1023204200 - QRCODE_LIMIT=30 - OPENAI_ENABLED=true - DIFY_ENABLED=true diff --git a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts index 619dd6c6..758a5bf9 100644 --- a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts +++ b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts @@ -549,17 +549,18 @@ export class BaileysStartupService extends ChannelStartupService { this.logger.info(`Browser: ${browser}`); } - let version; - let log; + const baileysVersion = await fetchLatestWaWebVersion({}); + const version = baileysVersion.version; + const log = `Baileys version: ${version.join('.')}`; - if (session.VERSION) { - version = session.VERSION.split('.'); - log = `Baileys version env: ${version}`; - } else { - const baileysVersion = await fetchLatestWaWebVersion({}); - version = baileysVersion.version; - log = `Baileys version: ${version}`; - } + // if (session.VERSION) { + // version = session.VERSION.split('.'); + // log = `Baileys version env: ${version}`; + // } else { + // const baileysVersion = await fetchLatestWaWebVersion({}); + // version = baileysVersion.version; + // log = `Baileys version: ${version}`; + // } this.logger.info(log); diff --git a/src/api/routes/index.router.ts b/src/api/routes/index.router.ts index fd2372fa..48954ea0 100644 --- a/src/api/routes/index.router.ts +++ b/src/api/routes/index.router.ts @@ -69,8 +69,7 @@ router clientName: process.env.DATABASE_CONNECTION_CLIENT_NAME, manager: !serverConfig.DISABLE_MANAGER ? `${req.protocol}://${req.get('host')}/manager` : undefined, documentation: `https://doc.evolution-api.com`, - whatsappWebVersion: - process.env.CONFIG_SESSION_PHONE_VERSION || (await fetchLatestWaWebVersion({})).version.join('.'), + whatsappWebVersion: (await fetchLatestWaWebVersion({})).version.join('.'), }); }) .post('/verify-creds', authGuard['apikey'], async (req, res) => { diff --git a/src/config/env.config.ts b/src/config/env.config.ts index 8c253163..c59acd38 100644 --- a/src/config/env.config.ts +++ b/src/config/env.config.ts @@ -249,7 +249,7 @@ export type Webhook = { }; }; export type Pusher = { ENABLED: boolean; GLOBAL?: GlobalPusher; EVENTS: EventsPusher }; -export type ConfigSessionPhone = { CLIENT: string; NAME: string; VERSION: string }; +export type ConfigSessionPhone = { CLIENT: string; NAME: string }; export type QrCode = { LIMIT: number; COLOR: string }; export type Typebot = { ENABLED: boolean; API_VERSION: string; SEND_MEDIA_BASE64: boolean }; export type Chatwoot = { @@ -590,7 +590,6 @@ export class ConfigService { CONFIG_SESSION_PHONE: { CLIENT: process.env?.CONFIG_SESSION_PHONE_CLIENT || 'Evolution API', NAME: process.env?.CONFIG_SESSION_PHONE_NAME || 'Chrome', - VERSION: process.env?.CONFIG_SESSION_PHONE_VERSION || null, }, QRCODE: { LIMIT: Number.parseInt(process.env.QRCODE_LIMIT) || 30,