From 7b84ee112d9386dc18a0bf0e83af5578877d8817 Mon Sep 17 00:00:00 2001 From: Rodrigo Rodriguez Date: Thu, 4 Jun 2020 00:05:53 -0300 Subject: [PATCH] fix(core.gbapp): Switch of bots working by activationCode. --- package-lock.json | 6 +++--- packages/core.gbapp/services/GBMinService.ts | 11 +++++++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/package-lock.json b/package-lock.json index 76ff6215..d467a2f4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3273,9 +3273,9 @@ } }, "botlib": { - "version": "1.5.4", - "resolved": "https://registry.npmjs.org/botlib/-/botlib-1.5.4.tgz", - "integrity": "sha512-m3VIwB1c/ZqRvkZ/Ip3zJhFDAK1kS8hSNS+J7JOJe9N2L1ajZU0QDV5ziK5KlWy5CpBx5TEMB0gJ3+SMhX+aCQ==", + "version": "1.5.5", + "resolved": "https://registry.npmjs.org/botlib/-/botlib-1.5.5.tgz", + "integrity": "sha512-fugvHvp0XDqAflOFxbLknC49ijDL0P0c8DDztLSj2sUfwoJ6J2YqVIU8kkVW1OdjNGvXCNUjiZS6ZHEuHaGdMQ==", "requires": { "async": "3.1.0", "botbuilder": "4.7.0", diff --git a/packages/core.gbapp/services/GBMinService.ts b/packages/core.gbapp/services/GBMinService.ts index 9e58297b..fc099c04 100644 --- a/packages/core.gbapp/services/GBMinService.ts +++ b/packages/core.gbapp/services/GBMinService.ts @@ -144,8 +144,11 @@ export class GBMinService { } let activeMin; if (process.env.WHATSAPP_WELCOME_DISABLED !== "true") { - // TODO: Active in two modes. - const toSwitchMin = GBServer.globals.minInstances.filter(p => p.instance.botId === text)[0]; + let toSwitchMin = GBServer.globals.minInstances.filter(p => p.instance.botId.toLowerCase() === text.toLowerCase())[0]; + if (!toSwitchMin){ + toSwitchMin = GBServer.globals.minInstances.filter(p => p.instance.activationCode.toLowerCase() === text.toLowerCase())[0]; + } + activeMin = toSwitchMin ? toSwitchMin : GBServer.globals.minBoot; let sec = new SecService(); @@ -159,8 +162,8 @@ export class GBMinService { } else { // User wants to switch bots. if (toSwitchMin !== undefined) { - const botId = text; - const instance = await this.core.loadInstanceByBotId(botId); + + const instance = await this.core.loadInstanceByBotId(activeMin.botId); await sec.updateUserInstance(id, instance.instanceId); await (activeMin as any).whatsAppDirectLine.resetConversationId(id);