From 8e51ae63aecb24d9ba3801f4f55de84ac8404fa9 Mon Sep 17 00:00:00 2001 From: William Dumes Date: Thu, 7 Aug 2025 15:21:30 -0300 Subject: [PATCH 1/6] fix: corrigido para que o envio de base64 nas mensagens do business api seja enviada somente qnd a config esta ativa --- .../channel/meta/whatsapp.business.service.ts | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/api/integrations/channel/meta/whatsapp.business.service.ts b/src/api/integrations/channel/meta/whatsapp.business.service.ts index d3c35bee3..4494b5b24 100644 --- a/src/api/integrations/channel/meta/whatsapp.business.service.ts +++ b/src/api/integrations/channel/meta/whatsapp.business.service.ts @@ -506,7 +506,9 @@ export class BusinessStartupService extends ChannelStartupService { const mediaUrl = await s3Service.getObjectUrl(fullName); messageRaw.message.mediaUrl = mediaUrl; - messageRaw.message.base64 = buffer.data.toString('base64'); + if (this.localWebhook.enabled && this.localWebhook.webhookBase64) { + messageRaw.message.base64 = buffer.data.toString('base64'); + } // Processar OpenAI speech-to-text para áudio após o mediaUrl estar disponível if (this.configService.get('OPENAI').ENABLED && mediaType === 'audio') { @@ -544,11 +546,19 @@ export class BusinessStartupService extends ChannelStartupService { this.logger.error(['Error on upload file to minio', error?.message, error?.stack]); } } else { - const buffer = await this.downloadMediaMessage(received?.messages[0]); - messageRaw.message.base64 = buffer.toString('base64'); + if (this.localWebhook.enabled && this.localWebhook.webhookBase64) { + const buffer = await this.downloadMediaMessage(received?.messages[0]); + messageRaw.message.base64 = buffer.toString('base64'); + } // Processar OpenAI speech-to-text para áudio mesmo sem S3 if (this.configService.get('OPENAI').ENABLED && message.type === 'audio') { + let openAiBase64 = messageRaw.message.base64; + if (!openAiBase64) { + const buffer = await this.downloadMediaMessage(received?.messages[0]); + openAiBase64 = buffer.toString('base64'); + } + const openAiDefaultSettings = await this.prismaRepository.openaiSetting.findFirst({ where: { instanceId: this.instanceId, @@ -564,7 +574,7 @@ export class BusinessStartupService extends ChannelStartupService { openAiDefaultSettings.OpenaiCreds, { message: { - base64: messageRaw.message.base64, + base64: openAiBase64, ...messageRaw, }, }, @@ -1593,9 +1603,14 @@ export class BusinessStartupService extends ChannelStartupService { const messageType = msg.messageType.includes('Message') ? msg.messageType : msg.messageType + 'Message'; const mediaMessage = msg.message[messageType]; + if (!msg.message?.base64) { + const buffer = await this.downloadMediaMessage({ type: messageType, ...msg.message }); + msg.message.base64 = buffer.toString('base64'); + } + return { mediaType: msg.messageType, - fileName: mediaMessage?.fileName, + fileName: mediaMessage?.fileName || mediaMessage?.filename, caption: mediaMessage?.caption, size: { fileLength: mediaMessage?.fileLength, From 06081f6502246b545225cff4aa08552bb193dde9 Mon Sep 17 00:00:00 2001 From: ricael Date: Wed, 10 Sep 2025 16:59:04 -0300 Subject: [PATCH 2/6] =?UTF-8?q?fix:=20adicionado=20tratamento=20para=20evi?= =?UTF-8?q?tar=20envio=20de=20filename=20e=20caption=20em=20mensagens=20de?= =?UTF-8?q?=20v=C3=ADdeo=20e=20=C3=A1udio=20no=20BusinessStartupService?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/integrations/channel/meta/whatsapp.business.service.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/api/integrations/channel/meta/whatsapp.business.service.ts b/src/api/integrations/channel/meta/whatsapp.business.service.ts index 4494b5b24..427299ff9 100644 --- a/src/api/integrations/channel/meta/whatsapp.business.service.ts +++ b/src/api/integrations/channel/meta/whatsapp.business.service.ts @@ -1014,6 +1014,7 @@ export class BusinessStartupService extends ChannelStartupService { [message['mediaType']]: { [message['type']]: message['id'], ...(message['mediaType'] !== 'audio' && + message['mediaType'] !== 'video' && message['fileName'] && !isImage && { filename: message['fileName'] }), ...(message['mediaType'] !== 'audio' && message['caption'] && { caption: message['caption'] }), From 0363fa979d7e0b22cc3a0e4e83f980ebe4ed1323 Mon Sep 17 00:00:00 2001 From: ricael Date: Tue, 16 Sep 2025 13:35:06 -0300 Subject: [PATCH 3/6] improv --- docker-compose.dev.yaml | 4 ++-- package-lock.json | 40 ++++++++++++++++++++++++++++++---------- package.json | 2 +- 3 files changed, 33 insertions(+), 13 deletions(-) diff --git a/docker-compose.dev.yaml b/docker-compose.dev.yaml index 2ca3424e5..5b054b352 100644 --- a/docker-compose.dev.yaml +++ b/docker-compose.dev.yaml @@ -5,7 +5,7 @@ services: build: . restart: always ports: - - 8080:8080 + - 9000:9000 volumes: - evolution_instances:/evolution/instances networks: @@ -13,7 +13,7 @@ services: env_file: - .env expose: - - 8080 + - 9000 volumes: evolution_instances: diff --git a/package-lock.json b/package-lock.json index 70cfbaf6c..7d6ff146d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20,7 +20,7 @@ "amqplib": "^0.10.5", "audio-decode": "^2.2.3", "axios": "^1.7.9", - "baileys": "github:WhiskeySockets/Baileys", + "baileys": "npm:@whiskeysockets/baileys@^7.0.0-rc.3", "class-validator": "^0.14.1", "compression": "^1.7.5", "cors": "^2.8.5", @@ -4986,8 +4986,10 @@ } }, "node_modules/baileys": { - "version": "6.7.19", - "resolved": "git+ssh://git@github.com/WhiskeySockets/Baileys.git#9e04cce8d3eeb16025283a57849cc83aa26c6dd1", + "name": "@whiskeysockets/baileys", + "version": "7.0.0-rc.3", + "resolved": "https://registry.npmjs.org/@whiskeysockets/baileys/-/baileys-7.0.0-rc.3.tgz", + "integrity": "sha512-aksCC3Df/cytmBg0cizIvoVappaP8dE+9kU5vFjtCHjoEpCzlK8/ESozgHJSkm5LQ7Ikygl6aZLYHB2C/qCdOA==", "hasInstallScript": true, "license": "MIT", "dependencies": { @@ -4995,7 +4997,8 @@ "@hapi/boom": "^9.1.3", "async-mutex": "^0.5.0", "axios": "^1.6.0", - "libsignal": "git+https://github.com/whiskeysockets/libsignal-node", + "libsignal": "git+https://github.com/whiskeysockets/libsignal-node.git", + "lru-cache": "^11.1.0", "music-metadata": "^11.7.0", "pino": "^9.6", "protobufjs": "^7.2.4", @@ -5026,6 +5029,7 @@ "version": "9.1.4", "resolved": "https://registry.npmjs.org/@hapi/boom/-/boom-9.1.4.tgz", "integrity": "sha512-Ls1oH8jaN1vNsqcaHVYJrKmgMcKsC1wcp8bujvXrHaAqD2iDYq3HoOwsxwo09Cuda5R5nC0o0IxlrlTuvPuzSw==", + "license": "BSD-3-Clause", "dependencies": { "@hapi/hoek": "9.x.x" } @@ -5033,12 +5037,23 @@ "node_modules/baileys/node_modules/@hapi/hoek": { "version": "9.3.0", "resolved": "https://registry.npmjs.org/@hapi/hoek/-/hoek-9.3.0.tgz", - "integrity": "sha512-/c6rf4UJlmHlC9b5BaNvzAcFv7HZ2QHaV0D4/HNlBdvFnvQq8RI4kYdhyPCl7Xj+oWvTWQ8ujhqS53LIgAe6KQ==" + "integrity": "sha512-/c6rf4UJlmHlC9b5BaNvzAcFv7HZ2QHaV0D4/HNlBdvFnvQq8RI4kYdhyPCl7Xj+oWvTWQ8ujhqS53LIgAe6KQ==", + "license": "BSD-3-Clause" + }, + "node_modules/baileys/node_modules/lru-cache": { + "version": "11.2.1", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-11.2.1.tgz", + "integrity": "sha512-r8LA6i4LP4EeWOhqBaZZjDWwehd1xUJPCJd9Sv300H0ZmcUER4+JPh7bqqZeqs1o5pgtgvXm+d9UGrB5zZGDiQ==", + "license": "ISC", + "engines": { + "node": "20 || >=22" + } }, "node_modules/baileys/node_modules/pino": { - "version": "9.7.0", - "resolved": "https://registry.npmjs.org/pino/-/pino-9.7.0.tgz", - "integrity": "sha512-vnMCM6xZTb1WDmLvtG2lE/2p+t9hDEIvTWJsu6FejkE62vB7gDhvzrpFR4Cw2to+9JNQxVnkAKVPA1KPB98vWg==", + "version": "9.9.5", + "resolved": "https://registry.npmjs.org/pino/-/pino-9.9.5.tgz", + "integrity": "sha512-d1s98p8/4TfYhsJ09r/Azt30aYELRi6NNnZtEbqFw6BoGsdPVf5lKNK3kUwH8BmJJfpTLNuicjUQjaMbd93dVg==", + "license": "MIT", "dependencies": { "atomic-sleep": "^1.0.0", "fast-redact": "^3.1.1", @@ -5060,6 +5075,7 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/pino-abstract-transport/-/pino-abstract-transport-2.0.0.tgz", "integrity": "sha512-F63x5tizV6WCh4R6RHyi2Ml+M70DNRXt/+HANowMflpgGFMAym/VKm6G7ZOQRjqN7XbGxK1Lg9t6ZrtzOaivMw==", + "license": "MIT", "dependencies": { "split2": "^4.0.0" } @@ -5067,7 +5083,8 @@ "node_modules/baileys/node_modules/pino-std-serializers": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/pino-std-serializers/-/pino-std-serializers-7.0.0.tgz", - "integrity": "sha512-e906FRY0+tV27iq4juKzSYPbUj2do2X2JX4EzSca1631EB2QJQUqGbDuERal7LCtOpxl6x3+nvo9NPZcmjkiFA==" + "integrity": "sha512-e906FRY0+tV27iq4juKzSYPbUj2do2X2JX4EzSca1631EB2QJQUqGbDuERal7LCtOpxl6x3+nvo9NPZcmjkiFA==", + "license": "MIT" }, "node_modules/baileys/node_modules/process-warning": { "version": "5.0.0", @@ -5082,12 +5099,14 @@ "type": "opencollective", "url": "https://opencollective.com/fastify" } - ] + ], + "license": "MIT" }, "node_modules/baileys/node_modules/sonic-boom": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/sonic-boom/-/sonic-boom-4.2.0.tgz", "integrity": "sha512-INb7TM37/mAcsGmc9hyyI6+QR3rR1zVRu36B0NeGXKnOOLiZOfER5SA+N7X7k3yUYRzLWafduTDvJAfDswwEww==", + "license": "MIT", "dependencies": { "atomic-sleep": "^1.0.0" } @@ -5096,6 +5115,7 @@ "version": "3.1.0", "resolved": "https://registry.npmjs.org/thread-stream/-/thread-stream-3.1.0.tgz", "integrity": "sha512-OqyPZ9u96VohAyMfJykzmivOrY2wfMSf3C5TtFJVgN+Hm6aj+voFhlK+kZEIv2FBh1X6Xp3DlnCOfEQ3B2J86A==", + "license": "MIT", "dependencies": { "real-require": "^0.2.0" } diff --git a/package.json b/package.json index e91d1ea70..a4544701c 100644 --- a/package.json +++ b/package.json @@ -57,10 +57,10 @@ "@paralleldrive/cuid2": "^2.2.2", "@prisma/client": "^6.1.0", "@sentry/node": "^8.47.0", + "baileys": "npm:@whiskeysockets/baileys@^7.0.0-rc.3", "amqplib": "^0.10.5", "audio-decode": "^2.2.3", "axios": "^1.7.9", - "baileys": "github:WhiskeySockets/Baileys", "class-validator": "^0.14.1", "compression": "^1.7.5", "cors": "^2.8.5", From e623269a185ea2a36b98fb9582174ff3b5c35a36 Mon Sep 17 00:00:00 2001 From: ricael Date: Wed, 17 Sep 2025 08:13:33 -0300 Subject: [PATCH 4/6] =?UTF-8?q?fix:=20ajustar=20o=20tratamento=20da=20chav?= =?UTF-8?q?e=20de=20m=C3=ADdia=20na=20mensagem=20do=20servi=C3=A7o=20Whats?= =?UTF-8?q?App=20para=20usar=20Uint8Array?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../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 ace12e163..4b1db1595 100644 --- a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts +++ b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts @@ -3601,7 +3601,7 @@ export class BaileysStartupService extends ChannelStartupService { } if (typeof mediaMessage['mediaKey'] === 'object') { - msg.message = JSON.parse(JSON.stringify(msg.message)); + msg.message[mediaType].mediaKey = Uint8Array.from(Object.values(mediaMessage['mediaKey'])); } let buffer: Buffer; From 24c339343f0b19d8fdf9a7df209d1a716fa9050a Mon Sep 17 00:00:00 2001 From: ricael Date: Wed, 17 Sep 2025 17:41:07 -0300 Subject: [PATCH 5/6] =?UTF-8?q?fix:=20ajustar=20a=20manipula=C3=A7=C3=A3o?= =?UTF-8?q?=20do=20remoteJid=20na=20mensagem=20do=20servi=C3=A7o=20WhatsAp?= =?UTF-8?q?p=20para=20garantir=20a=20utiliza=C3=A7=C3=A3o=20da=20chave=20a?= =?UTF-8?q?lternativa=20quando=20dispon=C3=ADvel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../channel/whatsapp/whatsapp.baileys.service.ts | 5 ++++- 1 file changed, 4 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 4b1db1595..ee7675ec8 100644 --- a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts +++ b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts @@ -1349,7 +1349,10 @@ export class BaileysStartupService extends ChannelStartupService { } } - this.logger.log(messageRaw); + if (messageRaw.key.remoteJid?.includes('@lid') && messageRaw.key.remoteJidAlt) { + messageRaw.key.remoteJid = messageRaw.key.remoteJidAlt; + } + console.log(messageRaw); this.sendDataWebhook(Events.MESSAGES_UPSERT, messageRaw); From a84faaa575cf7661760dd61a24df91b69ccad4cb Mon Sep 17 00:00:00 2001 From: ricael Date: Thu, 30 Oct 2025 10:55:47 -0300 Subject: [PATCH 6/6] refactor(utils): improve makeProxyAgent for Undici compatibility --- src/utils/makeProxyAgent.ts | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/src/utils/makeProxyAgent.ts b/src/utils/makeProxyAgent.ts index e882876ef..ac64b9dec 100644 --- a/src/utils/makeProxyAgent.ts +++ b/src/utils/makeProxyAgent.ts @@ -1,7 +1,6 @@ import { HttpsProxyAgent } from 'https-proxy-agent'; import { SocksProxyAgent } from 'socks-proxy-agent'; - -import { ProxyAgent } from 'undici' +import { ProxyAgent } from 'undici'; type Proxy = { host: string; @@ -46,38 +45,38 @@ export function makeProxyAgent(proxy: Proxy | string): HttpsProxyAgent | } export function makeProxyAgentUndici(proxy: Proxy | string): ProxyAgent { - let proxyUrl: string - let protocol: string + let proxyUrl: string; + let protocol: string; if (typeof proxy === 'string') { - const url = new URL(proxy) - protocol = url.protocol.replace(':', '') - proxyUrl = proxy + const url = new URL(proxy); + protocol = url.protocol.replace(':', ''); + proxyUrl = proxy; } else { - const { host, password, port, protocol: proto, username } = proxy - protocol = (proto || 'http').replace(':', '') + const { host, password, port, protocol: proto, username } = proxy; + protocol = (proto || 'http').replace(':', ''); if (protocol === 'socks') { - protocol = 'socks5' + protocol = 'socks5'; } - const auth = username && password ? `${username}:${password}@` : '' - proxyUrl = `${protocol}://${auth}${host}:${port}` + const auth = username && password ? `${username}:${password}@` : ''; + proxyUrl = `${protocol}://${auth}${host}:${port}`; } - const PROXY_HTTP_PROTOCOL = 'http' - const PROXY_HTTPS_PROTOCOL = 'https' - const PROXY_SOCKS4_PROTOCOL = 'socks4' - const PROXY_SOCKS5_PROTOCOL = 'socks5' + const PROXY_HTTP_PROTOCOL = 'http'; + const PROXY_HTTPS_PROTOCOL = 'https'; + const PROXY_SOCKS4_PROTOCOL = 'socks4'; + const PROXY_SOCKS5_PROTOCOL = 'socks5'; switch (protocol) { case PROXY_HTTP_PROTOCOL: case PROXY_HTTPS_PROTOCOL: case PROXY_SOCKS4_PROTOCOL: case PROXY_SOCKS5_PROTOCOL: - return new ProxyAgent(proxyUrl) + return new ProxyAgent(proxyUrl); default: - throw new Error(`Unsupported proxy protocol: ${protocol}`) + throw new Error(`Unsupported proxy protocol: ${protocol}`); } }