From 4f93b626d19b1c097ce615b7e3a0ffea5663b9ba Mon Sep 17 00:00:00 2001 From: Rodrigo Rodriguez Date: Fri, 8 Jul 2022 13:22:23 -0300 Subject: [PATCH] new(whatsapp.gblib): Multiple providers can be loaded at once. --- packages/core.gbapp/services/GBMinService.ts | 17 +++++++++++------ .../services/WhatsappDirectLine.ts | 2 +- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/packages/core.gbapp/services/GBMinService.ts b/packages/core.gbapp/services/GBMinService.ts index 80973cd9..1949badc 100644 --- a/packages/core.gbapp/services/GBMinService.ts +++ b/packages/core.gbapp/services/GBMinService.ts @@ -373,8 +373,6 @@ export class GBMinService { } } - let activeMin; - let botId; if (chatapi) { @@ -387,8 +385,14 @@ export class GBMinService { botId = WhatsappDirectLine.phones[req.body.phoneId]; } - GBLog.info(`Client requested instance for: ${botId}.`); + GBLog.info(`A WhatsApp mobile requested instance for: ${botId}.`); + let urlMin: any = GBServer.globals.minInstances.filter + (p => p.instance.botId === botId); + + const botNumber = urlMin.core.getParam(urlMin.instance, 'Bot Number', null); + + let activeMin; // Processes group behaviour. @@ -396,6 +400,7 @@ export class GBMinService { text = text.replace(/\@\d+ /gi, ''); if (chatapi) { + // Ensures that the bot group is the active bot for the user (like switching). const message = req.body.messages[0]; @@ -415,7 +420,6 @@ export class GBMinService { } } - // Detects if the welcome message is enabled. if (process.env.WHATSAPP_WELCOME_DISABLED !== 'true') { @@ -431,9 +435,10 @@ export class GBMinService { )[0]; } - // Find active bot instance. + // If bot has a fixed Find active bot instance. - activeMin = toSwitchMin ? toSwitchMin : GBServer.globals.minBoot; + activeMin = botNumber ? urlMin : + toSwitchMin ? toSwitchMin : GBServer.globals.minBoot; // If it is the first time for the user, tries to auto-execute // start dialog if any is specified in Config.xlsx. diff --git a/packages/whatsapp.gblib/services/WhatsappDirectLine.ts b/packages/whatsapp.gblib/services/WhatsappDirectLine.ts index a6b9a3ef..4b91f94f 100644 --- a/packages/whatsapp.gblib/services/WhatsappDirectLine.ts +++ b/packages/whatsapp.gblib/services/WhatsappDirectLine.ts @@ -87,7 +87,7 @@ export class WhatsappDirectLine extends GBService { this.whatsappServiceKey = whatsappServiceKey; this.whatsappServiceNumber = whatsappServiceNumber; this.whatsappServiceUrl = whatsappServiceUrl; - this.chatapi = whatsappServiceNumber.indexOf(';') > -1 ? false : true; + this.chatapi = whatsappServiceNumber.indexOf(';') > -1 ? false : false; } public static async asyncForEach(array, callback) {