From 3e85af958962ac26e9f6fe6b1baace71f15d00a8 Mon Sep 17 00:00:00 2001 From: jaison-x Date: Tue, 26 Mar 2024 15:42:32 -0300 Subject: [PATCH 1/2] fix(chatwoot): fix when receiving/sending messages from whatsapp desktop with ephemeral messages enabled --- src/whatsapp/services/chatwoot.service.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/whatsapp/services/chatwoot.service.ts b/src/whatsapp/services/chatwoot.service.ts index 43d8f5be..0fb6272e 100644 --- a/src/whatsapp/services/chatwoot.service.ts +++ b/src/whatsapp/services/chatwoot.service.ts @@ -1774,6 +1774,13 @@ export class ChatwootService { return; } + // fix when receiving/sending messages from whatsapp desktop with ephemeral messages enabled + if (body.message?.ephemeralMessage?.message) { + body.message = { + ...body.message?.ephemeralMessage?.message, + }; + } + this.logger.verbose('get conversation message'); // Whatsapp to Chatwoot From 28581f88b2083ae09ee37cbaacaef6c64a82449c Mon Sep 17 00:00:00 2001 From: jaison-x Date: Fri, 12 Apr 2024 10:51:36 -0300 Subject: [PATCH 2/2] fix(chatwoot): fix conversation read on chatwoot version 3.7 if contact has more than one conversation, we could get the wrong conversation. --- src/whatsapp/services/chatwoot.service.ts | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/whatsapp/services/chatwoot.service.ts b/src/whatsapp/services/chatwoot.service.ts index 0fb6272e..d2c1f139 100644 --- a/src/whatsapp/services/chatwoot.service.ts +++ b/src/whatsapp/services/chatwoot.service.ts @@ -1,4 +1,12 @@ -import ChatwootClient, { ChatwootAPIConfig, contact, conversation, generic_id, inbox } from '@figuro/chatwoot-sdk'; +import ChatwootClient, { + ChatwootAPIConfig, + contact, + contact_inboxes, + conversation, + conversation_show, + generic_id, + inbox, +} from '@figuro/chatwoot-sdk'; import { request as chatwootRequest } from '@figuro/chatwoot-sdk/dist/core/request'; import axios from 'axios'; import FormData from 'form-data'; @@ -2130,12 +2138,13 @@ export class ChatwootService { }; if (!sourceId && inbox) { - const contact = (await this.findContact( - instance, - this.getNumberFromRemoteJid(body.key.remoteJid), - )) as contact; - const contactInbox = contact?.contact_inboxes?.find((contactInbox) => contactInbox?.inbox?.id === inbox.id); - sourceId = contactInbox?.source_id; + const conversation = (await client.conversations.get({ + accountId: this.provider.account_id, + conversationId: conversationId, + })) as conversation_show & { + last_non_activity_message: { conversation: { contact_inbox: contact_inboxes } }; + }; + sourceId = conversation.last_non_activity_message?.conversation?.contact_inbox?.source_id; } if (sourceId && inbox?.inbox_identifier) {