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",
"dayjs": "^1.11.7",
"eventemitter2": "^6.4.9",
"evolution-manager": "latest",
"evolution-manager": "^0.4.4",
"exiftool-vendored": "^22.0.0",
"express": "^4.18.2",
"express-async-errors": "^3.1.1",

View File

@ -47,7 +47,7 @@ export class ChatwootController {
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;

View File

@ -52,25 +52,26 @@ export class ChatwootService {
private async getProvider(instance: InstanceDto) {
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) {
this.logger.warn('provider not found');
return null;
}
this.logger.verbose('provider found');
return provider;
} catch (error) {
this.logger.error('provider not found');
if (!provider) {
this.logger.warn('provider not found');
return null;
}
this.logger.verbose('provider found');
return provider;
// try {
// } catch (error) {
// this.logger.error('provider not found');
// return null;
// }
}
private async clientCw(instance: InstanceDto) {
this.logger.verbose('get client to instance: ' + instance.instanceName);
const provider = await this.getProvider(instance);
if (!provider) {
@ -97,17 +98,17 @@ export class ChatwootService {
return client;
}
public create(instance: InstanceDto, data: ChatwootDto) {
public async create(instance: InstanceDto, data: ChatwootDto) {
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');
if (data.auto_create) {
const urlServer = this.configService.get<HttpServer>('SERVER').URL;
this.initInstanceChatwoot(
await this.initInstanceChatwoot(
instance,
instance.instanceName.split('-cwId-')[0],
`${urlServer}/chatwoot/webhook/${encodeURIComponent(instance.instanceName)}`,
@ -1002,7 +1003,7 @@ export class ChatwootService {
if (state !== 'open') {
if (state === 'close') {
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');
const number = command.split(':')[1];

View File

@ -211,6 +211,7 @@ export class WAStartupService {
public async getProfileName() {
this.logger.verbose('Getting profile name');
let profileName = this.client.user?.name ?? this.client.user?.verifiedName;
if (!profileName) {
this.logger.verbose('Profile name not found, trying to get from database');
@ -3311,7 +3312,16 @@ export class WAStartupService {
public async fetchPrivacySettings() {
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) {
@ -3427,7 +3437,7 @@ export class WAStartupService {
await this.client.updateProfilePicture(this.instance.wuid, pic);
this.logger.verbose('Profile picture updated');
await this.reloadConnection();
this.reloadConnection();
return { update: 'success' };
} catch (error) {