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
This commit is contained in:
Davidson Gomes 2025-05-10 10:31:06 -03:00 committed by GitHub
commit bff3bf564b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -698,34 +698,33 @@ export class ChatwootService {
return null; return null;
} }
if (contactConversations.payload.length) { let inboxConversation = contactConversations.payload.find(
let conversation: any; (conversation) => conversation.inbox_id == filterInbox.id,
);
if (inboxConversation) {
if (this.provider.reopenConversation) { if (this.provider.reopenConversation) {
conversation = contactConversations.payload.find((conversation) => conversation.inbox_id == filterInbox.id); this.logger.verbose(`Found conversation in reopenConversation mode: ${JSON.stringify(inboxConversation)}`);
this.logger.verbose(`Found conversation in reopenConversation mode: ${JSON.stringify(conversation)}`);
if (this.provider.conversationPending && conversation.status !== 'open') { if (this.provider.conversationPending && inboxConversation.status !== 'open') {
if (conversation) {
await client.conversations.toggleStatus({ await client.conversations.toggleStatus({
accountId: this.provider.accountId, accountId: this.provider.accountId,
conversationId: conversation.id, conversationId: inboxConversation.id,
data: { data: {
status: 'pending', status: 'pending',
}, },
}); });
} }
}
} else { } else {
conversation = contactConversations.payload.find( inboxConversation = contactConversations.payload.find(
(conversation) => conversation.status !== 'resolved' && conversation.inbox_id == filterInbox.id, (conversation) => conversation.status !== 'resolved' && conversation.inbox_id == filterInbox.id,
); );
this.logger.verbose(`Found conversation: ${JSON.stringify(conversation)}`); this.logger.verbose(`Found conversation: ${JSON.stringify(inboxConversation)}`);
} }
if (conversation) { if (inboxConversation) {
this.logger.verbose(`Returning existing conversation ID: ${conversation.id}`); this.logger.verbose(`Returning existing conversation ID: ${inboxConversation.id}`);
this.cache.set(cacheKey, conversation.id); this.cache.set(cacheKey, inboxConversation.id);
return conversation.id; return inboxConversation.id;
} }
} }