Skip to content

Commit bff3bf5

Browse files
Merge pull request #1415 from victoreduardo/victoreduardos/fix-conversation-not-found
fix: Erro na criação de conversation quando já existe uma conversation de outro inbox para o mesmo usuário
2 parents c74eee8 + 8f0ede4 commit bff3bf5

File tree

1 file changed

+20
-21
lines changed

1 file changed

+20
-21
lines changed

src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -698,34 +698,33 @@ export class ChatwootService {
698698
return null;
699699
}
700700

701-
if (contactConversations.payload.length) {
702-
let conversation: any;
701+
let inboxConversation = contactConversations.payload.find(
702+
(conversation) => conversation.inbox_id == filterInbox.id,
703+
);
704+
if (inboxConversation) {
703705
if (this.provider.reopenConversation) {
704-
conversation = contactConversations.payload.find((conversation) => conversation.inbox_id == filterInbox.id);
705-
this.logger.verbose(`Found conversation in reopenConversation mode: ${JSON.stringify(conversation)}`);
706-
707-
if (this.provider.conversationPending && conversation.status !== 'open') {
708-
if (conversation) {
709-
await client.conversations.toggleStatus({
710-
accountId: this.provider.accountId,
711-
conversationId: conversation.id,
712-
data: {
713-
status: 'pending',
714-
},
715-
});
716-
}
706+
this.logger.verbose(`Found conversation in reopenConversation mode: ${JSON.stringify(inboxConversation)}`);
707+
708+
if (this.provider.conversationPending && inboxConversation.status !== 'open') {
709+
await client.conversations.toggleStatus({
710+
accountId: this.provider.accountId,
711+
conversationId: inboxConversation.id,
712+
data: {
713+
status: 'pending',
714+
},
715+
});
717716
}
718717
} else {
719-
conversation = contactConversations.payload.find(
718+
inboxConversation = contactConversations.payload.find(
720719
(conversation) => conversation.status !== 'resolved' && conversation.inbox_id == filterInbox.id,
721720
);
722-
this.logger.verbose(`Found conversation: ${JSON.stringify(conversation)}`);
721+
this.logger.verbose(`Found conversation: ${JSON.stringify(inboxConversation)}`);
723722
}
724723

725-
if (conversation) {
726-
this.logger.verbose(`Returning existing conversation ID: ${conversation.id}`);
727-
this.cache.set(cacheKey, conversation.id);
728-
return conversation.id;
724+
if (inboxConversation) {
725+
this.logger.verbose(`Returning existing conversation ID: ${inboxConversation.id}`);
726+
this.cache.set(cacheKey, inboxConversation.id);
727+
return inboxConversation.id;
729728
}
730729
}
731730

0 commit comments

Comments
 (0)