From 821842c317ac38af08718a4c9131cc09582556a7 Mon Sep 17 00:00:00 2001 From: Rodrigo Rodriguez Date: Mon, 25 May 2020 14:53:28 -0300 Subject: [PATCH] fix(core.gbapp): Better logging and WhatsApp channel detection fix. --- package-lock.json | 30 +++++++++---------- package.json | 2 +- .../services/GBConversationalService.ts | 30 +++++++++++-------- packages/core.gbapp/services/GBMinService.ts | 4 +-- 4 files changed, 35 insertions(+), 31 deletions(-) diff --git a/package-lock.json b/package-lock.json index 4cad4c69..76ff6215 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2925,9 +2925,9 @@ "integrity": "sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg==" }, "bn.js": { - "version": "4.11.8", - "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.8.tgz", - "integrity": "sha512-ItfYfPLkWHUjckQCk8xC+LwxgK8NYcXywGigJgSwOP8Y2iyWT4f2vsZnoOXTTbo+o5yXmIUJ4gn5538SO5S3gA==" + "version": "4.11.9", + "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.9.tgz", + "integrity": "sha512-E6QoYqCKZfgatHTdHzs1RRKP7ip4vvm+EyRUeE2RF0NblwVvb0p6jSVeNTOFxPn26QXN2o6SMfNxKp6kU8zQaw==" }, "body-parser": { "version": "1.19.0", @@ -3141,9 +3141,9 @@ }, "dependencies": { "@types/node": { - "version": "10.17.21", - "resolved": "https://registry.npmjs.org/@types/node/-/node-10.17.21.tgz", - "integrity": "sha512-PQKsydPxYxF1DsAFWmunaxd3sOi3iMt6Zmx/tgaagHYmwJ/9cRH91hQkeJZaUGWbvn0K5HlSVEXkn5U/llWPpQ==" + "version": "10.17.24", + "resolved": "https://registry.npmjs.org/@types/node/-/node-10.17.24.tgz", + "integrity": "sha512-5SCfvCxV74kzR3uWgTYiGxrd69TbT1I6+cMx1A5kEly/IVveJBimtAMlXiEyVFn5DvUFewQWxOOiJhlxeQwxgA==" } } }, @@ -3273,9 +3273,9 @@ } }, "botlib": { - "version": "1.5.2", - "resolved": "https://registry.npmjs.org/botlib/-/botlib-1.5.2.tgz", - "integrity": "sha512-drDSpfwN8dQe9X0+YkOFEP0wOfzvbumga3UlR0kB/4Zkt22jPlDXdCmS6e83hV9/93XMibwCgdKpF6WnKeZ8Zg==", + "version": "1.5.4", + "resolved": "https://registry.npmjs.org/botlib/-/botlib-1.5.4.tgz", + "integrity": "sha512-m3VIwB1c/ZqRvkZ/Ip3zJhFDAK1kS8hSNS+J7JOJe9N2L1ajZU0QDV5ziK5KlWy5CpBx5TEMB0gJ3+SMhX+aCQ==", "requires": { "async": "3.1.0", "botbuilder": "4.7.0", @@ -9210,9 +9210,9 @@ } }, "microsoft-cognitiveservices-speech-sdk": { - "version": "1.11.0", - "resolved": "https://registry.npmjs.org/microsoft-cognitiveservices-speech-sdk/-/microsoft-cognitiveservices-speech-sdk-1.11.0.tgz", - "integrity": "sha512-03nPTggWCjkvVvJ6Y795UUKkFhdVn32yYqIpI/vEvAQAssffbcP5syU8JfUzN9TF4UfYvUFKlnyNgGj7y1DyAw==", + "version": "1.12.0", + "resolved": "https://registry.npmjs.org/microsoft-cognitiveservices-speech-sdk/-/microsoft-cognitiveservices-speech-sdk-1.12.0.tgz", + "integrity": "sha512-1+67ejHPbz8VOBxFdh3Wq//K8mfKHFA3C1mLN779hRq0NDUfnkiGt8MApq9ry5gMLK3JX2zkt4SASI8EATyn9Q==", "requires": { "asn1.js-rfc2560": "^5.0.0", "asn1.js-rfc5280": "^3.0.0", @@ -19086,9 +19086,9 @@ } }, "ws": { - "version": "7.2.3", - "resolved": "https://registry.npmjs.org/ws/-/ws-7.2.3.tgz", - "integrity": "sha512-HTDl9G9hbkNDk98naoR/cHDws7+EyYMOdL1BmjsZXRUjf7d+MficC4B7HLUPlSiho0vg+CWKrGIt/VJBd1xunQ==" + "version": "7.3.0", + "resolved": "https://registry.npmjs.org/ws/-/ws-7.3.0.tgz", + "integrity": "sha512-iFtXzngZVXPGgpTlP1rBqsUK82p9tKqsWRPg5L56egiljujJT3vGAYnHANvFxBieXrTFavhzhxW52jnaWV+w2w==" }, "x256": { "version": "0.0.2", diff --git a/package.json b/package.json index c80310dd..7527ed89 100644 --- a/package.json +++ b/package.json @@ -76,7 +76,7 @@ "google-libphonenumber": "3.2.8", "js-beautify": "1.10.2", "marked": "0.8.0", - "microsoft-cognitiveservices-speech-sdk": "1.11.0", + "microsoft-cognitiveservices-speech-sdk": "1.12.0", "ms-rest-azure": "3.0.0", "nexmo": "2.5.2", "ngrok": "3.2.7", diff --git a/packages/core.gbapp/services/GBConversationalService.ts b/packages/core.gbapp/services/GBConversationalService.ts index 78d95ef7..0ca7b0c2 100644 --- a/packages/core.gbapp/services/GBConversationalService.ts +++ b/packages/core.gbapp/services/GBConversationalService.ts @@ -39,8 +39,6 @@ import { MessageFactory, RecognizerResult } from 'botbuilder'; import { LuisRecognizer } from 'botbuilder-ai'; import { GBDialogStep, GBLog, GBMinInstance, IGBCoreService } from 'botlib'; -import { AzureText } from 'pragmatismo-io-framework'; -import { Messages } from '../strings'; import { GBServer } from '../../../src/app'; import { Readable } from 'stream' import { GBAdminService } from '../../admin.gbapp/services/GBAdminService'; @@ -54,6 +52,7 @@ const { exec } = require('child_process') const fs = require('fs') const prism = require('prism-media') const sdk = require("microsoft-cognitiveservices-speech-sdk"); +sdk.Recognizer.enableTelemetry(false); const uuidv4 = require('uuid/v4'); const request = require('request-promise-native'); @@ -90,15 +89,22 @@ export class GBConversationalService { public getCurrentLanguage(step: GBDialogStep) { return step.context.activity.locale; } + private static getChannel(step): string { + return !isNaN(step.context.activity.from.id) ? 'whatsapp' : step.context.activity.channelId; + } + public async sendFile(min: GBMinInstance, step: GBDialogStep, mobile: string, url: string, caption: string): Promise { + if (step !== null) { mobile = step.context.activity.from.id; - if (step.context.activity.channelId === 'whatsapp') { + if (GBConversationalService.getChannel(step) === 'whatsapp') { + GBLog.info(`Sending file ${url} to ${step.context.activity.from.id}...`) const filename = url.substring(url.lastIndexOf('/') + 1); await min.whatsAppDirectLine.sendFileToDevice(mobile, url, filename, caption); } else { + GBLog.info(`Sending ${url} as file attachment not available in this channel ${step.context.activity.from.id}...`); await min.conversationalService.sendText(min, step, url); } } @@ -525,12 +531,12 @@ export class GBConversationalService { language: string ): Promise { - if (process.env.TRANSLATOR_DISABLED === "true"){ - return text; + if (process.env.TRANSLATOR_DISABLED === "true") { + return text; } - if (text.length > 5000){ - text = text.substr(0,4999); + if (text.length > 5000) { + text = text.substr(0, 4999); GBLog.warn(`Text that bot will translate will be truncated due to MSFT service limitations.`); } @@ -565,7 +571,7 @@ export class GBConversationalService { } } - public async prompt(min: GBMinInstance, step: GBDialogStep, text: string) { + public async prompt(min: GBMinInstance, step: GBDialogStep, text: string) { let sec = new SecService(); const member = step.context.activity.from; @@ -580,8 +586,8 @@ export class GBConversationalService { return await step.prompt("textPrompt", text ? text : {}); } - - public async sendText(min, step, text) { + + public async sendText(min, step, text) { let sec = new SecService(); const member = step.context.activity.from; @@ -591,8 +597,8 @@ export class GBConversationalService { min.instance.translatorKey, min.instance.translatorEndpoint, text, - user.locale? user.locale: 'pt' - ); + user.locale ? user.locale : 'pt' + ); await step.context.sendActivity(text); } diff --git a/packages/core.gbapp/services/GBMinService.ts b/packages/core.gbapp/services/GBMinService.ts index 859f6595..7df670e1 100644 --- a/packages/core.gbapp/services/GBMinService.ts +++ b/packages/core.gbapp/services/GBMinService.ts @@ -571,9 +571,7 @@ export class GBMinService { } GBLog.info( - `User>: ${context.activity.text} (${context.activity.type}, ${context.activity.name}, ${ - context.activity.channelId - }, {context.activity.value})` + `User>: text:${context.activity.text} (type: ${context.activity.type}, name: ${context.activity.name}, channelId: ${context.activity.channelId}, value: ${context.activity.value})` ); if (context.activity.type === 'conversationUpdate' && context.activity.membersAdded.length > 0) { const member = context.activity.membersAdded[0];