fix: correction of chatwoot functioning with admin flows

This commit is contained in:
Davidson Gomes 2023-12-12 13:56:41 -03:00
parent f069a41390
commit 64c1440c46
4 changed files with 31 additions and 20 deletions

View File

@ -56,7 +56,7 @@
"cross-env": "^7.0.3", "cross-env": "^7.0.3",
"dayjs": "^1.11.7", "dayjs": "^1.11.7",
"eventemitter2": "^6.4.9", "eventemitter2": "^6.4.9",
"evolution-manager": "latest", "evolution-manager": "^0.4.4",
"exiftool-vendored": "^22.0.0", "exiftool-vendored": "^22.0.0",
"express": "^4.18.2", "express": "^4.18.2",
"express-async-errors": "^3.1.1", "express-async-errors": "^3.1.1",

View File

@ -47,7 +47,7 @@ export class ChatwootController {
data.name_inbox = instance.instanceName; data.name_inbox = instance.instanceName;
const result = this.chatwootService.create(instance, data); const result = await this.chatwootService.create(instance, data);
const urlServer = this.configService.get<HttpServer>('SERVER').URL; const urlServer = this.configService.get<HttpServer>('SERVER').URL;

View File

@ -52,8 +52,7 @@ export class ChatwootService {
private async getProvider(instance: InstanceDto) { private async getProvider(instance: InstanceDto) {
this.logger.verbose('get provider to instance: ' + instance.instanceName); this.logger.verbose('get provider to instance: ' + instance.instanceName);
try { const provider = await this.waMonitor.waInstances[instance.instanceName]?.findChatwoot();
const provider = await this.waMonitor.waInstances[instance.instanceName].findChatwoot();
if (!provider) { if (!provider) {
this.logger.warn('provider not found'); this.logger.warn('provider not found');
@ -63,14 +62,16 @@ export class ChatwootService {
this.logger.verbose('provider found'); this.logger.verbose('provider found');
return provider; return provider;
} catch (error) { // try {
this.logger.error('provider not found'); // } catch (error) {
return null; // this.logger.error('provider not found');
} // return null;
// }
} }
private async clientCw(instance: InstanceDto) { private async clientCw(instance: InstanceDto) {
this.logger.verbose('get client to instance: ' + instance.instanceName); this.logger.verbose('get client to instance: ' + instance.instanceName);
const provider = await this.getProvider(instance); const provider = await this.getProvider(instance);
if (!provider) { if (!provider) {
@ -97,17 +98,17 @@ export class ChatwootService {
return client; return client;
} }
public create(instance: InstanceDto, data: ChatwootDto) { public async create(instance: InstanceDto, data: ChatwootDto) {
this.logger.verbose('create chatwoot: ' + instance.instanceName); this.logger.verbose('create chatwoot: ' + instance.instanceName);
this.waMonitor.waInstances[instance.instanceName].setChatwoot(data); await this.waMonitor.waInstances[instance.instanceName].setChatwoot(data);
this.logger.verbose('chatwoot created'); this.logger.verbose('chatwoot created');
if (data.auto_create) { if (data.auto_create) {
const urlServer = this.configService.get<HttpServer>('SERVER').URL; const urlServer = this.configService.get<HttpServer>('SERVER').URL;
this.initInstanceChatwoot( await this.initInstanceChatwoot(
instance, instance,
instance.instanceName.split('-cwId-')[0], instance.instanceName.split('-cwId-')[0],
`${urlServer}/chatwoot/webhook/${encodeURIComponent(instance.instanceName)}`, `${urlServer}/chatwoot/webhook/${encodeURIComponent(instance.instanceName)}`,
@ -1002,7 +1003,7 @@ export class ChatwootService {
if (state !== 'open') { if (state !== 'open') {
if (state === 'close') { if (state === 'close') {
this.logger.verbose('request cleaning up instance: ' + instance.instanceName); this.logger.verbose('request cleaning up instance: ' + instance.instanceName);
await this.waMonitor.cleaningUp(instance.instanceName); // await this.waMonitor.cleaningUp(instance.instanceName);
} }
this.logger.verbose('connect to whatsapp'); this.logger.verbose('connect to whatsapp');
const number = command.split(':')[1]; const number = command.split(':')[1];

View File

@ -211,6 +211,7 @@ export class WAStartupService {
public async getProfileName() { public async getProfileName() {
this.logger.verbose('Getting profile name'); this.logger.verbose('Getting profile name');
let profileName = this.client.user?.name ?? this.client.user?.verifiedName; let profileName = this.client.user?.name ?? this.client.user?.verifiedName;
if (!profileName) { if (!profileName) {
this.logger.verbose('Profile name not found, trying to get from database'); this.logger.verbose('Profile name not found, trying to get from database');
@ -3311,7 +3312,16 @@ export class WAStartupService {
public async fetchPrivacySettings() { public async fetchPrivacySettings() {
this.logger.verbose('Fetching privacy settings'); this.logger.verbose('Fetching privacy settings');
return await this.client.fetchPrivacySettings(); const privacy = await this.client.fetchPrivacySettings();
return {
readreceipts: privacy.readreceipts,
profile: privacy.profile,
status: privacy.status,
online: privacy.online,
last: privacy.last,
groupadd: privacy.groupadd,
};
} }
public async updatePrivacySettings(settings: PrivacySettingDto) { public async updatePrivacySettings(settings: PrivacySettingDto) {
@ -3427,7 +3437,7 @@ export class WAStartupService {
await this.client.updateProfilePicture(this.instance.wuid, pic); await this.client.updateProfilePicture(this.instance.wuid, pic);
this.logger.verbose('Profile picture updated'); this.logger.verbose('Profile picture updated');
await this.reloadConnection(); this.reloadConnection();
return { update: 'success' }; return { update: 'success' };
} catch (error) { } catch (error) {