mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-20 10:16:43 -06:00
fix(chatwoot): fix conversation read on chatwoot version 3.7
if contact has more than one conversation, we could get the wrong conversation.
This commit is contained in:
parent
3e85af9589
commit
28581f88b2
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user