diff --git a/Dockerfile b/Dockerfile index d30ccf0d..c6abb936 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,7 @@ FROM node:20-alpine AS builder RUN apk update && \ apk add git ffmpeg wget curl bash openssl -LABEL version="2.2.3.22" description="Api to control whatsapp features through http requests." +LABEL version="2.2.3.24" description="Api to control whatsapp features through http requests." LABEL maintainer="Davidson Gomes" git="https://github.com/DavidsonGomes" LABEL contact="contato@atendai.com" diff --git a/package-lock.json b/package-lock.json index 5e4a4ab4..5219a85a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "evolution-api", - "version": "2.2.3.22", + "version": "2.2.3.24", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "evolution-api", - "version": "2.2.3.22", + "version": "2.2.3.24", "license": "Apache-2.0", "dependencies": { "@adiwajshing/keyed-db": "^0.2.4", diff --git a/package.json b/package.json index c81d00ce..8a654f95 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "evolution-api", - "version": "2.2.3.22", + "version": "2.2.3.24", "description": "Rest api for communication with WhatsApp", "main": "./dist/main.js", "type": "commonjs", diff --git a/src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts b/src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts index c2fe0fd8..834d97b8 100644 --- a/src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts +++ b/src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts @@ -646,6 +646,9 @@ export class ChatwootService { this.logger.verbose("[createConversation] Removido pendingCreateConv para " + remoteJid); } } + + + private async _createConversation(instance: InstanceDto, body: any): Promise { const remoteJid = body.key.remoteJid as string; @@ -687,9 +690,18 @@ export class ChatwootService { this.logger.verbose("[_createConversation] Contato encontrado: id=" + contact.id); } else { this.logger.verbose("[_createConversation] Contato nao existe, criando..."); + + + const isOutgoing = body.key.fromMe; + const senderName = !isOutgoing && body.pushName ? body.pushName : chatId; + const name = isGroup - ? (await this.waMonitor.waInstances[instance.instanceName].client.groupMetadata(chatId)).subject + " (GROUP)" - : body.pushName || chatId; + ? (await this.waMonitor.waInstances[instance.instanceName] + .client.groupMetadata(chatId)).subject + " (GROUP)" + : senderName; + + + const pictureUrl = (await this.waMonitor.waInstances[instance.instanceName].profilePicture(chatId)).profilePictureUrl; contact = await this.createContact( instance, @@ -760,13 +772,16 @@ export class ChatwootService { accountId: this.provider.accountId, data: payload, }); - if (!newConv?.id) { - this.logger.error("[_createConversation] create retornou sem ID"); - throw new Error("Falha ao criar nova conversa: resposta sem ID"); + + const displayId = (newConv as any).display_id ?? newConv.id; + + if (!displayId) { + this.logger.error("[_createConversation] create retornou sem DisplayID"); + throw new Error("Falha ao criar nova conversa: resposta sem DisplayID"); } - this.logger.verbose("[_createConversation] Nova conversa criada id=" + newConv.id); - this.cache.set(cacheKey, newConv.id, 5 * 60); - return newConv.id; + this.logger.verbose("[_createConversation] Nova conversa criada DisplayId=" + displayId); + this.cache.set(cacheKey, displayId, 5 * 60); + return displayId; } catch (err: any) { this.logger.error("[_createConversation] Erro ao criar conversa: " + err);