@@ -9,6 +9,7 @@ import { WAMonitoringService } from '../services/monitor.service';
99import { WAStartupService } from '../services/whatsapp.service' ;
1010import { WebhookService } from '../services/webhook.service' ;
1111import { Logger } from '../../config/logger.config' ;
12+ import { wa } from '../types/wa.types' ;
1213
1314export class InstanceController {
1415 constructor (
@@ -22,7 +23,7 @@ export class InstanceController {
2223
2324 private readonly logger = new Logger ( InstanceController . name ) ;
2425
25- public async createInstance ( { instanceName, webhook, events } : InstanceDto ) {
26+ public async createInstance ( { instanceName, webhook, events, qrcode } : InstanceDto ) {
2627 const mode = this . configService . get < Auth > ( 'AUTHENTICATION' ) . INSTANCE . MODE ;
2728
2829 if ( mode === 'container' ) {
@@ -46,9 +47,13 @@ export class InstanceController {
4647 instanceName : instance . instanceName ,
4748 } ) ;
4849
50+ let getEvents : string [ ] ;
51+
4952 if ( webhook ) {
5053 try {
5154 this . webhookService . create ( instance , { enabled : true , url : webhook , events } ) ;
55+
56+ getEvents = ( await this . webhookService . find ( instance ) ) . events ;
5257 } catch ( error ) {
5358 this . logger . log ( error ) ;
5459 }
@@ -61,6 +66,7 @@ export class InstanceController {
6166 } ,
6267 hash,
6368 webhook,
69+ events : getEvents ,
6470 } ;
6571 } else {
6672 const instance = new WAStartupService (
@@ -76,21 +82,35 @@ export class InstanceController {
7682 instanceName : instance . instanceName ,
7783 } ) ;
7884
85+ let getEvents : string [ ] ;
86+
7987 if ( webhook ) {
8088 try {
81- this . webhookService . create ( instance , { enabled : true , url : webhook } ) ;
89+ this . webhookService . create ( instance , { enabled : true , url : webhook , events } ) ;
90+
91+ getEvents = ( await this . webhookService . find ( instance ) ) . events ;
8292 } catch ( error ) {
8393 this . logger . log ( error ) ;
8494 }
8595 }
8696
97+ let getQrcode : wa . QrCode ;
98+
99+ if ( qrcode ) {
100+ await instance . connectToWhatsapp ( ) ;
101+ await delay ( 2000 ) ;
102+ getQrcode = instance . qrCode ;
103+ }
104+
87105 return {
88106 instance : {
89107 instanceName : instance . instanceName ,
90108 status : 'created' ,
91109 } ,
92110 hash,
93111 webhook,
112+ events : getEvents ,
113+ qrcode : getQrcode ,
94114 } ;
95115 }
96116 }
0 commit comments