From dc9286ffe88145fc9b119e3430ca904bea86fbe4 Mon Sep 17 00:00:00 2001 From: Rodrigo Rodriguez Date: Wed, 16 Jun 2021 11:53:20 -0300 Subject: [PATCH] fix(whatsapp.gblib): Adding Google to WhatsApp. --- boot.js | 1 - .../services/GBConversationalService.ts | 26 ++++++++++++------- .../dialogs/FeedbackDialog.ts | 2 +- .../services/WhatsappDirectLine.ts | 8 +++--- 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/boot.js b/boot.js index 6dacf07b..269b1da6 100644 --- a/boot.js +++ b/boot.js @@ -7,7 +7,6 @@ var pjson = require('./package.json'); // Displays version of Node JS being used at runtime and others attributes. - console.log(`[GB Runtime] BotServer = v${pjson.version}`); console.log(`[GB Runtime] BotLib = v${pjson.dependencies.botlib}`); console.log(`[GB Runtime] BotBuilder (MS) = v${pjson.dependencies.botbuilder}`); diff --git a/packages/core.gbapp/services/GBConversationalService.ts b/packages/core.gbapp/services/GBConversationalService.ts index 2d549ad9..8bc49fba 100644 --- a/packages/core.gbapp/services/GBConversationalService.ts +++ b/packages/core.gbapp/services/GBConversationalService.ts @@ -439,8 +439,8 @@ export class GBConversationalService { var filetype = href.split('.').pop(); if (videos.indexOf(filetype) > -1) { var out = '' + + ' ' + + '' return out; } else { return renderer.oldImage(href, title, text); @@ -466,7 +466,7 @@ export class GBConversationalService { text = text.replace('! [', '![').replace('] (', ']('); text = text.replace(`[[embed url=`, process.env.BOT_URL + '/').replace(']]', ''); // TODO: Improve it. - text = text.replace(`](kb`, "]("+ process.env.BOT_URL + '/kb'); // TODO: Improve it. + text = text.replace(`](kb`, "](" + process.env.BOT_URL + '/kb'); // TODO: Improve it. // According to the channel, formats the output optimized to it. @@ -951,14 +951,20 @@ export class GBConversationalService { * Sends a message in a user with an already started conversation (got ConversationReference set) */ public async sendOnConversation(min: GBMinInstance, user: GuaribasUser, message: string) { - const ref = JSON.parse(user.conversationReference); - MicrosoftAppCredentials.trustServiceUrl(ref.serviceUrl); - await min.bot['createConversation'](ref, async (t1) => { - const ref2 = TurnContext.getConversationReference(t1.activity); - await min.bot.continueConversation(ref2, async (t2) => { - await t2.sendActivity(message); + + if (user.conversationReference.startsWith('spaces')) { + await min['googleDirectLine'].sendToDevice(user.userSystemId, null, user.conversationReference, message); + } + else { + const ref = JSON.parse(user.conversationReference); + MicrosoftAppCredentials.trustServiceUrl(ref.serviceUrl); + await min.bot['createConversation'](ref, async (t1) => { + const ref2 = TurnContext.getConversationReference(t1.activity); + await min.bot.continueConversation(ref2, async (t2) => { + await t2.sendActivity(message); + }); }); - }); + } } public static kmpSearch(pattern, text) { diff --git a/packages/customer-satisfaction.gbapp/dialogs/FeedbackDialog.ts b/packages/customer-satisfaction.gbapp/dialogs/FeedbackDialog.ts index 3b700154..18e09026 100644 --- a/packages/customer-satisfaction.gbapp/dialogs/FeedbackDialog.ts +++ b/packages/customer-satisfaction.gbapp/dialogs/FeedbackDialog.ts @@ -92,7 +92,7 @@ export class FeedbackDialog extends IGBDialog { user.systemUser = await sec.getUserFromAgentSystemId(agentSystemId); await min.userProfile.set(step.context, user); - if (agentSystemId.charAt(2) === ":") { // Agent is from Teams. + if (agentSystemId.charAt(2) === ":" || agentSystemId.indexOf("@") > -1) { // Agent is from Teams or Google Chat. const agent = await sec.getUserFromSystemId(agentSystemId); await min.conversationalService['sendOnConversation'](min, agent, Messages[locale].notify_agent(step.context.activity.from.name)); diff --git a/packages/whatsapp.gblib/services/WhatsappDirectLine.ts b/packages/whatsapp.gblib/services/WhatsappDirectLine.ts index 0a1033be..d7fe8dcd 100644 --- a/packages/whatsapp.gblib/services/WhatsappDirectLine.ts +++ b/packages/whatsapp.gblib/services/WhatsappDirectLine.ts @@ -276,7 +276,7 @@ export class WhatsappDirectLine extends GBService { } else { GBLog.info(`USER (${id}) TO AGENT ${agent.userSystemId}: ${text}`); - if (user.agentSystemId.charAt(2) === ":") { // Agent is from Teams. + if (user.agentSystemId.charAt(2) === ":" || agent.userSystemId.indexOf("@") > -1) { // Agent is from Teams or Google Chat. await this.min.conversationalService['sendOnConversation'](this.min, agent, text); } else { @@ -487,10 +487,8 @@ export class WhatsappDirectLine extends GBService { } public async sendToDeviceEx(to, text, locale) { - const minBoot = GBServer.globals.minBoot as any; - - text = await minBoot.conversationalService.translate( - minBoot, + text = await this.min.conversationalService.translate( + this.min, text, locale );