Skip to content

Commit

Permalink
fix(core.gbapp): Better logging and WhatsApp channel detection fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigorodriguez committed May 25, 2020
1 parent 077d70e commit 821842c
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 31 deletions.
30 changes: 15 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
30 changes: 18 additions & 12 deletions packages/core.gbapp/services/GBConversationalService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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');

Expand Down Expand Up @@ -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<any> {

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);
}
}
Expand Down Expand Up @@ -525,12 +531,12 @@ export class GBConversationalService {
language: string
): Promise<string> {

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.`);
}

Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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);
}
Expand Down
4 changes: 1 addition & 3 deletions packages/core.gbapp/services/GBMinService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down

0 comments on commit 821842c

Please sign in to comment.