Testing and rebase to en-us as default language.
This commit is contained in:
parent
7a33f6942e
commit
e7a7fcedbf
6 changed files with 76 additions and 73 deletions
|
@ -41,8 +41,6 @@ import { GBImporter } from '../../core.gbapp/services/GBImporter'
|
||||||
import { GBConfigService } from '../../core.gbapp/services/GBConfigService'
|
import { GBConfigService } from '../../core.gbapp/services/GBConfigService'
|
||||||
import { KBService } from './../../kb.gbapp/services/KBService'
|
import { KBService } from './../../kb.gbapp/services/KBService'
|
||||||
import { BotAdapter } from "botbuilder"
|
import { BotAdapter } from "botbuilder"
|
||||||
import {messages} from "./Strings"
|
|
||||||
import { reject } from "async"
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dialogs for administration tasks.
|
* Dialogs for administration tasks.
|
||||||
|
|
|
@ -39,6 +39,8 @@ import { IGBConversationalService } from "botlib";
|
||||||
import { GBMinInstance } from "botlib";
|
import { GBMinInstance } from "botlib";
|
||||||
import { LuisRecognizer } from "botbuilder-ai";
|
import { LuisRecognizer } from "botbuilder-ai";
|
||||||
import { MessageFactory } from "botbuilder";
|
import { MessageFactory } from "botbuilder";
|
||||||
|
import { Messages } from "../strings";
|
||||||
|
import { AzureText } from "pragmatismo-io-framework";
|
||||||
|
|
||||||
export interface LanguagePickerSettings {
|
export interface LanguagePickerSettings {
|
||||||
defaultLocale?: string;
|
defaultLocale?: string;
|
||||||
|
@ -65,7 +67,6 @@ export class GBConversationalService implements IGBConversationalService {
|
||||||
}
|
}
|
||||||
|
|
||||||
async routeNLP(dc: any, min: GBMinInstance, text: string): Promise<boolean> {
|
async routeNLP(dc: any, min: GBMinInstance, text: string): Promise<boolean> {
|
||||||
|
|
||||||
// Invokes LUIS.
|
// Invokes LUIS.
|
||||||
|
|
||||||
const model = new LuisRecognizer({
|
const model = new LuisRecognizer({
|
||||||
|
@ -99,4 +100,27 @@ export class GBConversationalService implements IGBConversationalService {
|
||||||
return Promise.resolve(false);
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -272,7 +272,7 @@ export class GBMinService {
|
||||||
return adapter.processActivity(req, res, async context => {
|
return adapter.processActivity(req, res, async context => {
|
||||||
const state = conversationState.get(context)
|
const state = conversationState.get(context)
|
||||||
const dc = min.dialogs.createContext(context, state)
|
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)
|
const user = min.userState.get(dc.context)
|
||||||
|
|
||||||
if (!user.loaded) {
|
if (!user.loaded) {
|
||||||
|
|
|
@ -80,14 +80,14 @@ class GBMarkdownPlayer extends Component {
|
||||||
|
|
||||||
var quality =
|
var quality =
|
||||||
<div className="gb-markdown-player-quality">
|
<div className="gb-markdown-player-quality">
|
||||||
<span ref={i => (this.quality = i)}>A resposta atende?</span>
|
<span ref={i => (this.quality = i)}>Is the answer OK?</span>
|
||||||
|
|
||||||
<button className="gb-quality-button-yes" onClick={() => this.clickYes()} ref={i => (this.Yes = i)}>
|
<button className="gb-quality-button-yes" onClick={() => this.clickYes()} ref={i => (this.Yes = i)}>
|
||||||
Sim
|
Yes
|
||||||
</button>
|
</button>
|
||||||
|
|
|
|
||||||
<button className="gb-quality-button-no" onClick={() => this.clickNo()} ref={i => (this.No = i)}>
|
<button className="gb-quality-button-no" onClick={() => this.clickNo()} ref={i => (this.No = i)}>
|
||||||
Não
|
No
|
||||||
</button>
|
</button>
|
||||||
</div>;
|
</div>;
|
||||||
|
|
||||||
|
|
|
@ -69,26 +69,7 @@ export class AskDialog extends IGBDialog {
|
||||||
throw new Error(`/answer being called with no args.query text.`);
|
throw new Error(`/answer being called with no args.query text.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
let locale = await AzureText.getLocale(
|
let locale = dc.context.activity.locale
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Stops any content on projector.
|
// Stops any content on projector.
|
||||||
|
|
||||||
|
|
|
@ -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 { BotAdapter, CardFactory, MessageFactory } from "botbuilder"
|
||||||
import { IGBDialog } from "botlib";
|
import { IGBDialog } from "botlib"
|
||||||
import { GBMinInstance } from "botlib";
|
import { GBMinInstance } from "botlib"
|
||||||
import { GuaribasSubject } from "../models";
|
import { GuaribasSubject } from "../models"
|
||||||
import { KBService } from "../services/KBService";
|
import { KBService } from "../services/KBService"
|
||||||
import { Messages } from "../strings";
|
import { Messages } from "../strings"
|
||||||
import { AzureText } from "pragmatismo-io-framework";
|
import { AzureText } from "pragmatismo-io-framework"
|
||||||
|
|
||||||
export class MenuDialog extends IGBDialog {
|
export class MenuDialog extends IGBDialog {
|
||||||
/**
|
/**
|
||||||
|
@ -50,30 +50,30 @@ export class MenuDialog extends IGBDialog {
|
||||||
* @param min The minimal bot instance data.
|
* @param min The minimal bot instance data.
|
||||||
*/
|
*/
|
||||||
static setup(bot: BotAdapter, min: GBMinInstance) {
|
static setup(bot: BotAdapter, min: GBMinInstance) {
|
||||||
var service = new KBService(min.core.sequelize);
|
var service = new KBService(min.core.sequelize)
|
||||||
|
|
||||||
min.dialogs.add("/menu", [
|
min.dialogs.add("/menu", [
|
||||||
async (dc, args) => {
|
async (dc, args) => {
|
||||||
const locale = dc.context.activity.locale;
|
const locale = dc.context.activity.locale
|
||||||
var rootSubjectId = null;
|
var rootSubjectId = null
|
||||||
|
|
||||||
if (args && args.data) {
|
if (args && args.data) {
|
||||||
var subject = args.data;
|
var subject = args.data
|
||||||
|
|
||||||
// If there is a shortcut specified as subject destination, go there.
|
// If there is a shortcut specified as subject destination, go there.
|
||||||
|
|
||||||
if (subject.to) {
|
if (subject.to) {
|
||||||
let dialog = subject.to.split(":")[1];
|
let dialog = subject.to.split(":")[1]
|
||||||
await dc.replace("/" + dialog);
|
await dc.replace("/" + dialog)
|
||||||
await dc.end();
|
await dc.end()
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adds to bot a perception of a new subject.
|
// Adds to bot a perception of a new subject.
|
||||||
|
|
||||||
const user = min.userState.get(dc.context);
|
const user = min.userState.get(dc.context)
|
||||||
user.subjects.push(subject);
|
user.subjects.push(subject)
|
||||||
rootSubjectId = subject.subjectId;
|
rootSubjectId = subject.subjectId
|
||||||
|
|
||||||
// Whenever a subject is selected, shows a faq about it.
|
// Whenever a subject is selected, shows a faq about it.
|
||||||
|
|
||||||
|
@ -81,32 +81,32 @@ export class MenuDialog extends IGBDialog {
|
||||||
let data = await service.getFaqBySubjectArray(
|
let data = await service.getFaqBySubjectArray(
|
||||||
"menu",
|
"menu",
|
||||||
user.subjects
|
user.subjects
|
||||||
);
|
)
|
||||||
await min.conversationalService.sendEvent(dc, "play", {
|
await min.conversationalService.sendEvent(dc, "play", {
|
||||||
playerType: "bullet",
|
playerType: "bullet",
|
||||||
data: data.slice(0, 6)
|
data: data.slice(0, 6)
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const user = min.userState.get(dc.context);
|
const user = min.userState.get(dc.context)
|
||||||
user.subjects = [];
|
user.subjects = []
|
||||||
|
|
||||||
await dc.context.sendActivity(Messages[locale].here_is_subjects); // TODO: Handle rnd.
|
await dc.context.sendActivity(Messages[locale].here_is_subjects) // TODO: Handle rnd.
|
||||||
user.isAsking = false;
|
user.isAsking = false
|
||||||
}
|
}
|
||||||
|
|
||||||
const msg = MessageFactory.text("");
|
const msg = MessageFactory.text("")
|
||||||
var attachments = [];
|
var attachments = []
|
||||||
|
|
||||||
let data = await service.getSubjectItems(
|
let data = await service.getSubjectItems(
|
||||||
min.instance.instanceId,
|
min.instance.instanceId,
|
||||||
rootSubjectId
|
rootSubjectId
|
||||||
);
|
)
|
||||||
|
|
||||||
msg.attachmentLayout = "carousel";
|
msg.attachmentLayout = "carousel"
|
||||||
|
|
||||||
data.forEach(function(item: GuaribasSubject) {
|
data.forEach(function(item: GuaribasSubject) {
|
||||||
var subject = item;
|
var subject = item
|
||||||
var card = CardFactory.heroCard(
|
var card = CardFactory.heroCard(
|
||||||
subject.title,
|
subject.title,
|
||||||
CardFactory.images([
|
CardFactory.images([
|
||||||
|
@ -128,40 +128,40 @@ export class MenuDialog extends IGBDialog {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
);
|
)
|
||||||
|
|
||||||
attachments.push(card);
|
attachments.push(card)
|
||||||
});
|
})
|
||||||
|
|
||||||
if (attachments.length == 0) {
|
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) {
|
if (user.subjects && user.subjects.length > 0) {
|
||||||
await dc.context.sendActivity(
|
await dc.context.sendActivity(
|
||||||
Messages[locale].lets_search(
|
Messages[locale].lets_search(
|
||||||
KBService.getFormattedSubjectItems(user.subjects)
|
KBService.getFormattedSubjectItems(user.subjects)
|
||||||
)
|
)
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
await dc.replace("/ask", {});
|
await dc.replace("/ask", {})
|
||||||
} else {
|
} else {
|
||||||
msg.attachments = attachments;
|
msg.attachments = attachments
|
||||||
await dc.context.sendActivity(msg);
|
await dc.context.sendActivity(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
const user = min.userState.get(dc.context);
|
const user = min.userState.get(dc.context)
|
||||||
user.isAsking = true;
|
user.isAsking = true
|
||||||
},
|
},
|
||||||
async (dc, value) => {
|
async (dc, value) => {
|
||||||
var text = value;
|
var text = value
|
||||||
const locale = dc.context.activity.locale;
|
const locale = dc.context.activity.locale
|
||||||
if (AzureText.isIntentNo(locale, text)) {
|
if (AzureText.isIntentNo(locale, text)) {
|
||||||
await dc.replace("/feedback");
|
await dc.replace("/feedback")
|
||||||
} else {
|
} else {
|
||||||
await dc.replace("/ask");
|
await dc.replace("/ask")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]);
|
])
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue