fix: Adjusts in restart instance

This commit is contained in:
Davidson Gomes 2024-08-03 12:54:23 -03:00
parent 7ed1965f57
commit c6db03ffa2
2 changed files with 18 additions and 9 deletions

View File

@ -3,6 +3,7 @@
### Fixed
* BusinessId added on create instances in manager
* Adjusts in restart instance
# 2.0.6-rc (2024-08-02 19:23)

View File

@ -583,6 +583,7 @@ export class InstanceController {
};
} catch (error) {
this.logger.error(error);
return { error: true, message: error.toString() };
}
}
@ -591,19 +592,26 @@ export class InstanceController {
const instance = this.waMonitor.waInstances[instanceName];
const state = instance?.connectionStatus?.state;
switch (state) {
case 'open':
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED) instance.clearCacheChatwoot();
if (!state) {
throw new BadRequestException('The "' + instanceName + '" instance does not exist');
}
this.logger.info('Connection closed, restarting instance' + instanceName);
instance.client?.ws?.close();
instance.client?.end(new Error('restart'));
return await this.connectToWhatsapp({ instanceName });
default:
return await this.connectionState({ instanceName });
if (state == 'close') {
throw new BadRequestException('The "' + instanceName + '" instance is not connected');
} else if (state == 'open') {
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED) instance.clearCacheChatwoot();
this.logger.info('restarting instance' + instanceName);
instance.client?.ws?.close();
instance.client?.end(new Error('restart'));
return await this.connectToWhatsapp({ instanceName });
} else if (state == 'connecting') {
instance.client?.end(new Error('restart'));
return await this.connectToWhatsapp({ instanceName });
}
} catch (error) {
this.logger.error(error);
return { error: true, message: error.toString() };
}
}