Skip to content

Commit 64c1440

Browse files
committed
fix: correction of chatwoot functioning with admin flows
1 parent f069a41 commit 64c1440

File tree

4 files changed

+31
-20
lines changed

4 files changed

+31
-20
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"cross-env": "^7.0.3",
5757
"dayjs": "^1.11.7",
5858
"eventemitter2": "^6.4.9",
59-
"evolution-manager": "latest",
59+
"evolution-manager": "^0.4.4",
6060
"exiftool-vendored": "^22.0.0",
6161
"express": "^4.18.2",
6262
"express-async-errors": "^3.1.1",

src/whatsapp/controllers/chatwoot.controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export class ChatwootController {
4747

4848
data.name_inbox = instance.instanceName;
4949

50-
const result = this.chatwootService.create(instance, data);
50+
const result = await this.chatwootService.create(instance, data);
5151

5252
const urlServer = this.configService.get<HttpServer>('SERVER').URL;
5353

src/whatsapp/services/chatwoot.service.ts

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -52,25 +52,26 @@ export class ChatwootService {
5252

5353
private async getProvider(instance: InstanceDto) {
5454
this.logger.verbose('get provider to instance: ' + instance.instanceName);
55-
try {
56-
const provider = await this.waMonitor.waInstances[instance.instanceName].findChatwoot();
57-
58-
if (!provider) {
59-
this.logger.warn('provider not found');
60-
return null;
61-
}
62-
63-
this.logger.verbose('provider found');
55+
const provider = await this.waMonitor.waInstances[instance.instanceName]?.findChatwoot();
6456

65-
return provider;
66-
} catch (error) {
67-
this.logger.error('provider not found');
57+
if (!provider) {
58+
this.logger.warn('provider not found');
6859
return null;
6960
}
61+
62+
this.logger.verbose('provider found');
63+
64+
return provider;
65+
// try {
66+
// } catch (error) {
67+
// this.logger.error('provider not found');
68+
// return null;
69+
// }
7070
}
7171

7272
private async clientCw(instance: InstanceDto) {
7373
this.logger.verbose('get client to instance: ' + instance.instanceName);
74+
7475
const provider = await this.getProvider(instance);
7576

7677
if (!provider) {
@@ -97,17 +98,17 @@ export class ChatwootService {
9798
return client;
9899
}
99100

100-
public create(instance: InstanceDto, data: ChatwootDto) {
101+
public async create(instance: InstanceDto, data: ChatwootDto) {
101102
this.logger.verbose('create chatwoot: ' + instance.instanceName);
102103

103-
this.waMonitor.waInstances[instance.instanceName].setChatwoot(data);
104+
await this.waMonitor.waInstances[instance.instanceName].setChatwoot(data);
104105

105106
this.logger.verbose('chatwoot created');
106107

107108
if (data.auto_create) {
108109
const urlServer = this.configService.get<HttpServer>('SERVER').URL;
109110

110-
this.initInstanceChatwoot(
111+
await this.initInstanceChatwoot(
111112
instance,
112113
instance.instanceName.split('-cwId-')[0],
113114
`${urlServer}/chatwoot/webhook/${encodeURIComponent(instance.instanceName)}`,
@@ -1002,7 +1003,7 @@ export class ChatwootService {
10021003
if (state !== 'open') {
10031004
if (state === 'close') {
10041005
this.logger.verbose('request cleaning up instance: ' + instance.instanceName);
1005-
await this.waMonitor.cleaningUp(instance.instanceName);
1006+
// await this.waMonitor.cleaningUp(instance.instanceName);
10061007
}
10071008
this.logger.verbose('connect to whatsapp');
10081009
const number = command.split(':')[1];

src/whatsapp/services/whatsapp.service.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ export class WAStartupService {
211211

212212
public async getProfileName() {
213213
this.logger.verbose('Getting profile name');
214+
214215
let profileName = this.client.user?.name ?? this.client.user?.verifiedName;
215216
if (!profileName) {
216217
this.logger.verbose('Profile name not found, trying to get from database');
@@ -3311,7 +3312,16 @@ export class WAStartupService {
33113312

33123313
public async fetchPrivacySettings() {
33133314
this.logger.verbose('Fetching privacy settings');
3314-
return await this.client.fetchPrivacySettings();
3315+
const privacy = await this.client.fetchPrivacySettings();
3316+
3317+
return {
3318+
readreceipts: privacy.readreceipts,
3319+
profile: privacy.profile,
3320+
status: privacy.status,
3321+
online: privacy.online,
3322+
last: privacy.last,
3323+
groupadd: privacy.groupadd,
3324+
};
33153325
}
33163326

33173327
public async updatePrivacySettings(settings: PrivacySettingDto) {
@@ -3427,7 +3437,7 @@ export class WAStartupService {
34273437
await this.client.updateProfilePicture(this.instance.wuid, pic);
34283438
this.logger.verbose('Profile picture updated');
34293439

3430-
await this.reloadConnection();
3440+
this.reloadConnection();
34313441

34323442
return { update: 'success' };
34333443
} catch (error) {

0 commit comments

Comments
 (0)