prisma orm: all endpoints ok

This commit is contained in:
Davidson Gomes 2024-06-06 17:01:48 -03:00
parent 161814a9e5
commit 51c873c19e
8 changed files with 115 additions and 46 deletions

View File

@ -3,6 +3,8 @@
### Feature ### Feature
* New method of saving sessions to a file using worker, made in partnership with [codechat](https://github.com/code-chat-br/whatsapp-api) * New method of saving sessions to a file using worker, made in partnership with [codechat](https://github.com/code-chat-br/whatsapp-api)
* Added prism orm, connection to postgres and mysql * Added prism orm, connection to postgres and mysql
* Added chatwoot integration activation
* Added typebot integration activation
### Fixed ### Fixed
* *

View File

@ -1,4 +1,6 @@
import { configService, Rabbitmq } from '../../../../config/env.config';
import { Logger } from '../../../../config/logger.config'; import { Logger } from '../../../../config/logger.config';
import { BadRequestException } from '../../../../exceptions';
import { InstanceDto } from '../../../dto/instance.dto'; import { InstanceDto } from '../../../dto/instance.dto';
import { RabbitmqDto } from '../dto/rabbitmq.dto'; import { RabbitmqDto } from '../dto/rabbitmq.dto';
import { RabbitmqService } from '../services/rabbitmq.service'; import { RabbitmqService } from '../services/rabbitmq.service';
@ -9,6 +11,8 @@ export class RabbitmqController {
constructor(private readonly rabbitmqService: RabbitmqService) {} constructor(private readonly rabbitmqService: RabbitmqService) {}
public async createRabbitmq(instance: InstanceDto, data: RabbitmqDto) { public async createRabbitmq(instance: InstanceDto, data: RabbitmqDto) {
if (!configService.get<Rabbitmq>('RABBITMQ').ENABLED) throw new BadRequestException('Rabbitmq is disabled');
logger.verbose('requested createRabbitmq from ' + instance.instanceName + ' instance'); logger.verbose('requested createRabbitmq from ' + instance.instanceName + ' instance');
if (!data.enabled) { if (!data.enabled) {

View File

@ -1,4 +1,6 @@
import { configService, Sqs } from '../../../../config/env.config';
import { Logger } from '../../../../config/logger.config'; import { Logger } from '../../../../config/logger.config';
import { BadRequestException } from '../../../../exceptions';
import { InstanceDto } from '../../../dto/instance.dto'; import { InstanceDto } from '../../../dto/instance.dto';
import { SqsDto } from '../dto/sqs.dto'; import { SqsDto } from '../dto/sqs.dto';
import { SqsService } from '../services/sqs.service'; import { SqsService } from '../services/sqs.service';
@ -9,6 +11,7 @@ export class SqsController {
constructor(private readonly sqsService: SqsService) {} constructor(private readonly sqsService: SqsService) {}
public async createSqs(instance: InstanceDto, data: SqsDto) { public async createSqs(instance: InstanceDto, data: SqsDto) {
if (!configService.get<Sqs>('SQS').ENABLED) throw new BadRequestException('Sqs is disabled');
logger.verbose('requested createSqs from ' + instance.instanceName + ' instance'); logger.verbose('requested createSqs from ' + instance.instanceName + ' instance');
if (!data.enabled) { if (!data.enabled) {

View File

@ -240,8 +240,20 @@ export class ChannelStartupService {
public async setSettings(data: SettingsDto) { public async setSettings(data: SettingsDto) {
this.logger.verbose('Setting settings'); this.logger.verbose('Setting settings');
await this.prismaRepository.setting.create({ await this.prismaRepository.setting.upsert({
data: { where: {
instanceId: this.instanceId,
},
update: {
rejectCall: data.rejectCall,
msgCall: data.msgCall,
groupsIgnore: data.groupsIgnore,
alwaysOnline: data.alwaysOnline,
readMessages: data.readMessages,
readStatus: data.readStatus,
syncFullHistory: data.syncFullHistory,
},
create: {
rejectCall: data.rejectCall, rejectCall: data.rejectCall,
msgCall: data.msgCall, msgCall: data.msgCall,
groupsIgnore: data.groupsIgnore, groupsIgnore: data.groupsIgnore,
@ -805,15 +817,20 @@ export class ChannelStartupService {
this.localProxy.enabled = data?.enabled; this.localProxy.enabled = data?.enabled;
this.logger.verbose(`Proxy enabled: ${this.localProxy.enabled}`); this.logger.verbose(`Proxy enabled: ${this.localProxy.enabled}`);
this.localProxy.proxy = { this.localProxy.host = data?.host;
host: data?.host, this.logger.verbose(`Proxy host: ${this.localProxy.host}`);
port: `${data?.port}`,
protocol: data?.protocol,
username: data?.username,
password: data?.password,
};
this.logger.verbose(`Proxy proxy: ${this.localProxy.proxy?.host}`); this.localProxy.port = data?.port;
this.logger.verbose(`Proxy port: ${this.localProxy.port}`);
this.localProxy.protocol = data?.protocol;
this.logger.verbose(`Proxy protocol: ${this.localProxy.protocol}`);
this.localProxy.username = data?.username;
this.logger.verbose(`Proxy username: ${this.localProxy.username}`);
this.localProxy.password = data?.password;
this.logger.verbose(`Proxy password: ${this.localProxy.password}`);
this.logger.verbose('Proxy loaded'); this.logger.verbose('Proxy loaded');
} }

View File

@ -553,11 +553,11 @@ export class BaileysStartupService extends ChannelStartupService {
let options; let options;
if (this.localProxy.enabled) { if (this.localProxy.enabled) {
this.logger.info('Proxy enabled: ' + this.localProxy.proxy?.host); this.logger.info('Proxy enabled: ' + this.localProxy?.host);
if (this.localProxy?.proxy?.host?.includes('proxyscrape')) { if (this.localProxy?.host?.includes('proxyscrape')) {
try { try {
const response = await axios.get(this.localProxy.proxy?.host); const response = await axios.get(this.localProxy?.host);
const text = response.data; const text = response.data;
const proxyUrls = text.split('\r\n'); const proxyUrls = text.split('\r\n');
const rand = Math.floor(Math.random() * Math.floor(proxyUrls.length)); const rand = Math.floor(Math.random() * Math.floor(proxyUrls.length));
@ -571,8 +571,20 @@ export class BaileysStartupService extends ChannelStartupService {
} }
} else { } else {
options = { options = {
agent: makeProxyAgent(this.localProxy.proxy), agent: makeProxyAgent({
fetchAgent: makeProxyAgent(this.localProxy.proxy), host: this.localProxy.host,
port: this.localProxy.port,
protocol: this.localProxy.protocol,
username: this.localProxy.username,
password: this.localProxy.password,
}),
fetchAgent: makeProxyAgent({
host: this.localProxy.host,
port: this.localProxy.port,
protocol: this.localProxy.protocol,
username: this.localProxy.username,
password: this.localProxy.password,
}),
}; };
} }
} }
@ -673,11 +685,11 @@ export class BaileysStartupService extends ChannelStartupService {
let options; let options;
if (this.localProxy.enabled) { if (this.localProxy.enabled) {
this.logger.info('Proxy enabled: ' + this.localProxy.proxy?.host); this.logger.info('Proxy enabled: ' + this.localProxy?.host);
if (this.localProxy?.proxy?.host?.includes('proxyscrape')) { if (this.localProxy?.host?.includes('proxyscrape')) {
try { try {
const response = await axios.get(this.localProxy.proxy?.host); const response = await axios.get(this.localProxy?.host);
const text = response.data; const text = response.data;
const proxyUrls = text.split('\r\n'); const proxyUrls = text.split('\r\n');
const rand = Math.floor(Math.random() * Math.floor(proxyUrls.length)); const rand = Math.floor(Math.random() * Math.floor(proxyUrls.length));
@ -691,8 +703,20 @@ export class BaileysStartupService extends ChannelStartupService {
} }
} else { } else {
options = { options = {
agent: makeProxyAgent(this.localProxy.proxy), agent: makeProxyAgent({
fetchAgent: makeProxyAgent(this.localProxy.proxy), host: this.localProxy.host,
port: this.localProxy.port,
protocol: this.localProxy.protocol,
username: this.localProxy.username,
password: this.localProxy.password,
}),
fetchAgent: makeProxyAgent({
host: this.localProxy.host,
port: this.localProxy.port,
protocol: this.localProxy.protocol,
username: this.localProxy.username,
password: this.localProxy.password,
}),
}; };
} }
} }
@ -2317,7 +2341,13 @@ export class BaileysStartupService extends ChannelStartupService {
if (this.localProxy.enabled) { if (this.localProxy.enabled) {
config = { config = {
...config, ...config,
httpsAgent: makeProxyAgent(this.localProxy.proxy), httpsAgent: makeProxyAgent({
host: this.localProxy.host,
port: this.localProxy.port,
protocol: this.localProxy.protocol,
username: this.localProxy.username,
password: this.localProxy.password,
}),
}; };
} }
@ -2388,7 +2418,13 @@ export class BaileysStartupService extends ChannelStartupService {
if (this.localProxy.enabled) { if (this.localProxy.enabled) {
config = { config = {
...config, ...config,
httpsAgent: makeProxyAgent(this.localProxy.proxy), httpsAgent: makeProxyAgent({
host: this.localProxy.host,
port: this.localProxy.port,
protocol: this.localProxy.protocol,
username: this.localProxy.username,
password: this.localProxy.password,
}),
}; };
} }
@ -3105,7 +3141,13 @@ export class BaileysStartupService extends ChannelStartupService {
if (this.localProxy.enabled) { if (this.localProxy.enabled) {
config = { config = {
...config, ...config,
httpsAgent: makeProxyAgent(this.localProxy.proxy), httpsAgent: makeProxyAgent({
host: this.localProxy.host,
port: this.localProxy.port,
protocol: this.localProxy.protocol,
username: this.localProxy.username,
password: this.localProxy.password,
}),
}; };
} }
@ -3307,7 +3349,13 @@ export class BaileysStartupService extends ChannelStartupService {
if (this.localProxy.enabled) { if (this.localProxy.enabled) {
config = { config = {
...config, ...config,
httpsAgent: makeProxyAgent(this.localProxy.proxy), httpsAgent: makeProxyAgent({
host: this.localProxy.host,
port: this.localProxy.port,
protocol: this.localProxy.protocol,
username: this.localProxy.username,
password: this.localProxy.password,
}),
}; };
} }

View File

@ -121,7 +121,8 @@ export declare namespace wa {
sessions?: TypebotSession[]; sessions?: TypebotSession[];
}; };
type Proxy = { export type LocalProxy = {
enabled?: boolean;
host?: string; host?: string;
port?: string; port?: string;
protocol?: string; protocol?: string;
@ -129,11 +130,6 @@ export declare namespace wa {
password?: string; password?: string;
}; };
export type LocalProxy = {
enabled?: boolean;
proxy?: Proxy;
};
export type LocalIntegration = { export type LocalIntegration = {
integration?: string; integration?: string;
number?: string; number?: string;

View File

@ -1,8 +1,14 @@
import { HttpsProxyAgent } from 'https-proxy-agent'; import { HttpsProxyAgent } from 'https-proxy-agent';
import { wa } from '../api/types/wa.types'; type Proxy = {
host: string;
password?: string;
port: string;
protocol: string;
username?: string;
};
export function makeProxyAgent(proxy: wa.Proxy | string) { export function makeProxyAgent(proxy: Proxy | string) {
if (typeof proxy === 'string') { if (typeof proxy === 'string') {
return new HttpsProxyAgent(proxy); return new HttpsProxyAgent(proxy);
} }

View File

@ -1050,21 +1050,14 @@ export const proxySchema: JSONSchema7 = {
type: 'object', type: 'object',
properties: { properties: {
enabled: { type: 'boolean', enum: [true, false] }, enabled: { type: 'boolean', enum: [true, false] },
proxy: {
type: 'object',
properties: {
host: { type: 'string' }, host: { type: 'string' },
port: { type: 'string' }, port: { type: 'string' },
protocol: { type: 'string' }, protocol: { type: 'string' },
username: { type: 'string' }, username: { type: 'string' },
password: { type: 'string' }, password: { type: 'string' },
}, },
required: ['host', 'port', 'protocol'], required: ['enabled', 'host', 'port', 'protocol'],
...isNotEmpty('host', 'port', 'protocol'), ...isNotEmpty('enabled', 'host', 'port', 'protocol'),
},
},
required: ['enabled', 'proxy'],
...isNotEmpty('enabled', 'proxy'),
}; };
export const handleLabelSchema: JSONSchema7 = { export const handleLabelSchema: JSONSchema7 = {