@@ -8,21 +8,22 @@ import { Logger } from '../../config/logger.config';
88import { BadRequestException , InternalServerErrorException } from '../../exceptions' ;
99import { RedisCache } from '../../libs/redis.client' ;
1010import { InstanceDto , SetPresenceDto } from '../dto/instance.dto' ;
11+ import { ChatwootService } from '../integrations/chatwoot/services/chatwoot.service' ;
12+ import { RabbitmqService } from '../integrations/rabbitmq/services/rabbitmq.service' ;
13+ import { SqsService } from '../integrations/sqs/services/sqs.service' ;
14+ import { TypebotService } from '../integrations/typebot/services/typebot.service' ;
15+ import { WebsocketService } from '../integrations/websocket/services/websocket.service' ;
1116import { RepositoryBroker } from '../repository/repository.manager' ;
1217import { AuthService , OldToken } from '../services/auth.service' ;
1318import { CacheService } from '../services/cache.service' ;
14- import { ChatwootService } from '../services/chatwoot.service' ;
1519import { IntegrationService } from '../services/integration.service' ;
1620import { WAMonitoringService } from '../services/monitor.service' ;
17- import { RabbitmqService } from '../services/rabbitmq.service' ;
1821import { SettingsService } from '../services/settings.service' ;
19- import { SqsService } from '../services/sqs.service' ;
20- import { TypebotService } from '../services/typebot.service' ;
2122import { WebhookService } from '../services/webhook.service' ;
22- import { WebsocketService } from '../services/websocket.service' ;
23- import { BaileysStartupService } from '../services/whatsapp.baileys.service' ;
24- import { BusinessStartupService } from '../services/whatsapp.business.service' ;
23+ import { BaileysStartupService } from '../services/whatsapp/whatsapp.baileys.service' ;
24+ import { BusinessStartupService } from '../services/whatsapp/whatsapp.business.service' ;
2525import { Events , Integration , wa } from '../types/wa.types' ;
26+ import { ProxyController } from './proxy.controller' ;
2627
2728export class InstanceController {
2829 constructor (
@@ -39,6 +40,7 @@ export class InstanceController {
3940 private readonly sqsService : SqsService ,
4041 private readonly typebotService : TypebotService ,
4142 private readonly integrationService : IntegrationService ,
43+ private readonly proxyService : ProxyController ,
4244 private readonly cache : RedisCache ,
4345 private readonly chatwootCache : CacheService ,
4446 ) { }
@@ -53,6 +55,7 @@ export class InstanceController {
5355 events,
5456 qrcode,
5557 number,
58+ mobile,
5659 integration,
5760 token,
5861 chatwoot_account_id,
@@ -84,6 +87,7 @@ export class InstanceController {
8487 typebot_delay_message,
8588 typebot_unknown_message,
8689 typebot_listening_from_me,
90+ proxy,
8791 } : InstanceDto ) {
8892 try {
8993 this . logger . verbose ( 'requested createInstance from ' + instanceName + ' instance' ) ;
@@ -115,7 +119,7 @@ export class InstanceController {
115119 ) ;
116120 }
117121
118- await this . waMonitor . saveInstance ( { integration, instanceName, token, number } ) ;
122+ await this . waMonitor . saveInstance ( { integration, instanceName, token, number, mobile } ) ;
119123
120124 instance . instanceName = instanceName ;
121125
@@ -345,6 +349,18 @@ export class InstanceController {
345349 }
346350 }
347351
352+ if ( proxy ) {
353+ const testProxy = await this . proxyService . testProxy ( proxy ) ;
354+ if ( ! testProxy ) {
355+ throw new BadRequestException ( 'Invalid proxy' ) ;
356+ }
357+
358+ await this . proxyService . createProxy ( instance , {
359+ enabled : true ,
360+ proxy,
361+ } ) ;
362+ }
363+
348364 if ( typebot_url ) {
349365 try {
350366 if ( ! isURL ( typebot_url , { require_tld : false } ) ) {
@@ -405,7 +421,7 @@ export class InstanceController {
405421
406422 if ( qrcode ) {
407423 this . logger . verbose ( 'creating qrcode' ) ;
408- await instance . connectToWhatsapp ( number ) ;
424+ await instance . connectToWhatsapp ( number , mobile ) ;
409425 await delay ( 5000 ) ;
410426 getQrcode = instance . qrCode ;
411427 }
@@ -569,7 +585,7 @@ export class InstanceController {
569585 }
570586 }
571587
572- public async connectToWhatsapp ( { instanceName, number = null } : InstanceDto ) {
588+ public async connectToWhatsapp ( { instanceName, number = null , mobile = null } : InstanceDto ) {
573589 try {
574590 this . logger . verbose ( 'requested connectToWhatsapp from ' + instanceName + ' instance' ) ;
575591
@@ -592,7 +608,7 @@ export class InstanceController {
592608
593609 if ( state == 'close' ) {
594610 this . logger . verbose ( 'connecting' ) ;
595- await instance . connectToWhatsapp ( number ) ;
611+ await instance . connectToWhatsapp ( number , mobile ) ;
596612
597613 await delay ( 5000 ) ;
598614 return instance . qrCode ;
@@ -633,6 +649,20 @@ export class InstanceController {
633649 }
634650 }
635651
652+ public async registerMobileCode ( { instanceName } : InstanceDto , { mobileCode } : any ) {
653+ try {
654+ this . logger . verbose ( 'requested registerMobileCode from ' + instanceName + ' instance' ) ;
655+
656+ const instance = this . waMonitor . waInstances [ instanceName ] ;
657+
658+ console . log ( 'mobileCode' , mobileCode ) ;
659+ await instance . receiveMobileCode ( mobileCode ) ;
660+ return { status : 'SUCCESS' , error : false , response : { message : 'Mobile code registered' } } ;
661+ } catch ( error ) {
662+ this . logger . error ( error ) ;
663+ }
664+ }
665+
636666 public async connectionState ( { instanceName } : InstanceDto ) {
637667 this . logger . verbose ( 'requested connectionState from ' + instanceName + ' instance' ) ;
638668 return {
0 commit comments