mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-26 18:38:39 -06:00
Update monitor.service.ts
This commit is contained in:
parent
8932fd0ada
commit
789aadef03
@ -7,9 +7,6 @@ import { join } from 'path';
|
|||||||
import { Auth, ConfigService, Database, DelInstance, HttpServer, Redis } from '../../config/env.config';
|
import { Auth, ConfigService, Database, DelInstance, HttpServer, Redis } from '../../config/env.config';
|
||||||
import { Logger } from '../../config/logger.config';
|
import { Logger } from '../../config/logger.config';
|
||||||
import { INSTANCE_DIR, STORE_DIR } from '../../config/path.config';
|
import { INSTANCE_DIR, STORE_DIR } from '../../config/path.config';
|
||||||
//inserido por Francis inicio
|
|
||||||
import { NotFoundException } from '../../exceptions';
|
|
||||||
//inserido por Francis final
|
|
||||||
import { dbserver } from '../../libs/db.connect';
|
import { dbserver } from '../../libs/db.connect';
|
||||||
import { RedisCache } from '../../libs/redis.client';
|
import { RedisCache } from '../../libs/redis.client';
|
||||||
import {
|
import {
|
||||||
@ -75,18 +72,10 @@ export class WAMonitoringService {
|
|||||||
}, 1000 * 60 * time);
|
}, 1000 * 60 * time);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/* ocultado por francis inicio
|
||||||
public async instanceInfo(instanceName?: string) {
|
public async instanceInfo(instanceName?: string) {
|
||||||
this.logger.verbose('get instance info');
|
this.logger.verbose('get instance info');
|
||||||
|
|
||||||
//inserido pot Francis - inicio
|
|
||||||
|
|
||||||
if (instanceName && !this.waInstances[instanceName]) {
|
|
||||||
throw new NotFoundException(`Instance "${instanceName}" not found`);
|
|
||||||
}
|
|
||||||
//inserido pot Francis - inicio
|
|
||||||
|
|
||||||
|
|
||||||
const urlServer = this.configService.get<HttpServer>('SERVER').URL;
|
const urlServer = this.configService.get<HttpServer>('SERVER').URL;
|
||||||
|
|
||||||
const instances: any[] = await Promise.all(
|
const instances: any[] = await Promise.all(
|
||||||
@ -108,15 +97,13 @@ export class WAMonitoringService {
|
|||||||
profileName: (await value.getProfileName()) || 'not loaded',
|
profileName: (await value.getProfileName()) || 'not loaded',
|
||||||
profilePictureUrl: value.profilePictureUrl,
|
profilePictureUrl: value.profilePictureUrl,
|
||||||
profileStatus: (await value.getProfileStatus()) || '',
|
profileStatus: (await value.getProfileStatus()) || '',
|
||||||
//status: status,
|
status: status,
|
||||||
status: value.connectionStatus.state,
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
if (this.configService.get<Auth>('AUTHENTICATION').EXPOSE_IN_FETCH_INSTANCES) {
|
if (this.configService.get<Auth>('AUTHENTICATION').EXPOSE_IN_FETCH_INSTANCES) {
|
||||||
instanceData.instance.serverUrl = urlServer;
|
instanceData.instance.serverUrl = urlServer;
|
||||||
instanceData.instance.apikey = (await this.repository.auth.find(key))?.apikey;
|
instanceData.instance.apikey = (await this.repository.auth.find(key))?.apikey;
|
||||||
|
|
||||||
|
|
||||||
const findChatwoot = await this.waInstances[key].findChatwoot();
|
const findChatwoot = await this.waInstances[key].findChatwoot();
|
||||||
if (findChatwoot && findChatwoot.enabled) {
|
if (findChatwoot && findChatwoot.enabled) {
|
||||||
@ -141,6 +128,96 @@ export class WAMonitoringService {
|
|||||||
return instances;
|
return instances;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ocultado por francis fim */
|
||||||
|
|
||||||
|
// inserido por francis inicio
|
||||||
|
|
||||||
|
public async instanceInfo(instanceName?: string) {
|
||||||
|
this.logger.verbose('get instance info');
|
||||||
|
if (instanceName && !this.waInstances[instanceName]) {
|
||||||
|
throw new NotFoundException(`Instance "${instanceName}" not found`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const instances: any[] = [];
|
||||||
|
|
||||||
|
for await (const [key, value] of Object.entries(this.waInstances)) {
|
||||||
|
if (value) {
|
||||||
|
this.logger.verbose('get instance info: ' + key);
|
||||||
|
let chatwoot: any;
|
||||||
|
|
||||||
|
const urlServer = this.configService.get<HttpServer>('SERVER').URL;
|
||||||
|
|
||||||
|
const findChatwoot = await this.waInstances[key].findChatwoot();
|
||||||
|
|
||||||
|
if (findChatwoot && findChatwoot.enabled) {
|
||||||
|
chatwoot = {
|
||||||
|
...findChatwoot,
|
||||||
|
webhook_url: `${urlServer}/chatwoot/webhook/${encodeURIComponent(key)}`,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value.connectionStatus.state === 'open') {
|
||||||
|
this.logger.verbose('instance: ' + key + ' - connectionStatus: open');
|
||||||
|
|
||||||
|
const instanceData = {
|
||||||
|
instance: {
|
||||||
|
instanceName: key,
|
||||||
|
owner: value.wuid,
|
||||||
|
profileName: (await value.getProfileName()) || 'not loaded',
|
||||||
|
profilePictureUrl: value.profilePictureUrl,
|
||||||
|
profileStatus: (await value.getProfileStatus()) || '',
|
||||||
|
status: value.connectionStatus.state,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
if (this.configService.get<Auth>('AUTHENTICATION').EXPOSE_IN_FETCH_INSTANCES) {
|
||||||
|
instanceData.instance['serverUrl'] = this.configService.get<HttpServer>('SERVER').URL;
|
||||||
|
|
||||||
|
instanceData.instance['apikey'] = (await this.repository.auth.find(key)).apikey;
|
||||||
|
|
||||||
|
instanceData.instance['chatwoot'] = chatwoot;
|
||||||
|
}
|
||||||
|
|
||||||
|
instances.push(instanceData);
|
||||||
|
} else {
|
||||||
|
this.logger.verbose('instance: ' + key + ' - connectionStatus: ' + value.connectionStatus.state);
|
||||||
|
|
||||||
|
const instanceData = {
|
||||||
|
instance: {
|
||||||
|
instanceName: key,
|
||||||
|
status: value.connectionStatus.state,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
if (this.configService.get<Auth>('AUTHENTICATION').EXPOSE_IN_FETCH_INSTANCES) {
|
||||||
|
instanceData.instance['serverUrl'] = this.configService.get<HttpServer>('SERVER').URL;
|
||||||
|
|
||||||
|
instanceData.instance['apikey'] = (await this.repository.auth.find(key)).apikey;
|
||||||
|
|
||||||
|
instanceData.instance['chatwoot'] = chatwoot;
|
||||||
|
}
|
||||||
|
|
||||||
|
instances.push(instanceData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.logger.verbose('return instance info: ' + instances.length);
|
||||||
|
|
||||||
|
return instances.find((i) => i.instance.instanceName === instanceName) ?? instances;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// inserido por francis fim
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private delInstanceFiles() {
|
private delInstanceFiles() {
|
||||||
this.logger.verbose('cron to delete instance files started');
|
this.logger.verbose('cron to delete instance files started');
|
||||||
setInterval(async () => {
|
setInterval(async () => {
|
||||||
|
Loading…
Reference in New Issue
Block a user