Skip to content

Commit

Permalink
Merge pull request EvolutionAPI#528 from jaison-x/pr
Browse files Browse the repository at this point in the history
fix(chatwoot): fix conversation read on chatwoot version 3.7
  • Loading branch information
DavidsonGomes authored Apr 12, 2024
2 parents 833c625 + 28581f8 commit c2839dd
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/whatsapp/services/chatwoot.service.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit c2839dd

Please sign in to comment.