From 6306274db9bcaf151aab05b54836783723496ea0 Mon Sep 17 00:00:00 2001 From: Rodrigo Rodriguez Date: Fri, 5 Jun 2020 16:09:47 -0300 Subject: [PATCH] fix(whatsapp.gblib): Fix of missing mobile number. --- .../services/GBConversationalService.ts | 19 ++++++++-------- packages/kb.gbapp/services/KBService.ts | 22 ++++++++++++------- .../services/WhatsappDirectLine.ts | 2 +- 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/packages/core.gbapp/services/GBConversationalService.ts b/packages/core.gbapp/services/GBConversationalService.ts index b61e5f0d..a9a3d737 100644 --- a/packages/core.gbapp/services/GBConversationalService.ts +++ b/packages/core.gbapp/services/GBConversationalService.ts @@ -97,7 +97,8 @@ export class GBConversationalService { if (step !== null) { if (!isNaN(step.context.activity.from.id as any)) { - GBLog.info(`Sending file ${url} to ${step.context.activity.from.id}...`) + mobile = step.context.activity.from.id; + GBLog.info(`Sending file ${url} to ${mobile}...`) const filename = url.substring(url.lastIndexOf('/') + 1); await min.whatsAppDirectLine.sendFileToDevice(mobile, url, filename, caption); } @@ -348,7 +349,7 @@ export class GBConversationalService { await step.context.sendActivity(currentText); } else { - this.sendToMobile(min, mobile, currentText); + await this.sendToMobile(min, mobile, currentText); } await sleep(3000); currentText = ''; @@ -371,7 +372,7 @@ export class GBConversationalService { await step.context.sendActivity(currentText); } else { - this.sendToMobile(min, mobile, currentText); + await this.sendToMobile(min, mobile, currentText); } await sleep(3000); } @@ -404,9 +405,9 @@ export class GBConversationalService { await step.context.sendActivity(currentText); } else { - this.sendToMobile(min, mobile, currentText); + await this.sendToMobile(min, mobile, currentText); } - await sleep(3000); + await sleep(2900); } currentText = ''; state = State.InImageCaption; @@ -435,7 +436,7 @@ export class GBConversationalService { let url = urlJoin(GBServer.globals.publicAddress, currentImage); await this.sendFile(min, step, mobile, url, currentCaption); currentCaption = ''; - await sleep(5000); + await sleep(4500); currentImage = ''; } else { @@ -451,7 +452,7 @@ export class GBConversationalService { } else { - this.sendToMobile(min, mobile, currentText); + await this.sendToMobile(min, mobile, currentText); } } } @@ -590,7 +591,7 @@ export class GBConversationalService { const user = await sec.ensureUser(min.instance.instanceId, member.id, member.name, "", "web", member.name); if (text !== null) { - text = await min.conversationalService.translate(min, + text = await min.conversationalService.translate(min, min.instance.translatorKey ? min.instance.translatorKey : minBoot.instance.translatorKey, min.instance.translatorEndpoint ? min.instance.translatorEndpoint : minBoot.instance.translatorEndpoint, text, @@ -606,7 +607,7 @@ export class GBConversationalService { const user = await min.userProfile.get(step.context, {}); if (user) { const minBoot = GBServer.globals.minBoot as any; - text = await min.conversationalService.translate(min, + text = await min.conversationalService.translate(min, min.instance.translatorKey ? min.instance.translatorKey : minBoot.instance.translatorKey, min.instance.translatorEndpoint ? min.instance.translatorEndpoint : minBoot.instance.translatorEndpoint, text, diff --git a/packages/kb.gbapp/services/KBService.ts b/packages/kb.gbapp/services/KBService.ts index 4d3b3093..7d6c3ade 100644 --- a/packages/kb.gbapp/services/KBService.ts +++ b/packages/kb.gbapp/services/KBService.ts @@ -380,7 +380,7 @@ export class KBService implements IGBKBService { public async sendAnswer(min: GBMinInstance, channel: string, step: GBDialogStep, answer: GuaribasAnswer) { if (answer.content.endsWith('.mp4')) { - await this.playVideo(min, min.conversationalService, step, answer); + await this.playVideo(min, min.conversationalService, step, answer, channel); } else if (answer.format === '.md') { @@ -433,14 +433,14 @@ export class KBService implements IGBKBService { // MSFT Translator breaks markdown, so we need to fix it: text = text.replace('! [', '![').replace('] (', ']('); - text = text.replace(`[[embed url=`, process.env.BOT_URL + '/').replace(']]', ''); // TODO: Improve it. - const html = marked(text); + let html = text.replace(`[[embed url=`, process.env.BOT_URL + '/').replace(']]', ''); // TODO: Improve it. // According to the channel, formats the output optimized to it. if (channel === 'webchat' && GBConfigService.get('DISABLE_WEB') !== 'true') { + html = marked(text); await this.sendMarkdownToWeb(min, step, conversationalService, html, answer); } else if (channel === 'whatsapp') { @@ -448,6 +448,7 @@ export class KBService implements IGBKBService { await conversationalService.sendMarkdownToMobile(min, step, user.userSystemId, text); } else { + html = marked(text); await min.conversationalService.sendText(min, step, html); } } @@ -481,11 +482,16 @@ export class KBService implements IGBKBService { } - private async playVideo(min, conversationalService: IGBConversationalService, step: GBDialogStep, answer: GuaribasAnswer) { - await conversationalService.sendEvent(min, step, 'play', { - playerType: 'video', - data: answer.content - }); + private async playVideo(min, conversationalService: IGBConversationalService, + step: GBDialogStep, answer: GuaribasAnswer, channel: string) { + if (channel === "whatsapp") { + await min.conversationalService.sendFile(min, step, null, answer.content, ""); + } else { + await conversationalService.sendEvent(min, step, 'play', { + playerType: 'video', + data: answer.content + }); + } } public async importKbPackage( diff --git a/packages/whatsapp.gblib/services/WhatsappDirectLine.ts b/packages/whatsapp.gblib/services/WhatsappDirectLine.ts index 85a36e4d..140153bb 100644 --- a/packages/whatsapp.gblib/services/WhatsappDirectLine.ts +++ b/packages/whatsapp.gblib/services/WhatsappDirectLine.ts @@ -428,7 +428,7 @@ export class WhatsappDirectLine extends GBService { } - public async sendToDevice(to, msg) { + public async sendToDevice(to: string, msg: string) { const cmd = '/audio '; if (msg.startsWith(cmd)) {