fix(core.gbapp): Better logging and WhatsApp channel detection fix.
This commit is contained in:
parent
077d70e418
commit
821842c317
4 changed files with 35 additions and 31 deletions
30
package-lock.json
generated
30
package-lock.json
generated
|
@ -2925,9 +2925,9 @@
|
||||||
"integrity": "sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg=="
|
"integrity": "sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg=="
|
||||||
},
|
},
|
||||||
"bn.js": {
|
"bn.js": {
|
||||||
"version": "4.11.8",
|
"version": "4.11.9",
|
||||||
"resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.8.tgz",
|
"resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.9.tgz",
|
||||||
"integrity": "sha512-ItfYfPLkWHUjckQCk8xC+LwxgK8NYcXywGigJgSwOP8Y2iyWT4f2vsZnoOXTTbo+o5yXmIUJ4gn5538SO5S3gA=="
|
"integrity": "sha512-E6QoYqCKZfgatHTdHzs1RRKP7ip4vvm+EyRUeE2RF0NblwVvb0p6jSVeNTOFxPn26QXN2o6SMfNxKp6kU8zQaw=="
|
||||||
},
|
},
|
||||||
"body-parser": {
|
"body-parser": {
|
||||||
"version": "1.19.0",
|
"version": "1.19.0",
|
||||||
|
@ -3141,9 +3141,9 @@
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/node": {
|
"@types/node": {
|
||||||
"version": "10.17.21",
|
"version": "10.17.24",
|
||||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-10.17.21.tgz",
|
"resolved": "https://registry.npmjs.org/@types/node/-/node-10.17.24.tgz",
|
||||||
"integrity": "sha512-PQKsydPxYxF1DsAFWmunaxd3sOi3iMt6Zmx/tgaagHYmwJ/9cRH91hQkeJZaUGWbvn0K5HlSVEXkn5U/llWPpQ=="
|
"integrity": "sha512-5SCfvCxV74kzR3uWgTYiGxrd69TbT1I6+cMx1A5kEly/IVveJBimtAMlXiEyVFn5DvUFewQWxOOiJhlxeQwxgA=="
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -3273,9 +3273,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"botlib": {
|
"botlib": {
|
||||||
"version": "1.5.2",
|
"version": "1.5.4",
|
||||||
"resolved": "https://registry.npmjs.org/botlib/-/botlib-1.5.2.tgz",
|
"resolved": "https://registry.npmjs.org/botlib/-/botlib-1.5.4.tgz",
|
||||||
"integrity": "sha512-drDSpfwN8dQe9X0+YkOFEP0wOfzvbumga3UlR0kB/4Zkt22jPlDXdCmS6e83hV9/93XMibwCgdKpF6WnKeZ8Zg==",
|
"integrity": "sha512-m3VIwB1c/ZqRvkZ/Ip3zJhFDAK1kS8hSNS+J7JOJe9N2L1ajZU0QDV5ziK5KlWy5CpBx5TEMB0gJ3+SMhX+aCQ==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"async": "3.1.0",
|
"async": "3.1.0",
|
||||||
"botbuilder": "4.7.0",
|
"botbuilder": "4.7.0",
|
||||||
|
@ -9210,9 +9210,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"microsoft-cognitiveservices-speech-sdk": {
|
"microsoft-cognitiveservices-speech-sdk": {
|
||||||
"version": "1.11.0",
|
"version": "1.12.0",
|
||||||
"resolved": "https://registry.npmjs.org/microsoft-cognitiveservices-speech-sdk/-/microsoft-cognitiveservices-speech-sdk-1.11.0.tgz",
|
"resolved": "https://registry.npmjs.org/microsoft-cognitiveservices-speech-sdk/-/microsoft-cognitiveservices-speech-sdk-1.12.0.tgz",
|
||||||
"integrity": "sha512-03nPTggWCjkvVvJ6Y795UUKkFhdVn32yYqIpI/vEvAQAssffbcP5syU8JfUzN9TF4UfYvUFKlnyNgGj7y1DyAw==",
|
"integrity": "sha512-1+67ejHPbz8VOBxFdh3Wq//K8mfKHFA3C1mLN779hRq0NDUfnkiGt8MApq9ry5gMLK3JX2zkt4SASI8EATyn9Q==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"asn1.js-rfc2560": "^5.0.0",
|
"asn1.js-rfc2560": "^5.0.0",
|
||||||
"asn1.js-rfc5280": "^3.0.0",
|
"asn1.js-rfc5280": "^3.0.0",
|
||||||
|
@ -19086,9 +19086,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"ws": {
|
"ws": {
|
||||||
"version": "7.2.3",
|
"version": "7.3.0",
|
||||||
"resolved": "https://registry.npmjs.org/ws/-/ws-7.2.3.tgz",
|
"resolved": "https://registry.npmjs.org/ws/-/ws-7.3.0.tgz",
|
||||||
"integrity": "sha512-HTDl9G9hbkNDk98naoR/cHDws7+EyYMOdL1BmjsZXRUjf7d+MficC4B7HLUPlSiho0vg+CWKrGIt/VJBd1xunQ=="
|
"integrity": "sha512-iFtXzngZVXPGgpTlP1rBqsUK82p9tKqsWRPg5L56egiljujJT3vGAYnHANvFxBieXrTFavhzhxW52jnaWV+w2w=="
|
||||||
},
|
},
|
||||||
"x256": {
|
"x256": {
|
||||||
"version": "0.0.2",
|
"version": "0.0.2",
|
||||||
|
|
|
@ -76,7 +76,7 @@
|
||||||
"google-libphonenumber": "3.2.8",
|
"google-libphonenumber": "3.2.8",
|
||||||
"js-beautify": "1.10.2",
|
"js-beautify": "1.10.2",
|
||||||
"marked": "0.8.0",
|
"marked": "0.8.0",
|
||||||
"microsoft-cognitiveservices-speech-sdk": "1.11.0",
|
"microsoft-cognitiveservices-speech-sdk": "1.12.0",
|
||||||
"ms-rest-azure": "3.0.0",
|
"ms-rest-azure": "3.0.0",
|
||||||
"nexmo": "2.5.2",
|
"nexmo": "2.5.2",
|
||||||
"ngrok": "3.2.7",
|
"ngrok": "3.2.7",
|
||||||
|
|
|
@ -39,8 +39,6 @@
|
||||||
import { MessageFactory, RecognizerResult } from 'botbuilder';
|
import { MessageFactory, RecognizerResult } from 'botbuilder';
|
||||||
import { LuisRecognizer } from 'botbuilder-ai';
|
import { LuisRecognizer } from 'botbuilder-ai';
|
||||||
import { GBDialogStep, GBLog, GBMinInstance, IGBCoreService } from 'botlib';
|
import { GBDialogStep, GBLog, GBMinInstance, IGBCoreService } from 'botlib';
|
||||||
import { AzureText } from 'pragmatismo-io-framework';
|
|
||||||
import { Messages } from '../strings';
|
|
||||||
import { GBServer } from '../../../src/app';
|
import { GBServer } from '../../../src/app';
|
||||||
import { Readable } from 'stream'
|
import { Readable } from 'stream'
|
||||||
import { GBAdminService } from '../../admin.gbapp/services/GBAdminService';
|
import { GBAdminService } from '../../admin.gbapp/services/GBAdminService';
|
||||||
|
@ -54,6 +52,7 @@ const { exec } = require('child_process')
|
||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
const prism = require('prism-media')
|
const prism = require('prism-media')
|
||||||
const sdk = require("microsoft-cognitiveservices-speech-sdk");
|
const sdk = require("microsoft-cognitiveservices-speech-sdk");
|
||||||
|
sdk.Recognizer.enableTelemetry(false);
|
||||||
const uuidv4 = require('uuid/v4');
|
const uuidv4 = require('uuid/v4');
|
||||||
const request = require('request-promise-native');
|
const request = require('request-promise-native');
|
||||||
|
|
||||||
|
@ -90,15 +89,22 @@ export class GBConversationalService {
|
||||||
public getCurrentLanguage(step: GBDialogStep) {
|
public getCurrentLanguage(step: GBDialogStep) {
|
||||||
return step.context.activity.locale;
|
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<any> {
|
public async sendFile(min: GBMinInstance, step: GBDialogStep, mobile: string, url: string, caption: string): Promise<any> {
|
||||||
|
|
||||||
if (step !== null) {
|
if (step !== null) {
|
||||||
mobile = step.context.activity.from.id;
|
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);
|
const filename = url.substring(url.lastIndexOf('/') + 1);
|
||||||
await min.whatsAppDirectLine.sendFileToDevice(mobile, url, filename, caption);
|
await min.whatsAppDirectLine.sendFileToDevice(mobile, url, filename, caption);
|
||||||
}
|
}
|
||||||
else {
|
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);
|
await min.conversationalService.sendText(min, step, url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -525,12 +531,12 @@ export class GBConversationalService {
|
||||||
language: string
|
language: string
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
|
|
||||||
if (process.env.TRANSLATOR_DISABLED === "true"){
|
if (process.env.TRANSLATOR_DISABLED === "true") {
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (text.length > 5000){
|
if (text.length > 5000) {
|
||||||
text = text.substr(0,4999);
|
text = text.substr(0, 4999);
|
||||||
GBLog.warn(`Text that bot will translate will be truncated due to MSFT service limitations.`);
|
GBLog.warn(`Text that bot will translate will be truncated due to MSFT service limitations.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -591,7 +597,7 @@ export class GBConversationalService {
|
||||||
min.instance.translatorKey,
|
min.instance.translatorKey,
|
||||||
min.instance.translatorEndpoint,
|
min.instance.translatorEndpoint,
|
||||||
text,
|
text,
|
||||||
user.locale? user.locale: 'pt'
|
user.locale ? user.locale : 'pt'
|
||||||
);
|
);
|
||||||
|
|
||||||
await step.context.sendActivity(text);
|
await step.context.sendActivity(text);
|
||||||
|
|
|
@ -571,9 +571,7 @@ export class GBMinService {
|
||||||
}
|
}
|
||||||
|
|
||||||
GBLog.info(
|
GBLog.info(
|
||||||
`User>: ${context.activity.text} (${context.activity.type}, ${context.activity.name}, ${
|
`User>: text:${context.activity.text} (type: ${context.activity.type}, name: ${context.activity.name}, channelId: ${context.activity.channelId}, value: ${context.activity.value})`
|
||||||
context.activity.channelId
|
|
||||||
}, {context.activity.value})`
|
|
||||||
);
|
);
|
||||||
if (context.activity.type === 'conversationUpdate' && context.activity.membersAdded.length > 0) {
|
if (context.activity.type === 'conversationUpdate' && context.activity.membersAdded.length > 0) {
|
||||||
const member = context.activity.membersAdded[0];
|
const member = context.activity.membersAdded[0];
|
||||||
|
|
Loading…
Add table
Reference in a new issue