From 8d3ee08a9f4b3b5ad4a83e0d5d4ec7855f594143 Mon Sep 17 00:00:00 2001 From: Rodrigo Rodriguez Date: Thu, 9 Jun 2022 13:31:24 -0300 Subject: [PATCH] new(whatsapp.gblib): New provider. --- packages/core.gbapp/services/GBMinService.ts | 16 ++++++++++++---- .../services/WhatsappDirectLine.ts | 2 ++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/packages/core.gbapp/services/GBMinService.ts b/packages/core.gbapp/services/GBMinService.ts index 70c37b8d..7295373e 100644 --- a/packages/core.gbapp/services/GBMinService.ts +++ b/packages/core.gbapp/services/GBMinService.ts @@ -365,9 +365,17 @@ export class GBMinService { } let activeMin; - let botId = req.params.botId; - if (botId === '[default]' || botId === undefined) { - botId = GBConfigService.get('BOT_ID'); + + let botId; + + if (chatapi) { + botId = req.params.botId; + if (botId === '[default]' || botId === undefined) { + botId = GBConfigService.get('BOT_ID'); + } + } + else { + botId = WhatsappDirectLine.phones[req.body.phoneId]; } GBLog.info(`Client requested instance for: ${botId}.`); @@ -508,7 +516,7 @@ export class GBMinService { await minInstance.whatsAppDirectLine.received(req, res); } } catch (error) { - + GBLog.error(`Error on Whatsapp callback: ${error.data ? error.data : error}`); } } diff --git a/packages/whatsapp.gblib/services/WhatsappDirectLine.ts b/packages/whatsapp.gblib/services/WhatsappDirectLine.ts index c75ba90a..40183cc6 100644 --- a/packages/whatsapp.gblib/services/WhatsappDirectLine.ts +++ b/packages/whatsapp.gblib/services/WhatsappDirectLine.ts @@ -51,6 +51,7 @@ export class WhatsappDirectLine extends GBService { public static conversationIds = {}; public static mobiles = {}; + public static phones = {}; public static chatIds = {}; public static usernames = {}; public static state = {}; // 2: Waiting, 3: MessageArrived. @@ -133,6 +134,7 @@ export class WhatsappDirectLine extends GBService { let url = `${this.INSTANCE_URL}/${productId}/setWebhook`; let webhook = `${GBServer.globals.publicAddress}/webhooks/whatsapp/${this.botId}`; + WhatsappDirectLine.phones[phoneId] = this.botId; options = { url: url,