Merge pull request #582 from deivisonrpg/hotfix-getOpenConversationByContact

fix(chatwoot): getOpenConversationByContact and init queries error
This commit is contained in:
Davidson Gomes 2024-05-08 09:55:08 -03:00 committed by GitHub
commit 60a20f61af
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 19 deletions

View File

@ -49,7 +49,7 @@
"amqplib": "^0.10.3",
"aws-sdk": "^2.1499.0",
"axios": "^1.6.5",
"baileys": "^6.7.1",
"baileys": "^6.7.2",
"class-validator": "^0.14.1",
"compression": "^1.7.4",
"cors": "^2.8.5",

View File

@ -789,26 +789,15 @@ export class ChatwootService {
return null;
}
const payload = [
['inbox_id', inbox.id.toString()],
['contact_id', contact.id.toString()],
['status', 'open'],
];
const conversations = (await client.contacts.listConversations({
accountId: this.provider.account_id,
id: contact.id,
})) as any;
return (
(
(await client.conversations.filter({
accountId: this.provider.account_id,
payload: payload.map((item, i, payload) => {
return {
attribute_key: item[0],
filter_operator: 'equal_to',
values: [item[1]],
query_operator: i < payload.length - 1 ? 'AND' : null,
};
}),
})) as { payload: conversation[] }
).payload[0] || undefined
conversations.payload.find(
(conversation) => conversation.inbox_id === inbox.id && conversation.status === 'open',
) || undefined
);
}