File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -373,18 +373,30 @@ export class InstanceController {
373373
374374 const state = instance ?. connectionStatus ?. state ;
375375
376- if ( state == 'open' ) {
376+ if ( state === 'open' ) {
377377 return await this . connectionState ( { instanceName } ) ;
378378 }
379379
380- if ( state == 'connecting' ) {
380+ if ( state === 'connecting' ) {
381381 return instance . qrCode ;
382382 }
383383
384- // Connect if closed or no state
384+ // Connect if closed, no state, or just loaded from DB
385+ this . logger . info ( `Connecting instance "${ instanceName } " (current state: ${ state || 'none' } )` ) ;
385386 await instance . connectToWhatsapp ( number ) ;
386- await delay ( 2000 ) ;
387- return instance . qrCode ;
387+ await delay ( 3000 ) ;
388+
389+ // Return QR code or connection status
390+ if ( instance . qrCode ) {
391+ return instance . qrCode ;
392+ }
393+
394+ return {
395+ instance : {
396+ instanceName : instanceName ,
397+ status : instance ?. connectionStatus ?. state || 'connecting' ,
398+ } ,
399+ } ;
388400 } catch ( error ) {
389401 this . logger . error ( error ) ;
390402 const errorMessage = error ?. message || error ?. toString ( ) || JSON . stringify ( error ) ;
You can’t perform that action at this time.
0 commit comments