diff --git a/docker-compose.yaml b/docker-compose.yaml index e0edee6569..f5c6b448e6 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -9,12 +9,11 @@ services: - redis - evolution-postgres ports: - - "127.0.0.1:8080:8080" + - "127.0.0.1:8081:8080" volumes: - evolution_instances:/evolution/instances networks: - evolution-net - - dokploy-network env_file: - .env expose: @@ -41,9 +40,6 @@ services: evolution-net: aliases: - evolution-redis - dokploy-network: - aliases: - - evolution-redis expose: - "6379" @@ -67,7 +63,6 @@ services: - postgres_data:/var/lib/postgresql/data networks: - evolution-net - - dokploy-network expose: - "5432" @@ -79,6 +74,4 @@ volumes: networks: evolution-net: name: evolution-net - driver: bridge - dokploy-network: - external: true \ No newline at end of file + driver: bridge \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index c45e8fef38..4f8d2d5202 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15080,7 +15080,6 @@ "cpu": [ "ppc64" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -15097,7 +15096,6 @@ "cpu": [ "arm" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -15114,7 +15112,6 @@ "cpu": [ "arm64" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -15131,7 +15128,6 @@ "cpu": [ "x64" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -15148,7 +15144,6 @@ "cpu": [ "arm64" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -15165,7 +15160,6 @@ "cpu": [ "x64" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -15182,7 +15176,6 @@ "cpu": [ "arm64" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -15199,7 +15192,6 @@ "cpu": [ "x64" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -15216,7 +15208,6 @@ "cpu": [ "arm" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -15233,7 +15224,6 @@ "cpu": [ "arm64" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -15250,7 +15240,6 @@ "cpu": [ "ia32" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -15267,7 +15256,6 @@ "cpu": [ "loong64" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -15284,7 +15272,6 @@ "cpu": [ "mips64el" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -15301,7 +15288,6 @@ "cpu": [ "ppc64" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -15318,7 +15304,6 @@ "cpu": [ "riscv64" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -15335,7 +15320,6 @@ "cpu": [ "s390x" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -15352,7 +15336,6 @@ "cpu": [ "x64" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -15369,7 +15352,6 @@ "cpu": [ "arm64" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -15386,7 +15368,6 @@ "cpu": [ "x64" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -15403,7 +15384,6 @@ "cpu": [ "arm64" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -15420,7 +15400,6 @@ "cpu": [ "x64" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -15437,7 +15416,6 @@ "cpu": [ "arm64" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -15454,7 +15432,6 @@ "cpu": [ "x64" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -15471,7 +15448,6 @@ "cpu": [ "arm64" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -15488,7 +15464,6 @@ "cpu": [ "ia32" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -15505,7 +15480,6 @@ "cpu": [ "x64" ], - "dev": true, "license": "MIT", "optional": true, "os": [ diff --git a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts index 60e857fcc1..dc9dfcb2c0 100644 --- a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts +++ b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts @@ -1201,6 +1201,20 @@ export class BaileysStartupService extends ChannelStartupService { } } + // FIX: Fallback pushName if not present in received payload + if (!received.pushName && !received.key.fromMe) { + const participantJid = received.participant || received.key.participant || received.key.remoteJid; + if (participantJid) { + const contact = await this.prismaRepository.contact.findFirst({ + where: { instanceId: this.instanceId, remoteJid: participantJid }, + select: { pushName: true } + }); + if (contact && contact.pushName) { + received.pushName = contact.pushName; + } + } + } + const messageRaw = this.prepareMessage(received); if (messageRaw.messageType === 'pollUpdateMessage') { @@ -1355,7 +1369,20 @@ export class BaileysStartupService extends ChannelStartupService { if (this.configService.get('DATABASE').SAVE_DATA.NEW_MESSAGE) { // eslint-disable-next-line @typescript-eslint/no-unused-vars const { pollUpdates, ...messageData } = messageRaw; - const msg = await this.prismaRepository.message.create({ data: messageData }); + + const existingMessage = await this.prismaRepository.$queryRaw` + SELECT id, status, "messageTimestamp" FROM "Message" + WHERE "instanceId" = ${this.instanceId} + AND "key"->>'id' = ${received.key.id} + ` as any[]; + + let msg; + if (existingMessage && existingMessage.length > 0) { + msg = existingMessage[0]; + this.logger.info(`Message already exists, ignoring create: ${received.key.id}`); + } else { + msg = await this.prismaRepository.message.create({ data: messageData }); + } const { remoteJid } = received.key; const timestamp = msg.messageTimestamp; @@ -1495,16 +1522,19 @@ export class BaileysStartupService extends ChannelStartupService { const contactRaw: { remoteJid: string; - pushName: string; + pushName?: string; profilePicUrl?: string; instanceId: string; } = { remoteJid: received.key.remoteJid, - pushName: received.key.fromMe ? '' : received.key.fromMe == null ? '' : received.pushName, profilePicUrl: (await this.profilePicture(received.key.remoteJid)).profilePictureUrl, instanceId: this.instanceId, }; + if (!received.key.fromMe && received.pushName) { + contactRaw.pushName = received.pushName; + } + if (contactRaw.remoteJid === 'status@broadcast') { continue; } diff --git a/src/api/services/monitor.service.ts b/src/api/services/monitor.service.ts index 438530b57e..be215a3c9a 100644 --- a/src/api/services/monitor.service.ts +++ b/src/api/services/monitor.service.ts @@ -271,6 +271,22 @@ export class WAMonitoringService { } private async setInstance(instanceData: InstanceDto) { + if (this.waInstances[instanceData.instanceName]) { + this.logger.warn(`Forcefully closing existing instance ${instanceData.instanceName} to prevent zombies`); + try { + const existing = this.waInstances[instanceData.instanceName]; + if (existing?.client?.ws) { + existing.client.ws.close(); + } + if (existing?.client?.end) { + existing.client.end(undefined); + } + } catch (err) { + this.logger.error(`Error closing zombie instance ${instanceData.instanceName}: ${err}`); + } + delete this.waInstances[instanceData.instanceName]; + } + const instance = channelController.init(instanceData, { configService: this.configService, eventEmitter: this.eventEmitter,