From 6101c8d65140fe8a2716e0507bee700db23ac5f1 Mon Sep 17 00:00:00 2001 From: William Dumes Date: Fri, 25 Jul 2025 17:08:14 -0300 Subject: [PATCH 01/13] fix: corrigido disparo de eventos quando nao usa a opcao da ENV de salvar mensagens no banco --- .../whatsapp/whatsapp.baileys.service.ts | 91 +++++++++++-------- 1 file changed, 53 insertions(+), 38 deletions(-) diff --git a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts index f454473a4..7d7da2be8 100644 --- a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts +++ b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts @@ -1443,16 +1443,7 @@ export class BaileysStartupService extends ChannelStartupService { } } - const findMessage = await this.prismaRepository.message.findFirst({ - where: { instanceId: this.instanceId, key: { path: ['id'], equals: key.id } }, - }); - - if (!findMessage) { - continue; - } - const message: any = { - messageId: findMessage.id, keyId: key.id, remoteJid: key?.remoteJid, fromMe: key.fromMe, @@ -1462,6 +1453,16 @@ export class BaileysStartupService extends ChannelStartupService { instanceId: this.instanceId, }; + let findMessage: any; + const configDatabaseData = this.configService.get('DATABASE').SAVE_DATA; + if (configDatabaseData.HISTORIC || configDatabaseData.NEW_MESSAGE) { + findMessage = await this.prismaRepository.message.findFirst({ + where: { instanceId: this.instanceId, key: { path: ['id'], equals: key.id } }, + }); + + if (findMessage) message.messageId = findMessage.id; + } + if (update.message === null && update.status === undefined) { this.sendDataWebhook(Events.MESSAGES_DELETE, key); @@ -1477,7 +1478,9 @@ export class BaileysStartupService extends ChannelStartupService { } continue; - } else if (update.status !== undefined && status[update.status] !== findMessage.status) { + } + + if (findMessage && update.status !== undefined && status[update.status] !== findMessage.status) { if (!key.fromMe && key.remoteJid) { readChatToUpdate[key.remoteJid] = true; @@ -3431,16 +3434,18 @@ export class BaileysStartupService extends ChannelStartupService { where: { id: message.id }, data: { key: { ...existingKey, deleted: true }, status: 'DELETED' }, }); - const messageUpdate: any = { - messageId: message.id, - keyId: messageId, - remoteJid: response.key.remoteJid, - fromMe: response.key.fromMe, - participant: response.key?.remoteJid, - status: 'DELETED', - instanceId: this.instanceId, - }; - await this.prismaRepository.messageUpdate.create({ data: messageUpdate }); + if (this.configService.get('DATABASE').SAVE_DATA.MESSAGE_UPDATE) { + const messageUpdate: any = { + messageId: message.id, + keyId: messageId, + remoteJid: response.key.remoteJid, + fromMe: response.key.fromMe, + participant: response.key?.remoteJid, + status: 'DELETED', + instanceId: this.instanceId, + }; + await this.prismaRepository.messageUpdate.create({ data: messageUpdate }); + } } else { await this.prismaRepository.message.deleteMany({ where: { id: message.id } }); } @@ -3771,6 +3776,10 @@ export class BaileysStartupService extends ChannelStartupService { private async formatUpdateMessage(data: UpdateMessageDto) { try { + if (!this.configService.get('DATABASE').SAVE_DATA.NEW_MESSAGE) { + return data; + } + const msg: any = await this.getMessage(data.key, true); if (msg?.messageType === 'conversation' || msg?.messageType === 'extendedTextMessage') { @@ -3804,13 +3813,15 @@ export class BaileysStartupService extends ChannelStartupService { try { const oldMessage: any = await this.getMessage(data.key, true); - if (!oldMessage) throw new NotFoundException('Message not found'); - if (oldMessage?.key?.remoteJid !== jid) { - throw new BadRequestException('RemoteJid does not match'); - } - if (oldMessage?.messageTimestamp > Date.now() + 900000) { - // 15 minutes in milliseconds - throw new BadRequestException('Message is older than 15 minutes'); + if (this.configService.get('DATABASE').SAVE_DATA.NEW_MESSAGE) { + if (!oldMessage) throw new NotFoundException('Message not found'); + if (oldMessage?.key?.remoteJid !== jid) { + throw new BadRequestException('RemoteJid does not match'); + } + if (oldMessage?.messageTimestamp > Date.now() + 900000) { + // 15 minutes in milliseconds + throw new BadRequestException('Message is older than 15 minutes'); + } } const messageSent = await this.client.sendMessage(jid, { ...(options as any), edit: data.key }); @@ -3828,7 +3839,7 @@ export class BaileysStartupService extends ChannelStartupService { ); const messageId = messageSent.message?.protocolMessage?.key?.id; - if (messageId) { + if (messageId && this.configService.get('DATABASE').SAVE_DATA.NEW_MESSAGE) { let message = await this.prismaRepository.message.findFirst({ where: { key: { path: ['id'], equals: messageId } }, }); @@ -3840,6 +3851,7 @@ export class BaileysStartupService extends ChannelStartupService { if ((message.key.valueOf() as any)?.deleted) { new BadRequestException('You cannot edit deleted messages'); } + if (oldMessage.messageType === 'conversation' || oldMessage.messageType === 'extendedTextMessage') { oldMessage.message.conversation = data.text; } else { @@ -3853,16 +3865,19 @@ export class BaileysStartupService extends ChannelStartupService { messageTimestamp: Math.floor(Date.now() / 1000), // Convert to int32 by dividing by 1000 to get seconds }, }); - const messageUpdate: any = { - messageId: message.id, - keyId: messageId, - remoteJid: messageSent.key.remoteJid, - fromMe: messageSent.key.fromMe, - participant: messageSent.key?.remoteJid, - status: 'EDITED', - instanceId: this.instanceId, - }; - await this.prismaRepository.messageUpdate.create({ data: messageUpdate }); + + if (this.configService.get('DATABASE').SAVE_DATA.MESSAGE_UPDATE) { + const messageUpdate: any = { + messageId: message.id, + keyId: messageId, + remoteJid: messageSent.key.remoteJid, + fromMe: messageSent.key.fromMe, + participant: messageSent.key?.remoteJid, + status: 'EDITED', + instanceId: this.instanceId, + }; + await this.prismaRepository.messageUpdate.create({ data: messageUpdate }); + } } } } From 69726f0dc2b77c6c017d08fd65491195059617c7 Mon Sep 17 00:00:00 2001 From: William Dumes Date: Mon, 28 Jul 2025 09:24:22 -0300 Subject: [PATCH 02/13] fix(evo): melhorado controle de recebimento do ack das msgs --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 02130c434..261b734c4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -55,6 +55,6 @@ COPY --from=builder /evolution/tsup.config.ts ./tsup.config.ts ENV DOCKER_ENV=true -EXPOSE 8080 +EXPOSE 9000 ENTRYPOINT ["/bin/bash", "-c", ". ./Docker/scripts/deploy_database.sh && npm run start:prod" ] From a62f9ebe465fc6a933716b787063387435f1fe7e Mon Sep 17 00:00:00 2001 From: William Dumes Date: Mon, 28 Jul 2025 11:19:07 -0300 Subject: [PATCH 03/13] chore: voltar porta do dockerfile --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 261b734c4..02130c434 100644 --- a/Dockerfile +++ b/Dockerfile @@ -55,6 +55,6 @@ COPY --from=builder /evolution/tsup.config.ts ./tsup.config.ts ENV DOCKER_ENV=true -EXPOSE 9000 +EXPOSE 8080 ENTRYPOINT ["/bin/bash", "-c", ". ./Docker/scripts/deploy_database.sh && npm run start:prod" ] From 095e435561a2eb955f50daee6c9c0ff2fb2c6d21 Mon Sep 17 00:00:00 2001 From: Bilal Iqbal Date: Thu, 31 Jul 2025 14:26:05 +0500 Subject: [PATCH 04/13] Fixed boolean and integer type attributes --- prisma/mysql-schema.prisma | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/prisma/mysql-schema.prisma b/prisma/mysql-schema.prisma index 33d09d2b9..70efea470 100644 --- a/prisma/mysql-schema.prisma +++ b/prisma/mysql-schema.prisma @@ -647,22 +647,22 @@ model IsOnWhatsapp { model N8n { id String @id @default(cuid()) - enabled Boolean @default(true) @db.Boolean + enabled Boolean @default(true) @db.TinyInt(1) description String? @db.VarChar(255) webhookUrl String? @db.VarChar(255) basicAuthUser String? @db.VarChar(255) basicAuthPass String? @db.VarChar(255) expire Int? @default(0) @db.Int keywordFinish String? @db.VarChar(100) - delayMessage Int? @db.Integer + delayMessage Int? @db.Int unknownMessage String? @db.VarChar(100) listeningFromMe Boolean? @default(false) stopBotFromMe Boolean? @default(false) keepOpen Boolean? @default(false) - debounceTime Int? @db.Integer + debounceTime Int? @db.Int ignoreJids Json? splitMessages Boolean? @default(false) - timePerChar Int? @default(50) @db.Integer + timePerChar Int? @default(50) @db.Int triggerType TriggerType? triggerOperator TriggerOperator? triggerValue String? @@ -677,15 +677,15 @@ model N8nSetting { id String @id @default(cuid()) expire Int? @default(0) @db.Int keywordFinish String? @db.VarChar(100) - delayMessage Int? @db.Integer + delayMessage Int? @db.Int unknownMessage String? @db.VarChar(100) listeningFromMe Boolean? @default(false) stopBotFromMe Boolean? @default(false) keepOpen Boolean? @default(false) - debounceTime Int? @db.Integer + debounceTime Int? @db.Int ignoreJids Json? splitMessages Boolean? @default(false) - timePerChar Int? @default(50) @db.Integer + timePerChar Int? @default(50) @db.Int createdAt DateTime? @default(now()) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Fallback N8n? @relation(fields: [n8nIdFallback], references: [id]) @@ -696,21 +696,21 @@ model N8nSetting { model Evoai { id String @id @default(cuid()) - enabled Boolean @default(true) @db.Boolean + enabled Boolean @default(true) @db.TinyInt(1) description String? @db.VarChar(255) agentUrl String? @db.VarChar(255) apiKey String? @db.VarChar(255) expire Int? @default(0) @db.Int keywordFinish String? @db.VarChar(100) - delayMessage Int? @db.Integer + delayMessage Int? @db.Int unknownMessage String? @db.VarChar(100) listeningFromMe Boolean? @default(false) stopBotFromMe Boolean? @default(false) keepOpen Boolean? @default(false) - debounceTime Int? @db.Integer + debounceTime Int? @db.Int ignoreJids Json? splitMessages Boolean? @default(false) - timePerChar Int? @default(50) @db.Integer + timePerChar Int? @default(50) @db.Int triggerType TriggerType? triggerOperator TriggerOperator? triggerValue String? @@ -725,15 +725,15 @@ model EvoaiSetting { id String @id @default(cuid()) expire Int? @default(0) @db.Int keywordFinish String? @db.VarChar(100) - delayMessage Int? @db.Integer + delayMessage Int? @db.Int unknownMessage String? @db.VarChar(100) listeningFromMe Boolean? @default(false) stopBotFromMe Boolean? @default(false) keepOpen Boolean? @default(false) - debounceTime Int? @db.Integer + debounceTime Int? @db.Int ignoreJids Json? splitMessages Boolean? @default(false) - timePerChar Int? @default(50) @db.Integer + timePerChar Int? @default(50) @db.Int createdAt DateTime? @default(now()) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Fallback Evoai? @relation(fields: [evoaiIdFallback], references: [id]) From bc11d0f751f68816db68a46788c6821d7328de2f Mon Sep 17 00:00:00 2001 From: William Dumes Date: Thu, 31 Jul 2025 17:27:06 -0300 Subject: [PATCH 05/13] fix: corrigido delete de mensagem quando nao salvo no banco de dados --- .../integrations/channel/whatsapp/whatsapp.baileys.service.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts index 7d7da2be8..8496a7592 100644 --- a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts +++ b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts @@ -3447,6 +3447,7 @@ export class BaileysStartupService extends ChannelStartupService { await this.prismaRepository.messageUpdate.create({ data: messageUpdate }); } } else { + if (!message) return response; await this.prismaRepository.message.deleteMany({ where: { id: message.id } }); } this.sendDataWebhook(Events.MESSAGES_DELETE, { From 79f4a22217e6cb52e9ed41254c5f1037ed545aa4 Mon Sep 17 00:00:00 2001 From: William Dumes Date: Mon, 4 Aug 2025 13:56:16 -0300 Subject: [PATCH 06/13] refactor: lint check --- .../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 f9dbeed0c..c036a2818 100644 --- a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts +++ b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts @@ -1482,7 +1482,7 @@ export class BaileysStartupService extends ChannelStartupService { continue; } - + if (findMessage && update.status !== undefined && status[update.status] !== findMessage.status) { if (!key.fromMe && key.remoteJid) { readChatToUpdate[key.remoteJid] = true; From 4f043f9576bbda13b16ae47981fd77151a199fad Mon Sep 17 00:00:00 2001 From: Felipe Augusto Rieck Date: Mon, 4 Aug 2025 16:34:20 -0300 Subject: [PATCH 07/13] Securing websockets --- src/api/integrations/event/websocket/websocket.controller.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/api/integrations/event/websocket/websocket.controller.ts b/src/api/integrations/event/websocket/websocket.controller.ts index a1cef2dbc..c0d3e5def 100644 --- a/src/api/integrations/event/websocket/websocket.controller.ts +++ b/src/api/integrations/event/websocket/websocket.controller.ts @@ -28,10 +28,11 @@ export class WebsocketController extends EventController implements EventControl allowRequest: async (req, callback) => { try { const url = new URL(req.url || '', 'http://localhost'); + const isInternalConnection = req.socket.remoteAddress === '127.0.0.1' || req.socket.remoteAddress === '::1'; const params = new URLSearchParams(url.search); // Permite conexões internas do Socket.IO (EIO=4 é o Engine.IO v4) - if (params.has('EIO')) { + if (params.has('EIO') && isInternalConnection) { return callback(null, true); } From d4eb61f64d9fe263270146926e973018cf803880 Mon Sep 17 00:00:00 2001 From: Felipe Augusto Rieck Date: Mon, 4 Aug 2025 18:14:33 -0300 Subject: [PATCH 08/13] Improving localhost check --- .../integrations/event/websocket/websocket.controller.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/api/integrations/event/websocket/websocket.controller.ts b/src/api/integrations/event/websocket/websocket.controller.ts index c0d3e5def..f7250b7ac 100644 --- a/src/api/integrations/event/websocket/websocket.controller.ts +++ b/src/api/integrations/event/websocket/websocket.controller.ts @@ -28,11 +28,14 @@ export class WebsocketController extends EventController implements EventControl allowRequest: async (req, callback) => { try { const url = new URL(req.url || '', 'http://localhost'); - const isInternalConnection = req.socket.remoteAddress === '127.0.0.1' || req.socket.remoteAddress === '::1'; const params = new URLSearchParams(url.search); + const remoteAddress = req.socket.remoteAddress; + const isLocalhost = + remoteAddress === '127.0.0.1' || remoteAddress === '::1' || remoteAddress === '::ffff:127.0.0.1'; + // Permite conexões internas do Socket.IO (EIO=4 é o Engine.IO v4) - if (params.has('EIO') && isInternalConnection) { + if (params.has('EIO') && isLocalhost) { return callback(null, true); } From fb11f3f99cc19bf1631cb42538e29eb46cb87484 Mon Sep 17 00:00:00 2001 From: Felipe Augusto Rieck Date: Mon, 4 Aug 2025 18:19:14 -0300 Subject: [PATCH 09/13] Code quality --- src/api/integrations/event/websocket/websocket.controller.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/integrations/event/websocket/websocket.controller.ts b/src/api/integrations/event/websocket/websocket.controller.ts index f7250b7ac..3f4afd9b1 100644 --- a/src/api/integrations/event/websocket/websocket.controller.ts +++ b/src/api/integrations/event/websocket/websocket.controller.ts @@ -30,7 +30,7 @@ export class WebsocketController extends EventController implements EventControl const url = new URL(req.url || '', 'http://localhost'); const params = new URLSearchParams(url.search); - const remoteAddress = req.socket.remoteAddress; + const { remoteAddress } = req.socket; const isLocalhost = remoteAddress === '127.0.0.1' || remoteAddress === '::1' || remoteAddress === '::ffff:127.0.0.1'; From 3390958314f20b603788b7a975694014110b0975 Mon Sep 17 00:00:00 2001 From: Henry Barreto Date: Fri, 1 Aug 2025 19:40:39 -0300 Subject: [PATCH 10/13] feat: add support to socks proxy --- package-lock.json | 64 +++++++++++++++++++++++++++++++++++++ package.json | 1 + src/utils/makeProxyAgent.ts | 27 ++++++++++++++-- 3 files changed, 89 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index bb9f0c484..6e81cc530 100644 --- a/package-lock.json +++ b/package-lock.json @@ -60,6 +60,7 @@ "sharp": "^0.34.2", "socket.io": "^4.8.1", "socket.io-client": "^4.8.1", + "socks-proxy-agent": "^8.0.5", "swagger-ui-express": "^5.0.1", "tsup": "^8.3.5" }, @@ -7739,6 +7740,19 @@ "node": ">= 0.4" } }, + "node_modules/ip-address": { + "version": "9.0.5", + "resolved": "https://registry.npmjs.org/ip-address/-/ip-address-9.0.5.tgz", + "integrity": "sha512-zHtQzGojZXTwZTHQqra+ETKd4Sn3vgi7uBmlPoXVWZqYvuKmtI0l/VZTjqGmJY9x88GGOaZ9+G9ES8hC4T4X8g==", + "license": "MIT", + "dependencies": { + "jsbn": "1.1.0", + "sprintf-js": "^1.1.3" + }, + "engines": { + "node": ">= 12" + } + }, "node_modules/ipaddr.js": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-2.2.0.tgz", @@ -8249,6 +8263,12 @@ "js-yaml": "bin/js-yaml.js" } }, + "node_modules/jsbn": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-1.1.0.tgz", + "integrity": "sha512-4bYVV3aAMtDTTu4+xsDYa6sy9GyJ69/amsu9sYF2zqjiEoZA5xJi3BrfX3uY+/IekIu7MwdObdbDWpoZdBv3/A==", + "license": "MIT" + }, "node_modules/json-buffer": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.1.tgz", @@ -10761,6 +10781,16 @@ "node": ">=8" } }, + "node_modules/smart-buffer": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/smart-buffer/-/smart-buffer-4.2.0.tgz", + "integrity": "sha512-94hK0Hh8rPqQl2xXc3HsaBoOXKV20MToPkcXvwbISWLEs+64sBq5kFgn2kJDHb1Pry9yrP0dxrCI9RRci7RXKg==", + "license": "MIT", + "engines": { + "node": ">= 6.0.0", + "npm": ">= 3.0.0" + } + }, "node_modules/socket.io": { "version": "4.8.1", "resolved": "https://registry.npmjs.org/socket.io/-/socket.io-4.8.1.tgz", @@ -10897,6 +10927,34 @@ } } }, + "node_modules/socks": { + "version": "2.8.6", + "resolved": "https://registry.npmjs.org/socks/-/socks-2.8.6.tgz", + "integrity": "sha512-pe4Y2yzru68lXCb38aAqRf5gvN8YdjP1lok5o0J7BOHljkyCGKVz7H3vpVIXKD27rj2giOJ7DwVyk/GWrPHDWA==", + "license": "MIT", + "dependencies": { + "ip-address": "^9.0.5", + "smart-buffer": "^4.2.0" + }, + "engines": { + "node": ">= 10.0.0", + "npm": ">= 3.0.0" + } + }, + "node_modules/socks-proxy-agent": { + "version": "8.0.5", + "resolved": "https://registry.npmjs.org/socks-proxy-agent/-/socks-proxy-agent-8.0.5.tgz", + "integrity": "sha512-HehCEsotFqbPW9sJ8WVYB6UbmIMv7kUUORIF2Nncq4VQvBfNBLibW9YZR5dlYCSUhwcD628pRllm7n+E+YTzJw==", + "license": "MIT", + "dependencies": { + "agent-base": "^7.1.2", + "debug": "^4.3.4", + "socks": "^2.8.3" + }, + "engines": { + "node": ">= 14" + } + }, "node_modules/sonic-boom": { "version": "3.8.1", "resolved": "https://registry.npmjs.org/sonic-boom/-/sonic-boom-3.8.1.tgz", @@ -10921,6 +10979,12 @@ "node": ">= 10.x" } }, + "node_modules/sprintf-js": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.1.3.tgz", + "integrity": "sha512-Oo+0REFV59/rz3gfJNKQiBlwfHaSESl1pcGyABQsnnIfWOFt6JNj5gCog2U6MLZ//IGYD+nA8nI+mTShREReaA==", + "license": "BSD-3-Clause" + }, "node_modules/statuses": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz", diff --git a/package.json b/package.json index 9de9d07cb..107cca49f 100644 --- a/package.json +++ b/package.json @@ -100,6 +100,7 @@ "sharp": "^0.34.2", "socket.io": "^4.8.1", "socket.io-client": "^4.8.1", + "socks-proxy-agent": "^8.0.5", "swagger-ui-express": "^5.0.1", "tsup": "^8.3.5" }, diff --git a/src/utils/makeProxyAgent.ts b/src/utils/makeProxyAgent.ts index dcf560f6d..3b1379bde 100644 --- a/src/utils/makeProxyAgent.ts +++ b/src/utils/makeProxyAgent.ts @@ -1,4 +1,5 @@ import { HttpsProxyAgent } from 'https-proxy-agent'; +import { SocksProxyAgent } from 'socks-proxy-agent'; type Proxy = { host: string; @@ -8,9 +9,28 @@ type Proxy = { username?: string; }; -export function makeProxyAgent(proxy: Proxy | string) { +function selectProxyAgent(proxyUrl: string): HttpsProxyAgent | SocksProxyAgent { + const url = new URL(proxyUrl); + + // NOTE: The following constants are not used in the function but are defined for clarity. + // When a proxy URL is used to build the URL object, the protocol returned by procotol's property contains a `:` at + // the end so, we add the protocol constants without the `:` to avoid confusion. + const PROXY_HTTP_PROTOCOL = 'http:'; + const PROXY_SOCKS_PROTOCOL = 'socks:'; + + switch (url.protocol) { + case PROXY_HTTP_PROTOCOL: + return new HttpsProxyAgent(url); + case PROXY_SOCKS_PROTOCOL: + return new SocksProxyAgent(url); + default: + throw new Error(`Unsupported proxy protocol: ${url.protocol}`); + } +} + +export function makeProxyAgent(proxy: Proxy | string): HttpsProxyAgent | SocksProxyAgent { if (typeof proxy === 'string') { - return new HttpsProxyAgent(proxy); + return selectProxyAgent(proxy); } const { host, password, port, protocol, username } = proxy; @@ -19,5 +39,6 @@ export function makeProxyAgent(proxy: Proxy | string) { if (username && password) { proxyUrl = `${protocol}://${username}:${password}@${host}:${port}`; } - return new HttpsProxyAgent(proxyUrl); + + return selectProxyAgent(proxyUrl); } From ab9e0edad684ec9ca6a15a4422ff3e01393f9ebd Mon Sep 17 00:00:00 2001 From: Henry Barreto Date: Fri, 1 Aug 2025 12:49:15 -0300 Subject: [PATCH 11/13] feat: enhance logging for proxy testing errors This commit improves the logging in the testProxy method of the ProxyController class. Now, when an Axios error occurs, the specific error message will be logged if available. For unexpected errors, the error object is included for better insight. For reference, see the "message" field in the Axios documentation: [Axios Error Handling](https://axios-http.com/docs/handling_errors). --- src/api/controllers/proxy.controller.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/api/controllers/proxy.controller.ts b/src/api/controllers/proxy.controller.ts index fac003759..b6e7d153a 100644 --- a/src/api/controllers/proxy.controller.ts +++ b/src/api/controllers/proxy.controller.ts @@ -53,15 +53,21 @@ export class ProxyController { httpsAgent: makeProxyAgent(proxy), }); - return response?.data !== serverIp?.data; + const result = response?.data !== serverIp?.data; + if (result) { + logger.info('testProxy: proxy connection successful'); + } else { + logger.warn("testProxy: proxy connection doesn't change the origin IP"); + } + + return result; } catch (error) { - if (axios.isAxiosError(error) && error.response?.data) { - logger.error('testProxy error: ' + error.response.data); - } else if (axios.isAxiosError(error)) { - logger.error('testProxy error: '); + if (axios.isAxiosError(error)) { + logger.error('testProxy error: axios error: ' + error.message); } else { - logger.error('testProxy error: '); + logger.error('testProxy error: unexpected error: ' + error); } + return false; } } From 4945345519478345d04becafabd055e566de7ad6 Mon Sep 17 00:00:00 2001 From: "Neto, Aristides da Silva" Date: Tue, 5 Aug 2025 22:07:20 -0300 Subject: [PATCH 12/13] docs(readme): corrigidos badge Docker image no README MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Corrigida formatação do badge Docker image no README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9ad5fa0ae..6d9b33441 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@
-[![Docker Image (https://img.shields.io/badge/Docker-Image-blue)](https://hub.docker.com/r/evoapicloud/evolution-api)] +[![Docker Image](https://img.shields.io/badge/Docker-image-blue)](https://hub.docker.com/r/evoapicloud/evolution-api) [![Whatsapp Group](https://img.shields.io/badge/Group-WhatsApp-%2322BC18)](https://evolution-api.com/whatsapp) [![Discord Community](https://img.shields.io/badge/Discord-Community-blue)](https://evolution-api.com/discord) [![Postman Collection](https://img.shields.io/badge/Postman-Collection-orange)](https://evolution-api.com/postman) From 74cb65c4ea9ee84f4b85eb238773e94e73cd2add Mon Sep 17 00:00:00 2001 From: Bilal Iqbal Date: Thu, 14 Aug 2025 00:51:41 +0500 Subject: [PATCH 13/13] Added key id into webhook payload in n8n service --- src/api/integrations/chatbot/n8n/services/n8n.service.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/api/integrations/chatbot/n8n/services/n8n.service.ts b/src/api/integrations/chatbot/n8n/services/n8n.service.ts index 2d0802b9c..5bb408904 100644 --- a/src/api/integrations/chatbot/n8n/services/n8n.service.ts +++ b/src/api/integrations/chatbot/n8n/services/n8n.service.ts @@ -49,6 +49,7 @@ export class N8nService extends BaseChatbotService { sessionId: session.sessionId, remoteJid: remoteJid, pushName: pushName, + keyId: msg?.key?.id, fromMe: msg?.key?.fromMe, instanceName: instance.instanceName, serverUrl: this.configService.get('SERVER').URL,