Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hotfix: bug on chatwoot sdk #392

Merged
merged 1 commit into from
Feb 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions src/whatsapp/services/chatwoot.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,19 +382,27 @@ export class ChatwootService {
this.logger.verbose('find contact in chatwoot');
let contact: any;

if(isGroup) {
if (isGroup) {
contact = await client.contacts.search({
accountId: this.provider.account_id,
q: query,
});
} else {
contact = await client.contacts.filter({
accountId: this.provider.account_id,
payload: this.getFilterPayload(query),
// contact = await client.contacts.filter({
// accountId: this.provider.account_id,
// payload: this.getFilterPayload(query),
// });
// hotfix for: https://github.com/EvolutionAPI/evolution-api/pull/382. waiting fix: https://github.com/figurolatam/chatwoot-sdk/pull/7
contact = await chatwootRequest(this.getClientCwConfig(), {
method: 'POST',
url: `/api/v1/accounts/${this.provider.account_id}/contacts/filter`,
body: {
payload: this.getFilterPayload(query),
},
});
}

if(!contact) {
if (!contact) {
this.logger.warn('contact not found');
return null;
}
Expand Down Expand Up @@ -444,16 +452,16 @@ export class ChatwootService {

private getFilterPayload(query: string) {
const payload = [];
const values = this.getNumbers(query)
const values = this.getNumbers(query);

const fields = this.getSearchableFields();
fields.forEach((key, index) => {
const queryOperator = fields.length - 1 === index ? null : 'OR';
payload.push({
"attribute_key": key,
"filter_operator": "contains",
"values": values,
"query_operator": queryOperator
attribute_key: key,
filter_operator: 'contains',
values: values,
query_operator: queryOperator,
});
});

Expand Down