Skip to content

Commit 51c873c

Browse files
committed
prisma orm: all endpoints ok
1 parent 161814a commit 51c873c

File tree

8 files changed

+115
-46
lines changed

8 files changed

+115
-46
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
### Feature
44
* New method of saving sessions to a file using worker, made in partnership with [codechat](https://github.com/code-chat-br/whatsapp-api)
55
* Added prism orm, connection to postgres and mysql
6+
* Added chatwoot integration activation
7+
* Added typebot integration activation
68

79
### Fixed
810
*

src/api/integrations/rabbitmq/controllers/rabbitmq.controller.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import { configService, Rabbitmq } from '../../../../config/env.config';
12
import { Logger } from '../../../../config/logger.config';
3+
import { BadRequestException } from '../../../../exceptions';
24
import { InstanceDto } from '../../../dto/instance.dto';
35
import { RabbitmqDto } from '../dto/rabbitmq.dto';
46
import { RabbitmqService } from '../services/rabbitmq.service';
@@ -9,6 +11,8 @@ export class RabbitmqController {
911
constructor(private readonly rabbitmqService: RabbitmqService) {}
1012

1113
public async createRabbitmq(instance: InstanceDto, data: RabbitmqDto) {
14+
if (!configService.get<Rabbitmq>('RABBITMQ').ENABLED) throw new BadRequestException('Rabbitmq is disabled');
15+
1216
logger.verbose('requested createRabbitmq from ' + instance.instanceName + ' instance');
1317

1418
if (!data.enabled) {

src/api/integrations/sqs/controllers/sqs.controller.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import { configService, Sqs } from '../../../../config/env.config';
12
import { Logger } from '../../../../config/logger.config';
3+
import { BadRequestException } from '../../../../exceptions';
24
import { InstanceDto } from '../../../dto/instance.dto';
35
import { SqsDto } from '../dto/sqs.dto';
46
import { SqsService } from '../services/sqs.service';
@@ -9,6 +11,7 @@ export class SqsController {
911
constructor(private readonly sqsService: SqsService) {}
1012

1113
public async createSqs(instance: InstanceDto, data: SqsDto) {
14+
if (!configService.get<Sqs>('SQS').ENABLED) throw new BadRequestException('Sqs is disabled');
1215
logger.verbose('requested createSqs from ' + instance.instanceName + ' instance');
1316

1417
if (!data.enabled) {

src/api/services/channel.service.ts

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,20 @@ export class ChannelStartupService {
240240

241241
public async setSettings(data: SettingsDto) {
242242
this.logger.verbose('Setting settings');
243-
await this.prismaRepository.setting.create({
244-
data: {
243+
await this.prismaRepository.setting.upsert({
244+
where: {
245+
instanceId: this.instanceId,
246+
},
247+
update: {
248+
rejectCall: data.rejectCall,
249+
msgCall: data.msgCall,
250+
groupsIgnore: data.groupsIgnore,
251+
alwaysOnline: data.alwaysOnline,
252+
readMessages: data.readMessages,
253+
readStatus: data.readStatus,
254+
syncFullHistory: data.syncFullHistory,
255+
},
256+
create: {
245257
rejectCall: data.rejectCall,
246258
msgCall: data.msgCall,
247259
groupsIgnore: data.groupsIgnore,
@@ -805,15 +817,20 @@ export class ChannelStartupService {
805817
this.localProxy.enabled = data?.enabled;
806818
this.logger.verbose(`Proxy enabled: ${this.localProxy.enabled}`);
807819

808-
this.localProxy.proxy = {
809-
host: data?.host,
810-
port: `${data?.port}`,
811-
protocol: data?.protocol,
812-
username: data?.username,
813-
password: data?.password,
814-
};
820+
this.localProxy.host = data?.host;
821+
this.logger.verbose(`Proxy host: ${this.localProxy.host}`);
822+
823+
this.localProxy.port = data?.port;
824+
this.logger.verbose(`Proxy port: ${this.localProxy.port}`);
825+
826+
this.localProxy.protocol = data?.protocol;
827+
this.logger.verbose(`Proxy protocol: ${this.localProxy.protocol}`);
828+
829+
this.localProxy.username = data?.username;
830+
this.logger.verbose(`Proxy username: ${this.localProxy.username}`);
815831

816-
this.logger.verbose(`Proxy proxy: ${this.localProxy.proxy?.host}`);
832+
this.localProxy.password = data?.password;
833+
this.logger.verbose(`Proxy password: ${this.localProxy.password}`);
817834

818835
this.logger.verbose('Proxy loaded');
819836
}

src/api/services/channels/whatsapp.baileys.service.ts

Lines changed: 62 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -553,11 +553,11 @@ export class BaileysStartupService extends ChannelStartupService {
553553
let options;
554554

555555
if (this.localProxy.enabled) {
556-
this.logger.info('Proxy enabled: ' + this.localProxy.proxy?.host);
556+
this.logger.info('Proxy enabled: ' + this.localProxy?.host);
557557

558-
if (this.localProxy?.proxy?.host?.includes('proxyscrape')) {
558+
if (this.localProxy?.host?.includes('proxyscrape')) {
559559
try {
560-
const response = await axios.get(this.localProxy.proxy?.host);
560+
const response = await axios.get(this.localProxy?.host);
561561
const text = response.data;
562562
const proxyUrls = text.split('\r\n');
563563
const rand = Math.floor(Math.random() * Math.floor(proxyUrls.length));
@@ -571,8 +571,20 @@ export class BaileysStartupService extends ChannelStartupService {
571571
}
572572
} else {
573573
options = {
574-
agent: makeProxyAgent(this.localProxy.proxy),
575-
fetchAgent: makeProxyAgent(this.localProxy.proxy),
574+
agent: makeProxyAgent({
575+
host: this.localProxy.host,
576+
port: this.localProxy.port,
577+
protocol: this.localProxy.protocol,
578+
username: this.localProxy.username,
579+
password: this.localProxy.password,
580+
}),
581+
fetchAgent: makeProxyAgent({
582+
host: this.localProxy.host,
583+
port: this.localProxy.port,
584+
protocol: this.localProxy.protocol,
585+
username: this.localProxy.username,
586+
password: this.localProxy.password,
587+
}),
576588
};
577589
}
578590
}
@@ -673,11 +685,11 @@ export class BaileysStartupService extends ChannelStartupService {
673685
let options;
674686

675687
if (this.localProxy.enabled) {
676-
this.logger.info('Proxy enabled: ' + this.localProxy.proxy?.host);
688+
this.logger.info('Proxy enabled: ' + this.localProxy?.host);
677689

678-
if (this.localProxy?.proxy?.host?.includes('proxyscrape')) {
690+
if (this.localProxy?.host?.includes('proxyscrape')) {
679691
try {
680-
const response = await axios.get(this.localProxy.proxy?.host);
692+
const response = await axios.get(this.localProxy?.host);
681693
const text = response.data;
682694
const proxyUrls = text.split('\r\n');
683695
const rand = Math.floor(Math.random() * Math.floor(proxyUrls.length));
@@ -691,8 +703,20 @@ export class BaileysStartupService extends ChannelStartupService {
691703
}
692704
} else {
693705
options = {
694-
agent: makeProxyAgent(this.localProxy.proxy),
695-
fetchAgent: makeProxyAgent(this.localProxy.proxy),
706+
agent: makeProxyAgent({
707+
host: this.localProxy.host,
708+
port: this.localProxy.port,
709+
protocol: this.localProxy.protocol,
710+
username: this.localProxy.username,
711+
password: this.localProxy.password,
712+
}),
713+
fetchAgent: makeProxyAgent({
714+
host: this.localProxy.host,
715+
port: this.localProxy.port,
716+
protocol: this.localProxy.protocol,
717+
username: this.localProxy.username,
718+
password: this.localProxy.password,
719+
}),
696720
};
697721
}
698722
}
@@ -2317,7 +2341,13 @@ export class BaileysStartupService extends ChannelStartupService {
23172341
if (this.localProxy.enabled) {
23182342
config = {
23192343
...config,
2320-
httpsAgent: makeProxyAgent(this.localProxy.proxy),
2344+
httpsAgent: makeProxyAgent({
2345+
host: this.localProxy.host,
2346+
port: this.localProxy.port,
2347+
protocol: this.localProxy.protocol,
2348+
username: this.localProxy.username,
2349+
password: this.localProxy.password,
2350+
}),
23212351
};
23222352
}
23232353

@@ -2388,7 +2418,13 @@ export class BaileysStartupService extends ChannelStartupService {
23882418
if (this.localProxy.enabled) {
23892419
config = {
23902420
...config,
2391-
httpsAgent: makeProxyAgent(this.localProxy.proxy),
2421+
httpsAgent: makeProxyAgent({
2422+
host: this.localProxy.host,
2423+
port: this.localProxy.port,
2424+
protocol: this.localProxy.protocol,
2425+
username: this.localProxy.username,
2426+
password: this.localProxy.password,
2427+
}),
23922428
};
23932429
}
23942430

@@ -3105,7 +3141,13 @@ export class BaileysStartupService extends ChannelStartupService {
31053141
if (this.localProxy.enabled) {
31063142
config = {
31073143
...config,
3108-
httpsAgent: makeProxyAgent(this.localProxy.proxy),
3144+
httpsAgent: makeProxyAgent({
3145+
host: this.localProxy.host,
3146+
port: this.localProxy.port,
3147+
protocol: this.localProxy.protocol,
3148+
username: this.localProxy.username,
3149+
password: this.localProxy.password,
3150+
}),
31093151
};
31103152
}
31113153

@@ -3307,7 +3349,13 @@ export class BaileysStartupService extends ChannelStartupService {
33073349
if (this.localProxy.enabled) {
33083350
config = {
33093351
...config,
3310-
httpsAgent: makeProxyAgent(this.localProxy.proxy),
3352+
httpsAgent: makeProxyAgent({
3353+
host: this.localProxy.host,
3354+
port: this.localProxy.port,
3355+
protocol: this.localProxy.protocol,
3356+
username: this.localProxy.username,
3357+
password: this.localProxy.password,
3358+
}),
33113359
};
33123360
}
33133361

src/api/types/wa.types.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,19 +121,15 @@ export declare namespace wa {
121121
sessions?: TypebotSession[];
122122
};
123123

124-
type Proxy = {
124+
export type LocalProxy = {
125+
enabled?: boolean;
125126
host?: string;
126127
port?: string;
127128
protocol?: string;
128129
username?: string;
129130
password?: string;
130131
};
131132

132-
export type LocalProxy = {
133-
enabled?: boolean;
134-
proxy?: Proxy;
135-
};
136-
137133
export type LocalIntegration = {
138134
integration?: string;
139135
number?: string;

src/utils/makeProxyAgent.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
import { HttpsProxyAgent } from 'https-proxy-agent';
22

3-
import { wa } from '../api/types/wa.types';
3+
type Proxy = {
4+
host: string;
5+
password?: string;
6+
port: string;
7+
protocol: string;
8+
username?: string;
9+
};
410

5-
export function makeProxyAgent(proxy: wa.Proxy | string) {
11+
export function makeProxyAgent(proxy: Proxy | string) {
612
if (typeof proxy === 'string') {
713
return new HttpsProxyAgent(proxy);
814
}

src/validate/validate.schema.ts

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,21 +1050,14 @@ export const proxySchema: JSONSchema7 = {
10501050
type: 'object',
10511051
properties: {
10521052
enabled: { type: 'boolean', enum: [true, false] },
1053-
proxy: {
1054-
type: 'object',
1055-
properties: {
1056-
host: { type: 'string' },
1057-
port: { type: 'string' },
1058-
protocol: { type: 'string' },
1059-
username: { type: 'string' },
1060-
password: { type: 'string' },
1061-
},
1062-
required: ['host', 'port', 'protocol'],
1063-
...isNotEmpty('host', 'port', 'protocol'),
1064-
},
1053+
host: { type: 'string' },
1054+
port: { type: 'string' },
1055+
protocol: { type: 'string' },
1056+
username: { type: 'string' },
1057+
password: { type: 'string' },
10651058
},
1066-
required: ['enabled', 'proxy'],
1067-
...isNotEmpty('enabled', 'proxy'),
1059+
required: ['enabled', 'host', 'port', 'protocol'],
1060+
...isNotEmpty('enabled', 'host', 'port', 'protocol'),
10681061
};
10691062

10701063
export const handleLabelSchema: JSONSchema7 = {

0 commit comments

Comments
 (0)