From c6de0f0fa1cf626bbe7ec86615b7283fafe2c946 Mon Sep 17 00:00:00 2001 From: Rodrigo Rodriguez Date: Tue, 4 Oct 2022 15:42:34 -0300 Subject: [PATCH] fix(whatsapp.gblib): SEND FILE and WPP providers. --- .../services/WhatsappDirectLine.ts | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/packages/whatsapp.gblib/services/WhatsappDirectLine.ts b/packages/whatsapp.gblib/services/WhatsappDirectLine.ts index 753326bf..e600780a 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 = (browserWSEndpoint) => { + const createClient = async (browserWSEndpoint) => { let puppeteer: any = { headless: false, args: ['--disable-features=site-per-process', `--user-data-dir=${localName}`] @@ -156,8 +156,8 @@ export class WhatsappDirectLine extends GBService { }); - client.initialize(); - this.browserWSEndpoint = client.browser.wsEndpoint(); + await client.initialize(); + this.browserWSEndpoint = client.pupBrowser.wsEndpoint(); client.on('message', (async message => { await this.WhatsAppCallback(message, null); @@ -200,14 +200,21 @@ export class WhatsappDirectLine extends GBService { GBLog.info(`WhatsApp QR Code authenticated for ${this.botId}.`); }); - client.browser.on('disconnected', (async () => { - (createClient.bind(this))(this.browserWSEndpoint); + client.pupBrowser.on('disconnected', (async () => { + GBLog.info(`555555`); + await (createClient.bind(this))(null); }).bind(this)); - - }; + client.pupPage.on('error', (async () => { + GBLog.info(`22222s`); + if (!client.pupPage.isClosed()){ + client.pupPage.close(); + } await (createClient.bind(this))(null); + }).bind(this)); + + }; - (createClient.bind(this))(this.browserWSEndpoint); + await (createClient.bind(this))(this.browserWSEndpoint); setUrl = false; }