@@ -152,6 +152,8 @@ export class WAStartupService {
152152 private endSession = false ;
153153 private logBaileys = this . configService . get < Log > ( 'LOG' ) . BAILEYS ;
154154
155+ private phoneNumber : string ;
156+
155157 private chatwootService = new ChatwootService ( waMonitor , this . configService ) ;
156158
157159 public set instanceName ( name : string ) {
@@ -241,6 +243,12 @@ export class WAStartupService {
241243
242244 public get qrCode ( ) : wa . QrCode {
243245 this . logger . verbose ( 'Getting qrcode' ) ;
246+ if ( this . instance . qrcode ?. pairingCode ) {
247+ return {
248+ pairingCode : this . instance . qrcode ?. pairingCode ,
249+ } ;
250+ }
251+
244252 return {
245253 code : this . instance . qrcode ?. code ,
246254 base64 : this . instance . qrcode ?. base64 ,
@@ -588,11 +596,6 @@ export class WAStartupService {
588596 return this . eventEmitter . emit ( 'no.connection' , this . instance . name ) ;
589597 }
590598
591- // pairing code
592- // await delay(5000);
593- // const code = await this.client.requestPairingCode('557499879409');
594- // console.log(`Pairing code: ${code}`);
595-
596599 this . logger . verbose ( 'Incrementing QR code count' ) ;
597600 this . instance . qrcode . count ++ ;
598601
@@ -603,6 +606,13 @@ export class WAStartupService {
603606 color : { light : '#ffffff' , dark : '#198754' } ,
604607 } ;
605608
609+ if ( this . phoneNumber ) {
610+ await delay ( 2000 ) ;
611+ this . instance . qrcode . pairingCode = await this . client . requestPairingCode (
612+ this . phoneNumber ,
613+ ) ;
614+ }
615+
606616 this . logger . verbose ( 'Generating QR code' ) ;
607617 qrcode . toDataURL ( qr , optsQrcode , ( error , base64 ) => {
608618 if ( error ) {
@@ -614,15 +624,25 @@ export class WAStartupService {
614624 this . instance . qrcode . code = qr ;
615625
616626 this . sendDataWebhook ( Events . QRCODE_UPDATED , {
617- qrcode : { instance : this . instance . name , code : qr , base64 } ,
627+ qrcode : {
628+ instance : this . instance . name ,
629+ pairingCode : this . instance . qrcode . pairingCode ,
630+ code : qr ,
631+ base64,
632+ } ,
618633 } ) ;
619634
620635 if ( this . localChatwoot . enabled ) {
621636 this . chatwootService . eventWhatsapp (
622637 Events . QRCODE_UPDATED ,
623638 { instanceName : this . instance . name } ,
624639 {
625- qrcode : { instance : this . instance . name , code : qr , base64 } ,
640+ qrcode : {
641+ instance : this . instance . name ,
642+ pairingCode : this . instance . qrcode . pairingCode ,
643+ code : qr ,
644+ base64,
645+ } ,
626646 } ,
627647 ) ;
628648 }
@@ -631,7 +651,7 @@ export class WAStartupService {
631651 this . logger . verbose ( 'Generating QR code in terminal' ) ;
632652 qrcodeTerminal . generate ( qr , { small : true } , ( qrcode ) =>
633653 this . logger . log (
634- `\n{ instance: ${ this . instance . name } , qrcodeCount: ${ this . instance . qrcode . count } }\n` +
654+ `\n{ instance: ${ this . instance . name } pairingCode: ${ this . instance . qrcode . pairingCode } , qrcodeCount: ${ this . instance . qrcode . count } }\n` +
635655 qrcode ,
636656 ) ,
637657 ) ;
@@ -798,7 +818,7 @@ export class WAStartupService {
798818 return await useMultiFileAuthState ( join ( INSTANCE_DIR , this . instance . name ) ) ;
799819 }
800820
801- public async connectToWhatsapp ( ) : Promise < WASocket > {
821+ public async connectToWhatsapp ( number ?: string ) : Promise < WASocket > {
802822 this . logger . verbose ( 'Connecting to whatsapp' ) ;
803823 try {
804824 this . loadWebhook ( ) ;
@@ -872,6 +892,15 @@ export class WAStartupService {
872892
873893 this . logger . verbose ( 'Socket event handler initialized' ) ;
874894
895+ this . phoneNumber = number ;
896+
897+ // if (number) {
898+ // this.logger.verbose('creating pairing code');
899+ // await delay(5000);
900+ // this.phoneNumber = number;
901+ // this.instance.qrcode.pairingCode = await this.client.requestPairingCode(number);
902+ // }
903+
875904 return this . client ;
876905 } catch ( error ) {
877906 this . logger . error ( error ) ;
0 commit comments