From e7a7fcedbf6a3e495e7df68f8d4408c24b3fe961 Mon Sep 17 00:00:00 2001 From: Rodrigo Rodriguez Date: Fri, 14 Sep 2018 14:29:44 -0300 Subject: [PATCH] Testing and rebase to en-us as default language. --- deploy/admin.gbapp/dialogs/AdminDialog.ts | 2 - .../services/GBConversationalService.ts | 26 +++++- deploy/core.gbapp/services/GBMinService.ts | 2 +- .../src/players/GBMarkdownPlayer.js | 6 +- deploy/kb.gbapp/dialogs/AskDialog.ts | 21 +---- deploy/kb.gbapp/dialogs/MenuDialog.ts | 92 +++++++++---------- 6 files changed, 76 insertions(+), 73 deletions(-) diff --git a/deploy/admin.gbapp/dialogs/AdminDialog.ts b/deploy/admin.gbapp/dialogs/AdminDialog.ts index ef89f6d8..50890d3a 100644 --- a/deploy/admin.gbapp/dialogs/AdminDialog.ts +++ b/deploy/admin.gbapp/dialogs/AdminDialog.ts @@ -41,8 +41,6 @@ import { GBImporter } from '../../core.gbapp/services/GBImporter' import { GBConfigService } from '../../core.gbapp/services/GBConfigService' import { KBService } from './../../kb.gbapp/services/KBService' import { BotAdapter } from "botbuilder" -import {messages} from "./Strings" -import { reject } from "async" /** * Dialogs for administration tasks. diff --git a/deploy/core.gbapp/services/GBConversationalService.ts b/deploy/core.gbapp/services/GBConversationalService.ts index a97e23a3..1bc38579 100644 --- a/deploy/core.gbapp/services/GBConversationalService.ts +++ b/deploy/core.gbapp/services/GBConversationalService.ts @@ -39,6 +39,8 @@ import { IGBConversationalService } from "botlib"; import { GBMinInstance } from "botlib"; import { LuisRecognizer } from "botbuilder-ai"; import { MessageFactory } from "botbuilder"; +import { Messages } from "../strings"; +import { AzureText } from "pragmatismo-io-framework"; export interface LanguagePickerSettings { defaultLocale?: string; @@ -65,7 +67,6 @@ export class GBConversationalService implements IGBConversationalService { } async routeNLP(dc: any, min: GBMinInstance, text: string): Promise { - // Invokes LUIS. const model = new LuisRecognizer({ @@ -99,4 +100,27 @@ export class GBConversationalService implements IGBConversationalService { return Promise.resolve(false); } } + + async checkLanguage(dc, min, text) { + let locale = await AzureText.getLocale( + min.instance.textAnalyticsKey, + min.instance.textAnalyticsServerUrl, + text + ); + if (locale != dc.context.activity.locale.split("-")[0]) { + switch (locale) { + case "pt": + dc.context.activity.locale = "pt-BR"; + await dc.context.sendActivity(Messages[locale].changing_language); + break; + case "en": + dc.context.activity.locale = "en-US"; + await dc.context.sendActivity(Messages[locale].changing_language); + break; + default: + await dc.context.sendActivity(`Unknown language: ${locale}`); + break; + } + } + } } diff --git a/deploy/core.gbapp/services/GBMinService.ts b/deploy/core.gbapp/services/GBMinService.ts index 8b691ed3..2ddfa923 100644 --- a/deploy/core.gbapp/services/GBMinService.ts +++ b/deploy/core.gbapp/services/GBMinService.ts @@ -272,7 +272,7 @@ export class GBMinService { return adapter.processActivity(req, res, async context => { const state = conversationState.get(context) const dc = min.dialogs.createContext(context, state) - dc.context.activity.locale = "pt-BR" + dc.context.activity.locale = "en-US" const user = min.userState.get(dc.context) if (!user.loaded) { diff --git a/deploy/default.gbui/src/players/GBMarkdownPlayer.js b/deploy/default.gbui/src/players/GBMarkdownPlayer.js index cb455698..556440ad 100644 --- a/deploy/default.gbui/src/players/GBMarkdownPlayer.js +++ b/deploy/default.gbui/src/players/GBMarkdownPlayer.js @@ -80,14 +80,14 @@ class GBMarkdownPlayer extends Component { var quality =
- (this.quality = i)}>A resposta atende? + (this.quality = i)}>Is the answer OK?     | 
; diff --git a/deploy/kb.gbapp/dialogs/AskDialog.ts b/deploy/kb.gbapp/dialogs/AskDialog.ts index ba0419b4..8010e384 100644 --- a/deploy/kb.gbapp/dialogs/AskDialog.ts +++ b/deploy/kb.gbapp/dialogs/AskDialog.ts @@ -69,26 +69,7 @@ export class AskDialog extends IGBDialog { throw new Error(`/answer being called with no args.query text.`); } - let locale = await AzureText.getLocale( - min.instance.textAnalyticsKey, - min.instance.textAnalyticsServerUrl, - text - ); - if (locale != dc.context.activity.locale.split("-")[0]) { - switch (locale) { - case "pt": - dc.context.activity.locale = "pt-BR"; - await dc.context.sendActivity(Messages[locale].changing_language); - break; - case "en": - dc.context.activity.locale = "en-US"; - await dc.context.sendActivity(Messages[locale].changing_language); - break; - default: - await dc.context.sendActivity(`Unknown language: ${locale}`); - break; - } - } + let locale = dc.context.activity.locale // Stops any content on projector. diff --git a/deploy/kb.gbapp/dialogs/MenuDialog.ts b/deploy/kb.gbapp/dialogs/MenuDialog.ts index ba0a315e..d978c995 100644 --- a/deploy/kb.gbapp/dialogs/MenuDialog.ts +++ b/deploy/kb.gbapp/dialogs/MenuDialog.ts @@ -30,17 +30,17 @@ | | \*****************************************************************************/ -"use strict"; +"use strict" -const UrlJoin = require("url-join"); +const UrlJoin = require("url-join") -import { BotAdapter, CardFactory, MessageFactory } from "botbuilder"; -import { IGBDialog } from "botlib"; -import { GBMinInstance } from "botlib"; -import { GuaribasSubject } from "../models"; -import { KBService } from "../services/KBService"; -import { Messages } from "../strings"; -import { AzureText } from "pragmatismo-io-framework"; +import { BotAdapter, CardFactory, MessageFactory } from "botbuilder" +import { IGBDialog } from "botlib" +import { GBMinInstance } from "botlib" +import { GuaribasSubject } from "../models" +import { KBService } from "../services/KBService" +import { Messages } from "../strings" +import { AzureText } from "pragmatismo-io-framework" export class MenuDialog extends IGBDialog { /** @@ -50,30 +50,30 @@ export class MenuDialog extends IGBDialog { * @param min The minimal bot instance data. */ static setup(bot: BotAdapter, min: GBMinInstance) { - var service = new KBService(min.core.sequelize); + var service = new KBService(min.core.sequelize) min.dialogs.add("/menu", [ async (dc, args) => { - const locale = dc.context.activity.locale; - var rootSubjectId = null; + const locale = dc.context.activity.locale + var rootSubjectId = null if (args && args.data) { - var subject = args.data; + var subject = args.data // If there is a shortcut specified as subject destination, go there. if (subject.to) { - let dialog = subject.to.split(":")[1]; - await dc.replace("/" + dialog); - await dc.end(); - return; + let dialog = subject.to.split(":")[1] + await dc.replace("/" + dialog) + await dc.end() + return } // Adds to bot a perception of a new subject. - const user = min.userState.get(dc.context); - user.subjects.push(subject); - rootSubjectId = subject.subjectId; + const user = min.userState.get(dc.context) + user.subjects.push(subject) + rootSubjectId = subject.subjectId // Whenever a subject is selected, shows a faq about it. @@ -81,32 +81,32 @@ export class MenuDialog extends IGBDialog { let data = await service.getFaqBySubjectArray( "menu", user.subjects - ); + ) await min.conversationalService.sendEvent(dc, "play", { playerType: "bullet", data: data.slice(0, 6) - }); + }) } } else { - const user = min.userState.get(dc.context); - user.subjects = []; + const user = min.userState.get(dc.context) + user.subjects = [] - await dc.context.sendActivity(Messages[locale].here_is_subjects); // TODO: Handle rnd. - user.isAsking = false; + await dc.context.sendActivity(Messages[locale].here_is_subjects) // TODO: Handle rnd. + user.isAsking = false } - const msg = MessageFactory.text(""); - var attachments = []; + const msg = MessageFactory.text("") + var attachments = [] let data = await service.getSubjectItems( min.instance.instanceId, rootSubjectId - ); + ) - msg.attachmentLayout = "carousel"; + msg.attachmentLayout = "carousel" data.forEach(function(item: GuaribasSubject) { - var subject = item; + var subject = item var card = CardFactory.heroCard( subject.title, CardFactory.images([ @@ -128,40 +128,40 @@ export class MenuDialog extends IGBDialog { }) } ]) - ); + ) - attachments.push(card); - }); + attachments.push(card) + }) if (attachments.length == 0) { - const user = min.userState.get(dc.context); + const user = min.userState.get(dc.context) if (user.subjects && user.subjects.length > 0) { await dc.context.sendActivity( Messages[locale].lets_search( KBService.getFormattedSubjectItems(user.subjects) ) - ); + ) } - await dc.replace("/ask", {}); + await dc.replace("/ask", {}) } else { - msg.attachments = attachments; - await dc.context.sendActivity(msg); + msg.attachments = attachments + await dc.context.sendActivity(msg) } - const user = min.userState.get(dc.context); - user.isAsking = true; + const user = min.userState.get(dc.context) + user.isAsking = true }, async (dc, value) => { - var text = value; - const locale = dc.context.activity.locale; + var text = value + const locale = dc.context.activity.locale if (AzureText.isIntentNo(locale, text)) { - await dc.replace("/feedback"); + await dc.replace("/feedback") } else { - await dc.replace("/ask"); + await dc.replace("/ask") } } - ]); + ]) } } \ No newline at end of file