From 3f7e024b58660d0be0734dc5f3a3cd7884df3727 Mon Sep 17 00:00:00 2001 From: Rodrigo Rodriguez Date: Sun, 9 Oct 2022 14:21:40 -0300 Subject: [PATCH] fix(whatsapp.gblib): SEND FILE and WPP providers. --- .../services/WhatsappDirectLine.ts | 31 +++++++++---------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/packages/whatsapp.gblib/services/WhatsappDirectLine.ts b/packages/whatsapp.gblib/services/WhatsappDirectLine.ts index 2c7dd2eb..98ca6f9e 100644 --- a/packages/whatsapp.gblib/services/WhatsappDirectLine.ts +++ b/packages/whatsapp.gblib/services/WhatsappDirectLine.ts @@ -138,7 +138,8 @@ export class WhatsappDirectLine extends GBService { const gbaiName = `${this.min.botId}.gbai`; const localName = Path.join('work', gbaiName, 'profile'); - const createClient = (browserWSEndpoint) => { + + const createClient = async (browserWSEndpoint) => { let puppeteer: any = { headless: false, args: ['--disable-features=site-per-process', `--user-data-dir=${localName}`] @@ -155,7 +156,8 @@ export class WhatsappDirectLine extends GBService { puppeteer: puppeteer }); - client.initialize(); + await client.initialize(); + this.browserWSEndpoint = client.pupBrowser.wsEndpoint(); client.on('message', (async message => { await this.WhatsAppCallback(message, null); @@ -196,25 +198,22 @@ export class WhatsappDirectLine extends GBService { client.on('authenticated', () => { this.browserWSEndpoint = client.pupBrowser.wsEndpoint(); - + 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)); }; + await (createClient.bind(this))(this.browserWSEndpoint); - 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)); - - (createClient.bind(this))(this.browserWSEndpoint); - setUrl = false; }