Skip to content

Commit 60a20f6

Browse files
Merge pull request #582 from deivisonrpg/hotfix-getOpenConversationByContact
fix(chatwoot): getOpenConversationByContact and init queries error
2 parents e65c7b6 + ea3b0b3 commit 60a20f6

File tree

2 files changed

+8
-19
lines changed

2 files changed

+8
-19
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"amqplib": "^0.10.3",
5050
"aws-sdk": "^2.1499.0",
5151
"axios": "^1.6.5",
52-
"baileys": "^6.7.1",
52+
"baileys": "^6.7.2",
5353
"class-validator": "^0.14.1",
5454
"compression": "^1.7.4",
5555
"cors": "^2.8.5",

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

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -789,26 +789,15 @@ export class ChatwootService {
789789
return null;
790790
}
791791

792-
const payload = [
793-
['inbox_id', inbox.id.toString()],
794-
['contact_id', contact.id.toString()],
795-
['status', 'open'],
796-
];
792+
const conversations = (await client.contacts.listConversations({
793+
accountId: this.provider.account_id,
794+
id: contact.id,
795+
})) as any;
797796

798797
return (
799-
(
800-
(await client.conversations.filter({
801-
accountId: this.provider.account_id,
802-
payload: payload.map((item, i, payload) => {
803-
return {
804-
attribute_key: item[0],
805-
filter_operator: 'equal_to',
806-
values: [item[1]],
807-
query_operator: i < payload.length - 1 ? 'AND' : null,
808-
};
809-
}),
810-
})) as { payload: conversation[] }
811-
).payload[0] || undefined
798+
conversations.payload.find(
799+
(conversation) => conversation.inbox_id === inbox.id && conversation.status === 'open',
800+
) || undefined
812801
);
813802
}
814803

0 commit comments

Comments
 (0)