From 0c967a9f71ae3048f0978c91960d8c089acffadc Mon Sep 17 00:00:00 2001 From: Rodrigo Rodriguez Date: Thu, 9 Jun 2022 14:19:09 -0300 Subject: [PATCH] new(whatsapp.gblib): New provider. --- packages/basic.gblib/services/DialogKeywords.ts | 2 +- packages/core.gbapp/services/GBMinService.ts | 2 +- .../services/WhatsappDirectLine.ts | 16 ++++++++-------- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/basic.gblib/services/DialogKeywords.ts b/packages/basic.gblib/services/DialogKeywords.ts index 5c8e319d..59b9d5fa 100644 --- a/packages/basic.gblib/services/DialogKeywords.ts +++ b/packages/basic.gblib/services/DialogKeywords.ts @@ -700,7 +700,7 @@ export class DialogKeywords { } sleep(5000); } - const result = WhatsappDirectLine.lastMessage[mobile]; + const result = WhatsappDirectLine.lastMessage[this.min.instance.botId + mobile]; opts = await promise(step, result); if (previousResolve !== undefined) { diff --git a/packages/core.gbapp/services/GBMinService.ts b/packages/core.gbapp/services/GBMinService.ts index ed2b3bca..6d6a2560 100644 --- a/packages/core.gbapp/services/GBMinService.ts +++ b/packages/core.gbapp/services/GBMinService.ts @@ -468,7 +468,7 @@ export class GBMinService { const instance = await this.core.loadInstanceByBotId(activeMin.botId); await sec.updateUserInstance(id, instance.instanceId); - await (activeMin as any).whatsAppDirectLine.resetConversationId(id, ''); + await (activeMin as any).whatsAppDirectLine.resetConversationId(activeMin.botId, id, ''); const startDialog = activeMin.core.getParam(activeMin.instance, 'Start Dialog', null); diff --git a/packages/whatsapp.gblib/services/WhatsappDirectLine.ts b/packages/whatsapp.gblib/services/WhatsappDirectLine.ts index 7d527b11..c0c8f801 100644 --- a/packages/whatsapp.gblib/services/WhatsappDirectLine.ts +++ b/packages/whatsapp.gblib/services/WhatsappDirectLine.ts @@ -133,7 +133,7 @@ export class WhatsappDirectLine extends GBService { let productId = this.whatsappServiceNumber.split(';')[1] let url = `${this.INSTANCE_URL}/${productId}/setWebhook`; - let webhook = `${GBServer.globals.publicAddress}/webhooks/whatsapp/${this.botId}`; + let webhook = `${GBServer.globals.publicAddress}/webhooks/whatsapp`; WhatsappDirectLine.phones[phoneId] = this.botId; options = { @@ -162,8 +162,8 @@ export class WhatsappDirectLine extends GBService { } - public async resetConversationId(number, group = '') { - WhatsappDirectLine.conversationIds[number + group] = undefined; + public async resetConversationId(botId, number, group = '') { + WhatsappDirectLine.conversationIds[botId + number + group] = undefined; } public async check() { @@ -316,12 +316,12 @@ export class WhatsappDirectLine extends GBService { `No momento estou apenas conseguindo ler mensagens de texto.`, null); } } - - const conversationId = WhatsappDirectLine.conversationIds[from + group]; + const botId = this.min.instance.botId; + const conversationId = WhatsappDirectLine.conversationIds[botId + from + group]; const client = await this.directLineClient; - WhatsappDirectLine.lastMessage[from] = message; + WhatsappDirectLine.lastMessage[botId + from] = message; // Check if this message is from a Human Agent itself. @@ -393,12 +393,12 @@ export class WhatsappDirectLine extends GBService { } else if (user.agentMode === 'bot' || user.agentMode === null || user.agentMode === undefined) { - if (WhatsappDirectLine.conversationIds[from + group] === undefined) { + if (WhatsappDirectLine.conversationIds[botId + from + group] === undefined) { GBLog.info(`GBWhatsapp: Starting new conversation on Bot.`); const response = await client.Conversations.Conversations_StartConversation(); const generatedConversationId = response.obj.conversationId; - WhatsappDirectLine.conversationIds[from + group] = generatedConversationId; + WhatsappDirectLine.conversationIds[botId + from + group] = generatedConversationId; WhatsappDirectLine.mobiles[generatedConversationId] = from; WhatsappDirectLine.usernames[from] = fromName; WhatsappDirectLine.chatIds[generatedConversationId] = message.chatId;