From ca0394c5699815b09a43a1759b62a1df48154821 Mon Sep 17 00:00:00 2001 From: Danilo de Souza Date: Wed, 9 Jul 2025 08:19:09 -0300 Subject: [PATCH 01/12] Feat: Simplify docker-compose file --- docker-compose.yml | 66 +++++----------------------------------------- 1 file changed, 6 insertions(+), 60 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 71c1dc16..c455d0d2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,5 +1,3 @@ -version: '3.8' - networks: public-network: driver: bridge @@ -7,67 +5,15 @@ networks: services: api: container_name: codechat_api - image: codechat/api:v1.3.4 + build: + context: . + dockerfile: Dockerfile restart: unless-stopped ports: - 8084:8084 volumes: - - instances_connecteds:/codechat/instances - environment: - - SERVER_PORT=8084 - - SESSION_SECRET=W0NvZGVDaGF0XTpbU2Vzc - - - LOG_LEVEL=ERROR|WARN|INFO|DEBUG|LOG|VERBOSE|DARK - - LOG_COLOR=true - - - DATABASE_ENABLED=true - - DATABASE_URL=postgres://[USER]:[PASS]@[HOST]:[PORT]/[DATABASE_NAME]?schema=public - - DATABASE_SYNC_MESSAGES=true - - DATABASE_SAVE_DATA_NEW_MESSAGE=true - - DATABASE_SAVE_MESSAGE_UPDATE=true - - DATABASE_SAVE_DATA_CONTACTS=true - - DATABASE_SAVE_DATA_CHATS=true - - - GLOBAL_WEBHOOK_URL=url - - GLOBAL_WEBHOOK_ENABLED=false - - - INSTANCE_EXPIRATION_TIME=false - - - CONFIG_SESSION_PHONE_CLIENT=CodeChat_V1 - - CONFIG_SESSION_PHONE_NAME=Edge - - - WA_VERSION=[ 2, 3000, 1023235404 ] - - - QRCODE_LIMIT=10 - - QRCODE_EXPIRATION_TIME=60 - - QRCODE_LIGHT_COLOR='#ffffff' - - QRCODE_DARK_COLOR='#198754' - - - CONNECTION_TIMEOUT=300 - - - AUTHENTICATION_GLOBAL_AUTH_TOKEN=zYzP7ocstxh3SJ23D4FZTCu4ehnM8v4hu - - AUTHENTICATION_JWT_EXPIRES_IN=0 - - AUTHENTICATION_JWT_SECRET=3RFYiiRmvNiokSBrLZzx - - - PROVIDER_ENABLED=false - - PROVIDER_HOST=127.0.0.1 - - PROVIDER_PORT=5656 - - PROVIDER_PREFIX=codechat - - - BASE_URL= - - # - S3_ENABLED=false - # - S3_ACCESS_KEY=[ACCESS_KEY] - # - S3_SECRET_KEY=[SECRET_KEY] - # - S3_BUCKET=[BUCKET] - # - S3_PORT=9000 - # - S3_ENDPOINT=[ENDPOINT] - # - S3_USE_SSL=false + - ./instances:/codechat/instances + env_file: + - .env networks: - public-network - -volumes: - # In terminal run: docker volume create --name=instances_connecteds - instances_connecteds: - external: - name: instances_connecteds From 445240e63d85e53ee702d3e5b2925f7bfa35f40b Mon Sep 17 00:00:00 2001 From: Danilo de Souza Date: Mon, 18 Aug 2025 09:28:04 -0300 Subject: [PATCH 02/12] Fix: Ordering message by id desc --- src/whatsapp/services/whatsapp.service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/whatsapp/services/whatsapp.service.ts b/src/whatsapp/services/whatsapp.service.ts index 4dadfebf..ca822227 100644 --- a/src/whatsapp/services/whatsapp.service.ts +++ b/src/whatsapp/services/whatsapp.service.ts @@ -2309,7 +2309,7 @@ export class WAStartupService { const messages = await this.repository.message.findMany({ where, orderBy: { - messageTimestamp: 'desc', + id: 'desc', }, skip: query.offset * (query?.page === 1 ? 0 : (query?.page as number) - 1), take: query.offset, From a0ee436a8d6559bd291d283d18437a961f78c252 Mon Sep 17 00:00:00 2001 From: Danilo de Souza Date: Mon, 18 Aug 2025 10:23:35 -0300 Subject: [PATCH 03/12] Fix: Undo last commit --- src/whatsapp/services/whatsapp.service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/whatsapp/services/whatsapp.service.ts b/src/whatsapp/services/whatsapp.service.ts index ca822227..4dadfebf 100644 --- a/src/whatsapp/services/whatsapp.service.ts +++ b/src/whatsapp/services/whatsapp.service.ts @@ -2309,7 +2309,7 @@ export class WAStartupService { const messages = await this.repository.message.findMany({ where, orderBy: { - id: 'desc', + messageTimestamp: 'desc', }, skip: query.offset * (query?.page === 1 ? 0 : (query?.page as number) - 1), take: query.offset, From 52aa0a5bacdd48aad21ceb70114d2fe79b94ca1b Mon Sep 17 00:00:00 2001 From: Danilo de Souza Date: Mon, 25 Aug 2025 13:17:22 -0300 Subject: [PATCH 04/12] Feat: Adds a centralized axios in whatsapp.service.ts with connection pooling --- src/whatsapp/services/whatsapp.service.ts | 28 +++++++++++++++++------ 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/src/whatsapp/services/whatsapp.service.ts b/src/whatsapp/services/whatsapp.service.ts index f5efe313..5b867894 100644 --- a/src/whatsapp/services/whatsapp.service.ts +++ b/src/whatsapp/services/whatsapp.service.ts @@ -81,7 +81,7 @@ import { import { Logger } from '../../config/logger.config'; import { INSTANCE_DIR, ROOT_DIR } from '../../config/path.config'; import { join, normalize } from 'path'; -import axios, { AxiosError } from 'axios'; +import axios, { AxiosError, AxiosInstance } from 'axios'; import qrcode, { QRCodeToDataURLOptions } from 'qrcode'; import qrcodeTerminal from 'qrcode-terminal'; import { Boom } from '@hapi/boom'; @@ -151,6 +151,7 @@ import { unlinkSync, writeFileSync, } from 'fs'; +import http from 'http'; type InstanceQrCode = { count: number; @@ -175,6 +176,18 @@ export class WAStartupService { this.configService, this.providerFiles, ); + + const httpAgent = new http.Agent({ + keepAlive: true, + maxSockets: 100, + maxFreeSockets: 10, + timeout: 60000 + }) + + this.axiosInstance = axios.create({ + httpAgent, + timeout: 10000 + }) } private readonly logger = new Logger(this.configService, WAStartupService.name); @@ -186,6 +199,7 @@ export class WAStartupService { private readonly stateConnection: InstanceStateConnection = { state: 'close' }; private readonly databaseOptions: Database = this.configService.get('DATABASE'); + private readonly axiosInstance: AxiosInstance; private endSession = false; public client: WASocket; @@ -278,7 +292,7 @@ export class WAStartupService { try { if (this.webhook?.enabled) { if (this.webhook?.events && this.webhook?.events[event]) { - await axios.post( + await this.axiosInstance.post( this.webhook.url, { event: eventDesc, @@ -289,7 +303,7 @@ export class WAStartupService { ); } if (!this.webhook?.events) { - await axios.post( + await this.axiosInstance.post( this.webhook.url, { event: eventDesc, @@ -323,7 +337,7 @@ export class WAStartupService { try { const globalWebhook = this.configService.get('GLOBAL_WEBHOOK'); if (globalWebhook?.ENABLED && isURL(globalWebhook.URL)) { - await axios.post( + await this.axiosInstance.post( globalWebhook.URL, { event: eventDesc, @@ -1527,7 +1541,7 @@ export class WAStartupService { const isURL = /http(s?):\/\//.test(mediaMessage.media as string); if (isURL) { - const response = await axios.get(mediaMessage.media as string, { + const response = await this.axiosInstance.get(mediaMessage.media as string, { responseType: 'arraybuffer', }); @@ -1922,7 +1936,7 @@ export class WAStartupService { jpegThumbnail: await (async () => { if (data.linkMessage?.thumbnailUrl) { try { - const response = await axios.get(data.linkMessage.thumbnailUrl, { + const response = await this.axiosInstance.get(data.linkMessage.thumbnailUrl, { responseType: 'arraybuffer', }); return new Uint8Array(response.data); @@ -2410,7 +2424,7 @@ export class WAStartupService { try { let pic: WAMediaUpload; if (isURL(picture.image)) { - pic = (await axios.get(picture.image, { responseType: 'arraybuffer' })).data; + pic = (await this.axiosInstance.get(picture.image, { responseType: 'arraybuffer' })).data; } else if (isBase64(picture.image)) { pic = Buffer.from(picture.image, 'base64'); } else { From cf38e3ed66bd9a56096cd5efa06f0379ea9ec73e Mon Sep 17 00:00:00 2001 From: Danilo de Souza Date: Mon, 25 Aug 2025 14:53:52 -0300 Subject: [PATCH 05/12] Feat: Adds timeout of 60 seconds to whatsapp request --- src/whatsapp/services/whatsapp.service.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/whatsapp/services/whatsapp.service.ts b/src/whatsapp/services/whatsapp.service.ts index 5b867894..91efdb75 100644 --- a/src/whatsapp/services/whatsapp.service.ts +++ b/src/whatsapp/services/whatsapp.service.ts @@ -182,12 +182,12 @@ export class WAStartupService { maxSockets: 100, maxFreeSockets: 10, timeout: 60000 - }) + }); this.axiosInstance = axios.create({ httpAgent, - timeout: 10000 - }) + timeout: 60000 + }); } private readonly logger = new Logger(this.configService, WAStartupService.name); From 8eab3d6970bd0f5a05c3aa2ec935e779ff04141b Mon Sep 17 00:00:00 2001 From: Danilo de Souza Date: Wed, 9 Jul 2025 08:19:09 -0300 Subject: [PATCH 06/12] Feat: Simplify docker-compose file --- docker-compose.yml | 66 +++++----------------------------------------- 1 file changed, 6 insertions(+), 60 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 71c1dc16..c455d0d2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,5 +1,3 @@ -version: '3.8' - networks: public-network: driver: bridge @@ -7,67 +5,15 @@ networks: services: api: container_name: codechat_api - image: codechat/api:v1.3.4 + build: + context: . + dockerfile: Dockerfile restart: unless-stopped ports: - 8084:8084 volumes: - - instances_connecteds:/codechat/instances - environment: - - SERVER_PORT=8084 - - SESSION_SECRET=W0NvZGVDaGF0XTpbU2Vzc - - - LOG_LEVEL=ERROR|WARN|INFO|DEBUG|LOG|VERBOSE|DARK - - LOG_COLOR=true - - - DATABASE_ENABLED=true - - DATABASE_URL=postgres://[USER]:[PASS]@[HOST]:[PORT]/[DATABASE_NAME]?schema=public - - DATABASE_SYNC_MESSAGES=true - - DATABASE_SAVE_DATA_NEW_MESSAGE=true - - DATABASE_SAVE_MESSAGE_UPDATE=true - - DATABASE_SAVE_DATA_CONTACTS=true - - DATABASE_SAVE_DATA_CHATS=true - - - GLOBAL_WEBHOOK_URL=url - - GLOBAL_WEBHOOK_ENABLED=false - - - INSTANCE_EXPIRATION_TIME=false - - - CONFIG_SESSION_PHONE_CLIENT=CodeChat_V1 - - CONFIG_SESSION_PHONE_NAME=Edge - - - WA_VERSION=[ 2, 3000, 1023235404 ] - - - QRCODE_LIMIT=10 - - QRCODE_EXPIRATION_TIME=60 - - QRCODE_LIGHT_COLOR='#ffffff' - - QRCODE_DARK_COLOR='#198754' - - - CONNECTION_TIMEOUT=300 - - - AUTHENTICATION_GLOBAL_AUTH_TOKEN=zYzP7ocstxh3SJ23D4FZTCu4ehnM8v4hu - - AUTHENTICATION_JWT_EXPIRES_IN=0 - - AUTHENTICATION_JWT_SECRET=3RFYiiRmvNiokSBrLZzx - - - PROVIDER_ENABLED=false - - PROVIDER_HOST=127.0.0.1 - - PROVIDER_PORT=5656 - - PROVIDER_PREFIX=codechat - - - BASE_URL= - - # - S3_ENABLED=false - # - S3_ACCESS_KEY=[ACCESS_KEY] - # - S3_SECRET_KEY=[SECRET_KEY] - # - S3_BUCKET=[BUCKET] - # - S3_PORT=9000 - # - S3_ENDPOINT=[ENDPOINT] - # - S3_USE_SSL=false + - ./instances:/codechat/instances + env_file: + - .env networks: - public-network - -volumes: - # In terminal run: docker volume create --name=instances_connecteds - instances_connecteds: - external: - name: instances_connecteds From 0a5893623bad7f48b56df803ca752fc39a8d368d Mon Sep 17 00:00:00 2001 From: Danilo de Souza Date: Mon, 18 Aug 2025 09:28:04 -0300 Subject: [PATCH 07/12] Fix: Ordering message by id desc --- src/whatsapp/services/whatsapp.service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/whatsapp/services/whatsapp.service.ts b/src/whatsapp/services/whatsapp.service.ts index 822fc901..a32cec2c 100644 --- a/src/whatsapp/services/whatsapp.service.ts +++ b/src/whatsapp/services/whatsapp.service.ts @@ -2319,7 +2319,7 @@ export class WAStartupService { const messages = await this.repository.message.findMany({ where, orderBy: { - messageTimestamp: 'desc', + id: 'desc', }, skip: query.offset * (query?.page === 1 ? 0 : query?.page - 1), take: query.offset, From 1945383f792f2e33ef0d966908e219ecaef0080a Mon Sep 17 00:00:00 2001 From: Danilo de Souza Date: Mon, 18 Aug 2025 10:23:35 -0300 Subject: [PATCH 08/12] Fix: Undo last commit --- src/whatsapp/services/whatsapp.service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/whatsapp/services/whatsapp.service.ts b/src/whatsapp/services/whatsapp.service.ts index a32cec2c..822fc901 100644 --- a/src/whatsapp/services/whatsapp.service.ts +++ b/src/whatsapp/services/whatsapp.service.ts @@ -2319,7 +2319,7 @@ export class WAStartupService { const messages = await this.repository.message.findMany({ where, orderBy: { - id: 'desc', + messageTimestamp: 'desc', }, skip: query.offset * (query?.page === 1 ? 0 : query?.page - 1), take: query.offset, From 3b6c29cbddb3d9e971c4f32f6d13c17f354df5ac Mon Sep 17 00:00:00 2001 From: Danilo de Souza Date: Mon, 25 Aug 2025 13:17:22 -0300 Subject: [PATCH 09/12] Feat: Adds a centralized axios in whatsapp.service.ts with connection pooling --- src/whatsapp/services/whatsapp.service.ts | 134 ++++++++++++---------- 1 file changed, 72 insertions(+), 62 deletions(-) diff --git a/src/whatsapp/services/whatsapp.service.ts b/src/whatsapp/services/whatsapp.service.ts index 822fc901..da46b240 100644 --- a/src/whatsapp/services/whatsapp.service.ts +++ b/src/whatsapp/services/whatsapp.service.ts @@ -37,6 +37,8 @@ * └──────────────────────────────────────────────────────────────────────────────┘ */ +import { Boom } from '@hapi/boom'; +import PrismType, { Instance, Webhook } from '@prisma/client'; import makeWASocket, { AnyMessageContent, BaileysEventMap, @@ -71,43 +73,54 @@ import makeWASocket, { WAMessageUpdate, WASocket, } from '@whiskeysockets/baileys'; +import axios, { AxiosError, AxiosInstance } from 'axios'; +import { isArray, isBase64, isInt, isNotEmpty, isURL } from 'class-validator'; +import EventEmitter2 from 'eventemitter2'; +import ffmpeg from 'fluent-ffmpeg'; +import { + accessSync, + constants, + existsSync, + readFileSync, + rmSync, + unlinkSync, + writeFileSync, +} from 'fs'; +import http from 'http'; +import mime from 'mime-types'; +import NodeCache from 'node-cache'; +import { release } from 'os'; +import { join, normalize } from 'path'; +import P from 'pino'; +import qrcode, { QRCodeToDataURLOptions } from 'qrcode'; +import qrcodeTerminal from 'qrcode-terminal'; +import sharp from 'sharp'; +import { PassThrough } from 'stream'; +import { ulid } from 'ulid'; import { ConfigService, ConfigSessionPhone, Database, + EnvProxy, GlobalWebhook, - QrCode, ProviderSession, - EnvProxy, + QrCode, } from '../../config/env.config'; import { Logger } from '../../config/logger.config'; import { INSTANCE_DIR, ROOT_DIR } from '../../config/path.config'; -import { join, normalize } from 'path'; -import axios, { AxiosError } from 'axios'; -import qrcode, { QRCodeToDataURLOptions } from 'qrcode'; -import qrcodeTerminal from 'qrcode-terminal'; -import { Boom } from '@hapi/boom'; -import EventEmitter2 from 'eventemitter2'; -import { release } from 'os'; -import P from 'pino'; +import { BadRequestException, InternalServerErrorException } from '../../exceptions'; +import * as s3Service from '../../integrations/minio/minio.utils'; +import { ProviderFiles } from '../../provider/sessions'; +import { Query, Repository } from '../../repository/repository.service'; +import { getJidUser, getUserGroup } from '../../utils/extract-id'; +import { createProxyAgents } from '../../utils/proxy'; import { - AudioMessageFileDto, - ContactMessage, - MediaFileDto, - MediaMessage, - Options, - SendAudioDto, - SendButtonsDto, - SendContactDto, - SendLinkDto, - SendListDto, - SendListLegacyDto, - SendLocationDto, - SendMediaDto, - SendReactionDto, - SendTextDto, -} from '../dto/sendMessage.dto'; -import { isArray, isBase64, isInt, isNotEmpty, isURL } from 'class-validator'; + AuthState, + AuthStateProvider, +} from '../../utils/use-multi-file-auth-state-provider-files'; +import { fetchLatestBaileysVersionV2 } from '../../utils/wa-version'; +import { isValidUlid } from '../../validate/ulid'; +import { Websocket } from '../../websocket/server'; import { ArchiveChatDto, DeleteMessage, @@ -119,43 +132,27 @@ import { UpdatePresenceDto, WhatsAppNumberDto, } from '../dto/chat.dto'; -import { BadRequestException, InternalServerErrorException } from '../../exceptions'; import { CreateGroupDto, GroupJid, GroupPictureDto, GroupUpdateParticipantDto, } from '../dto/group.dto'; -import NodeCache from 'node-cache'; import { - AuthState, - AuthStateProvider, -} from '../../utils/use-multi-file-auth-state-provider-files'; -import mime from 'mime-types'; -import { Instance, Webhook } from '@prisma/client'; + AudioMessageFileDto, + ContactMessage, + MediaFileDto, + MediaMessage, + Options, + SendAudioDto, + SendContactDto, + SendLinkDto, + SendLocationDto, + SendMediaDto, + SendReactionDto, + SendTextDto +} from '../dto/sendMessage.dto'; import { WebhookEvents, WebhookEventsEnum, WebhookEventsType } from '../dto/webhook.dto'; -import { Query, Repository } from '../../repository/repository.service'; -import PrismType from '@prisma/client'; -import * as s3Service from '../../integrations/minio/minio.utils'; -import { ProviderFiles } from '../../provider/sessions'; -import { Websocket } from '../../websocket/server'; -import { ulid } from 'ulid'; -import { isValidUlid } from '../../validate/ulid'; -import sharp from 'sharp'; -import ffmpeg from 'fluent-ffmpeg'; -import { PassThrough } from 'stream'; -import { - accessSync, - constants, - existsSync, - readFileSync, - rmSync, - unlinkSync, - writeFileSync, -} from 'fs'; -import { createProxyAgents } from '../../utils/proxy'; -import { fetchLatestBaileysVersionV2 } from '../../utils/wa-version'; -import { getJidUser, getUserGroup } from '../../utils/extract-id'; type InstanceQrCode = { count: number; @@ -180,6 +177,18 @@ export class WAStartupService { this.configService, this.providerFiles, ); + + const httpAgent = new http.Agent({ + keepAlive: true, + maxSockets: 100, + maxFreeSockets: 10, + timeout: 60000 + }) + + this.axiosInstance = axios.create({ + httpAgent, + timeout: 10000 + }) } private readonly logger = new Logger(this.configService, WAStartupService.name); @@ -191,6 +200,7 @@ export class WAStartupService { private readonly stateConnection: InstanceStateConnection = { state: 'close' }; private readonly databaseOptions: Database = this.configService.get('DATABASE'); + private readonly axiosInstance: AxiosInstance; private endSession = false; public client: WASocket; @@ -297,7 +307,7 @@ export class WAStartupService { try { if (this.webhook?.enabled) { if (this.webhook?.events && this.webhook?.events[event]) { - await axios.post( + await this.axiosInstance.post( this.webhook.url, { event: eventDesc, @@ -308,7 +318,7 @@ export class WAStartupService { ); } if (!this.webhook?.events) { - await axios.post( + await this.axiosInstance.post( this.webhook.url, { event: eventDesc, @@ -342,7 +352,7 @@ export class WAStartupService { try { const globalWebhook = this.configService.get('GLOBAL_WEBHOOK'); if (globalWebhook?.ENABLED && isURL(globalWebhook.URL)) { - await axios.post( + await this.axiosInstance.post( globalWebhook.URL, { event: eventDesc, @@ -1654,7 +1664,7 @@ export class WAStartupService { const isURL = /http(s?):\/\//.test(mediaMessage.media as string); if (isURL) { - const response = await axios.get(mediaMessage.media as string, { + const response = await this.axiosInstance.get(mediaMessage.media as string, { responseType: 'arraybuffer', }); @@ -1927,7 +1937,7 @@ export class WAStartupService { jpegThumbnail: await (async () => { if (data.linkMessage?.thumbnailUrl) { try { - const response = await axios.get(data.linkMessage.thumbnailUrl, { + const response = await this.axiosInstance.get(data.linkMessage.thumbnailUrl, { responseType: 'arraybuffer', }); return new Uint8Array(response.data); @@ -2417,7 +2427,7 @@ export class WAStartupService { try { let pic: WAMediaUpload; if (isURL(picture.image)) { - pic = (await axios.get(picture.image, { responseType: 'arraybuffer' })).data; + pic = (await this.axiosInstance.get(picture.image, { responseType: 'arraybuffer' })).data; } else if (isBase64(picture.image)) { pic = Buffer.from(picture.image, 'base64'); } else { From f26f5fa0d169ec5d3a89a50f3f916cdbcc080254 Mon Sep 17 00:00:00 2001 From: Danilo de Souza Date: Mon, 25 Aug 2025 14:53:52 -0300 Subject: [PATCH 10/12] Feat: Adds timeout of 60 seconds to whatsapp request --- src/whatsapp/services/whatsapp.service.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/whatsapp/services/whatsapp.service.ts b/src/whatsapp/services/whatsapp.service.ts index da46b240..b71463b3 100644 --- a/src/whatsapp/services/whatsapp.service.ts +++ b/src/whatsapp/services/whatsapp.service.ts @@ -183,12 +183,12 @@ export class WAStartupService { maxSockets: 100, maxFreeSockets: 10, timeout: 60000 - }) + }); this.axiosInstance = axios.create({ httpAgent, - timeout: 10000 - }) + timeout: 60000 + }); } private readonly logger = new Logger(this.configService, WAStartupService.name); From 31d3afb5ff3714274861d75d37e7a362df7596e2 Mon Sep 17 00:00:00 2001 From: Danilo de Souza Nunes Date: Thu, 25 Dec 2025 21:10:54 -0300 Subject: [PATCH 11/12] fix: undo formating --- src/whatsapp/services/whatsapp.service.ts | 123 ++++++++++++---------- 1 file changed, 66 insertions(+), 57 deletions(-) diff --git a/src/whatsapp/services/whatsapp.service.ts b/src/whatsapp/services/whatsapp.service.ts index 4640592b..e5651d3e 100644 --- a/src/whatsapp/services/whatsapp.service.ts +++ b/src/whatsapp/services/whatsapp.service.ts @@ -37,8 +37,6 @@ * └──────────────────────────────────────────────────────────────────────────────┘ */ -import { Boom } from '@hapi/boom'; -import PrismType, { Instance, Webhook } from '@prisma/client'; import makeWASocket, { AnyMessageContent, BaileysEventMap, @@ -73,54 +71,43 @@ import makeWASocket, { WAMessageUpdate, WASocket, } from '@whiskeysockets/baileys'; -import axios, { AxiosError, AxiosInstance } from 'axios'; -import { isArray, isBase64, isInt, isNotEmpty, isURL } from 'class-validator'; -import EventEmitter2 from 'eventemitter2'; -import ffmpeg from 'fluent-ffmpeg'; -import { - accessSync, - constants, - existsSync, - readFileSync, - rmSync, - unlinkSync, - writeFileSync, -} from 'fs'; -import http from 'http'; -import mime from 'mime-types'; -import NodeCache from 'node-cache'; -import { release } from 'os'; -import { join, normalize } from 'path'; -import P from 'pino'; -import qrcode, { QRCodeToDataURLOptions } from 'qrcode'; -import qrcodeTerminal from 'qrcode-terminal'; -import sharp from 'sharp'; -import { PassThrough } from 'stream'; -import { ulid } from 'ulid'; import { ConfigService, ConfigSessionPhone, Database, - EnvProxy, GlobalWebhook, - ProviderSession, QrCode, + ProviderSession, + EnvProxy, } from '../../config/env.config'; import { Logger } from '../../config/logger.config'; import { INSTANCE_DIR, ROOT_DIR } from '../../config/path.config'; -import { BadRequestException, InternalServerErrorException } from '../../exceptions'; -import * as s3Service from '../../integrations/minio/minio.utils'; -import { ProviderFiles } from '../../provider/sessions'; -import { Query, Repository } from '../../repository/repository.service'; -import { getJidUser, getUserGroup } from '../../utils/extract-id'; -import { createProxyAgents } from '../../utils/proxy'; +import { join, normalize } from 'path'; +import axios, { AxiosError, AxiosInstance } from 'axios'; +import qrcode, { QRCodeToDataURLOptions } from 'qrcode'; +import qrcodeTerminal from 'qrcode-terminal'; +import { Boom } from '@hapi/boom'; +import EventEmitter2 from 'eventemitter2'; +import { release } from 'os'; +import P from 'pino'; import { - AuthState, - AuthStateProvider, -} from '../../utils/use-multi-file-auth-state-provider-files'; -import { fetchLatestBaileysVersionV2 } from '../../utils/wa-version'; -import { isValidUlid } from '../../validate/ulid'; -import { Websocket } from '../../websocket/server'; + AudioMessageFileDto, + ContactMessage, + MediaFileDto, + MediaMessage, + Options, + SendAudioDto, + SendButtonsDto, + SendContactDto, + SendLinkDto, + SendListDto, + SendListLegacyDto, + SendLocationDto, + SendMediaDto, + SendReactionDto, + SendTextDto, +} from '../dto/sendMessage.dto'; +import { isArray, isBase64, isInt, isNotEmpty, isURL } from 'class-validator'; import { ArchiveChatDto, DeleteMessage, @@ -132,27 +119,44 @@ import { UpdatePresenceDto, WhatsAppNumberDto, } from '../dto/chat.dto'; +import { BadRequestException, InternalServerErrorException } from '../../exceptions'; import { CreateGroupDto, GroupJid, GroupPictureDto, GroupUpdateParticipantDto, } from '../dto/group.dto'; +import NodeCache from 'node-cache'; import { - AudioMessageFileDto, - ContactMessage, - MediaFileDto, - MediaMessage, - Options, - SendAudioDto, - SendContactDto, - SendLinkDto, - SendLocationDto, - SendMediaDto, - SendReactionDto, - SendTextDto, -} from '../dto/sendMessage.dto'; + AuthState, + AuthStateProvider, +} from '../../utils/use-multi-file-auth-state-provider-files'; +import mime from 'mime-types'; +import { Instance, Webhook } from '@prisma/client'; import { WebhookEvents, WebhookEventsEnum, WebhookEventsType } from '../dto/webhook.dto'; +import { Query, Repository } from '../../repository/repository.service'; +import PrismType from '@prisma/client'; +import * as s3Service from '../../integrations/minio/minio.utils'; +import { ProviderFiles } from '../../provider/sessions'; +import { Websocket } from '../../websocket/server'; +import { ulid } from 'ulid'; +import { isValidUlid } from '../../validate/ulid'; +import sharp from 'sharp'; +import ffmpeg from 'fluent-ffmpeg'; +import { PassThrough } from 'stream'; +import { + accessSync, + constants, + existsSync, + readFileSync, + rmSync, + unlinkSync, + writeFileSync, +} from 'fs'; +import { createProxyAgents } from '../../utils/proxy'; +import { fetchLatestBaileysVersionV2 } from '../../utils/wa-version'; +import { getJidUser, getUserGroup } from '../../utils/extract-id'; +import http from 'http'; type InstanceQrCode = { count: number; @@ -1937,9 +1941,12 @@ export class WAStartupService { jpegThumbnail: await (async () => { if (data.linkMessage?.thumbnailUrl) { try { - const response = await this.axiosInstance.get(data.linkMessage.thumbnailUrl, { - responseType: 'arraybuffer', - }); + const response = await this.axiosInstance.get( + data.linkMessage.thumbnailUrl, + { + responseType: 'arraybuffer', + }, + ); return new Uint8Array(response.data); } catch (error) { // @@ -2427,7 +2434,9 @@ export class WAStartupService { try { let pic: WAMediaUpload; if (isURL(picture.image)) { - pic = (await this.axiosInstance.get(picture.image, { responseType: 'arraybuffer' })).data; + pic = ( + await this.axiosInstance.get(picture.image, { responseType: 'arraybuffer' }) + ).data; } else if (isBase64(picture.image)) { pic = Buffer.from(picture.image, 'base64'); } else { From 842d0c8ab9f52b08a32931c39ef0ed1ba6779af9 Mon Sep 17 00:00:00 2001 From: Danilo de Souza Nunes Date: Thu, 25 Dec 2025 21:12:49 -0300 Subject: [PATCH 12/12] fix: undo formating --- src/whatsapp/services/whatsapp.service.ts | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/whatsapp/services/whatsapp.service.ts b/src/whatsapp/services/whatsapp.service.ts index e5651d3e..3c5e2ba3 100644 --- a/src/whatsapp/services/whatsapp.service.ts +++ b/src/whatsapp/services/whatsapp.service.ts @@ -1941,12 +1941,9 @@ export class WAStartupService { jpegThumbnail: await (async () => { if (data.linkMessage?.thumbnailUrl) { try { - const response = await this.axiosInstance.get( - data.linkMessage.thumbnailUrl, - { - responseType: 'arraybuffer', - }, - ); + const response = await this.axiosInstance.get(data.linkMessage.thumbnailUrl, { + responseType: 'arraybuffer', + }); return new Uint8Array(response.data); } catch (error) { // @@ -2434,9 +2431,7 @@ export class WAStartupService { try { let pic: WAMediaUpload; if (isURL(picture.image)) { - pic = ( - await this.axiosInstance.get(picture.image, { responseType: 'arraybuffer' }) - ).data; + pic = (await this.axiosInstance.get(picture.image, { responseType: 'arraybuffer' })).data; } else if (isBase64(picture.image)) { pic = Buffer.from(picture.image, 'base64'); } else {