diff --git a/packages/whatsapp.gblib/services/WhatsappDirectLine.ts b/packages/whatsapp.gblib/services/WhatsappDirectLine.ts index ef1db427..2c7dd2eb 100644 --- a/packages/whatsapp.gblib/services/WhatsappDirectLine.ts +++ b/packages/whatsapp.gblib/services/WhatsappDirectLine.ts @@ -138,7 +138,7 @@ export class WhatsappDirectLine extends GBService { const gbaiName = `${this.min.botId}.gbai`; const localName = Path.join('work', gbaiName, 'profile'); - const createClient = async (browserWSEndpoint) => { + const createClient = (browserWSEndpoint) => { let puppeteer: any = { headless: false, args: ['--disable-features=site-per-process', `--user-data-dir=${localName}`] @@ -155,6 +155,7 @@ export class WhatsappDirectLine extends GBService { puppeteer: puppeteer }); + client.initialize(); client.on('message', (async message => { await this.WhatsAppCallback(message, null); @@ -195,24 +196,25 @@ export class WhatsappDirectLine extends GBService { client.on('authenticated', () => { this.browserWSEndpoint = client.pupBrowser.wsEndpoint(); - client.pupBrowser.on('disconnected', (async () => { - GBLog.info(`Browser crashed. Restarting ${this.min.botId} WhatsApp native provider.`); - await (createClient.bind(this))(null); - }).bind(this)); - client.pupPage.on('error', (async () => { - GBLog.info(`Page crashed. Restarting ${this.min.botId} WhatsApp native provider.`); - if (!client.pupPage.isClosed()){ - client.pupPage.close(); - } await (createClient.bind(this))(null); - }).bind(this)); + GBLog.info(`WhatsApp QR Code authenticated for ${this.botId}.`); }); }; + client.pupBrowser.on('disconnected', (async () => { + GBLog.info(`Browser crashed. Restarting ${this.min.botId} WhatsApp native provider.`); + await (createClient.bind(this))(null); + }).bind(this)); + client.pupPage.on('error', (async () => { + GBLog.info(`Page crashed. Restarting ${this.min.botId} WhatsApp native provider.`); + if (!client.pupPage.isClosed()){ + client.pupPage.close(); + } await (createClient.bind(this))(null); + }).bind(this)); - await (createClient.bind(this))(this.browserWSEndpoint); - await client.initialize(); + (createClient.bind(this))(this.browserWSEndpoint); + setUrl = false; }