From f0b996fd682fd163cff8fa574b0946ce4a40f52b Mon Sep 17 00:00:00 2001 From: rodrigorodriguez Date: Thu, 13 Oct 2022 11:24:21 -0300 Subject: [PATCH] new(whatsapp.gblib): Native provider works in groups now. --- packages/basic.gblib/services/GBVMService.ts | 2 +- .../services/WhatsappDirectLine.ts | 30 +++++++++++-------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/packages/basic.gblib/services/GBVMService.ts b/packages/basic.gblib/services/GBVMService.ts index 66e109be..89fb9b02 100644 --- a/packages/basic.gblib/services/GBVMService.ts +++ b/packages/basic.gblib/services/GBVMService.ts @@ -870,7 +870,7 @@ export class GBVMService extends GBService { } } catch (error) { - throw new Error(`BASIC ERROR: ${error.message ? error.message : error}\n Stack:${error.stack}`); + throw new Error(`BASIC RUNTIME ERR: ${error.message ? error.message : error}\n Stack:${error.stack}`); } return ret; } diff --git a/packages/whatsapp.gblib/services/WhatsappDirectLine.ts b/packages/whatsapp.gblib/services/WhatsappDirectLine.ts index 78bb62fe..434a0e1e 100644 --- a/packages/whatsapp.gblib/services/WhatsappDirectLine.ts +++ b/packages/whatsapp.gblib/services/WhatsappDirectLine.ts @@ -150,7 +150,7 @@ export class WhatsappDirectLine extends GBService { const browser = await createBrowser(profilePath); this.browserWSEndpoint = await browser.wsEndpoint(); } - else{ + else { this.browserWSEndpoint = browserWSEndpoint; } @@ -179,19 +179,23 @@ export class WhatsappDirectLine extends GBService { qrcode.generate(qr, { small: true, scale: 0.5 }); // While handling other bots uses boot instance of this class to send QR Codes. - + const s = new DialogKeywords(this.min, null, null, null); - const qrBuf = await s.getQRCode(qr); - const gbaiName = `${this.min.botId}.gbai`; - const localName = Path.join('work', gbaiName, 'cache', `qr${GBAdminService.getRndReadableIdentifier()}.png`); - fs.writeFileSync(localName, qrBuf); - const url = urlJoin( - GBServer.globals.publicAddress, - this.min.botId, - 'cache', - Path.basename(localName) - ); - GBServer.globals.minBoot.whatsAppDirectLine.sendFileToDevice(adminNumber, url, Path.basename(localName), msg); + if (minBoot.botId !== this.botId) { + const qrBuf = await s.getQRCode(qr); + const gbaiName = `${this.min.botId}.gbai`; + const localName = Path.join('work', gbaiName, 'cache', `qr${GBAdminService.getRndReadableIdentifier()}.png`); + fs.writeFileSync(localName, qrBuf); + const url = urlJoin( + GBServer.globals.publicAddress, + this.min.botId, + 'cache', + Path.basename(localName) + ); + GBServer.globals.minBoot.whatsAppDirectLine.sendFileToDevice(adminNumber, url, Path.basename(localName), msg); + } + + // The e-mail is sent to all bots. s.sendEmail(adminEmail, `Check your WhatsApp for bot ${this.botId}`, msg); }).bind(this));