From f8f2153cb4ae80bff1b805281e3ccfcdbd22bb80 Mon Sep 17 00:00:00 2001 From: Rafael Souza Date: Thu, 17 Jul 2025 15:29:04 -0300 Subject: [PATCH] Fix erro key --- .../chatwoot/services/chatwoot.service.ts | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts b/src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts index ba31ab33..cdac0fcc 100644 --- a/src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts +++ b/src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts @@ -567,6 +567,12 @@ export class ChatwootService { } public async createConversation(instance: InstanceDto, body: any) { + if (!body?.key) { + this.logger.warn('body.key is null or undefined in createConversation'); + this.logger.warn('Full body object:', JSON.stringify(body, null, 2)); + return null; + } + const isLid = body.key.previousRemoteJid?.includes('@lid') && body.key.senderPn; const remoteJid = body.key.remoteJid; const cacheKey = `${instance.instanceName}:createConversation-${remoteJid}`; @@ -1938,6 +1944,12 @@ export class ChatwootService { } if (event === 'messages.upsert' || event === 'send.message') { + if (!body?.key) { + this.logger.warn('body.key is null or undefined'); + this.logger.warn('Full body object:', JSON.stringify(body, null, 2)); + return; + } + if (body.key.remoteJid === 'status@broadcast') { return; } @@ -2260,10 +2272,16 @@ export class ChatwootService { } if (event === 'messages.edit' || event === 'send.message.update') { + if (!body?.key?.id) { + this.logger.warn('body.key.id is null or undefined in messages.edit'); + this.logger.warn('Full body object:', JSON.stringify(body, null, 2)); + return; + } + const editedText = `${ body?.editedMessage?.conversation || body?.editedMessage?.extendedTextMessage?.text }\n\n_\`${i18next.t('cw.message.edited')}.\`_`; - const message = await this.getMessageByKeyId(instance, body?.key?.id); + const message = await this.getMessageByKeyId(instance, body.key.id); const key = message.key as { id: string; fromMe: boolean;