fix: adjusts in proxy

This commit is contained in:
Davidson Gomes 2023-10-18 18:09:01 -03:00
parent d8d7debfee
commit e157a2a36b
2 changed files with 20 additions and 11 deletions

View File

@ -117,7 +117,7 @@ export class WAMonitoringService {
if (this.configService.get<Auth>('AUTHENTICATION').EXPOSE_IN_FETCH_INSTANCES) { if (this.configService.get<Auth>('AUTHENTICATION').EXPOSE_IN_FETCH_INSTANCES) {
instanceData.instance['serverUrl'] = this.configService.get<HttpServer>('SERVER').URL; instanceData.instance['serverUrl'] = this.configService.get<HttpServer>('SERVER').URL;
instanceData.instance['apikey'] = (await this.repository.auth.find(key)).apikey; instanceData.instance['apikey'] = (await this.repository.auth.find(key))?.apikey;
instanceData.instance['chatwoot'] = chatwoot; instanceData.instance['chatwoot'] = chatwoot;
} }
@ -136,7 +136,7 @@ export class WAMonitoringService {
if (this.configService.get<Auth>('AUTHENTICATION').EXPOSE_IN_FETCH_INSTANCES) { if (this.configService.get<Auth>('AUTHENTICATION').EXPOSE_IN_FETCH_INSTANCES) {
instanceData.instance['serverUrl'] = this.configService.get<HttpServer>('SERVER').URL; instanceData.instance['serverUrl'] = this.configService.get<HttpServer>('SERVER').URL;
instanceData.instance['apikey'] = (await this.repository.auth.find(key)).apikey; instanceData.instance['apikey'] = (await this.repository.auth.find(key))?.apikey;
instanceData.instance['chatwoot'] = chatwoot; instanceData.instance['chatwoot'] = chatwoot;
} }

View File

@ -128,9 +128,7 @@ import { Events, MessageSubtype, TypeMediaMessage, wa } from '../types/wa.types'
import { waMonitor } from '../whatsapp.module'; import { waMonitor } from '../whatsapp.module';
import { ChamaaiService } from './chamaai.service'; import { ChamaaiService } from './chamaai.service';
import { ChatwootService } from './chatwoot.service'; import { ChatwootService } from './chatwoot.service';
//import { SocksProxyAgent } from './socks-proxy-agent';
import { TypebotService } from './typebot.service'; import { TypebotService } from './typebot.service';
export class WAStartupService { export class WAStartupService {
constructor( constructor(
private readonly configService: ConfigService, private readonly configService: ConfigService,
@ -584,7 +582,7 @@ export class WAStartupService {
Object.assign(this.localProxy, data); Object.assign(this.localProxy, data);
this.logger.verbose('Proxy set'); this.logger.verbose('Proxy set');
this.client?.ws?.close(); this.reloadConnection();
} }
public async findProxy() { public async findProxy() {
@ -1183,11 +1181,23 @@ export class WAStartupService {
if (this.localProxy.enabled) { if (this.localProxy.enabled) {
this.logger.verbose('Proxy enabled'); this.logger.verbose('Proxy enabled');
if (this.localProxy.proxy.includes('proxyscrape')) {
const response = await axios.get(this.localProxy.proxy);
const text = response.data;
const proxyUrls = text.split('\r\n');
const rand = Math.floor(Math.random() * Math.floor(proxyUrls.length));
const proxyUrl = 'http://' + proxyUrls[rand];
console.log(proxyUrl);
options = {
agent: new ProxyAgent(proxyUrl as any),
};
} else {
options = { options = {
agent: new ProxyAgent(this.localProxy.proxy as any), agent: new ProxyAgent(this.localProxy.proxy as any),
fetchAgent: new ProxyAgent(this.localProxy.proxy as any),
}; };
} }
}
const socketConfig: UserFacingSocketConfig = { const socketConfig: UserFacingSocketConfig = {
...options, ...options,
@ -1546,7 +1556,6 @@ export class WAStartupService {
reuploadRequest: this.client.updateMediaMessage, reuploadRequest: this.client.updateMediaMessage,
}, },
); );
console.log(buffer);
messageRaw = { messageRaw = {
key: received.key, key: received.key,
pushName: received.pushName, pushName: received.pushName,
@ -3086,7 +3095,7 @@ export class WAStartupService {
await this.client.updateGroupsAddPrivacy(settings.privacySettings.groupadd); await this.client.updateGroupsAddPrivacy(settings.privacySettings.groupadd);
this.logger.verbose('Groups add privacy updated'); this.logger.verbose('Groups add privacy updated');
this.client?.ws?.close(); this.reloadConnection();
return { return {
update: 'success', update: 'success',