new(core.gbapp): New bot to any language according to the user language.
This commit is contained in:
parent
f0bb5978d4
commit
d0fecf1a6f
14 changed files with 160 additions and 76 deletions
|
@ -46,6 +46,7 @@ import { GBImporter } from '../../core.gbapp/services/GBImporterService';
|
|||
import { Messages } from '../strings';
|
||||
import { GBAdminService } from '../services/GBAdminService';
|
||||
import { CollectionUtil } from 'pragmatismo-io-framework';
|
||||
import { GBConversationalService } from '../../core.gbapp/services/GBConversationalService';
|
||||
|
||||
|
||||
/**
|
||||
|
@ -74,18 +75,18 @@ export class AdminDialog extends IGBDialog {
|
|||
const locale = step.context.activity.locale;
|
||||
const prompt = Messages[locale].authenticate;
|
||||
|
||||
return await step.prompt('textPrompt', prompt);
|
||||
return await min.conversationalService.prompt (min, step, prompt);
|
||||
},
|
||||
async step => {
|
||||
const locale = step.context.activity.locale;
|
||||
const sensitive = step.result;
|
||||
|
||||
if (sensitive === min.instance.adminPass) {
|
||||
await step.context.sendActivity(Messages[locale].welcome);
|
||||
await min.conversationalService.sendText(min, step, Messages[locale].welcome);
|
||||
|
||||
return await step.prompt('textPrompt', Messages[locale].which_task);
|
||||
return await min.conversationalService.prompt (min, step, Messages[locale].which_task);
|
||||
} else {
|
||||
await step.context.sendActivity(Messages[locale].wrong_password);
|
||||
await min.conversationalService.sendText(min, step, Messages[locale].wrong_password);
|
||||
|
||||
return await step.endDialog();
|
||||
}
|
||||
|
@ -96,7 +97,7 @@ export class AdminDialog extends IGBDialog {
|
|||
const text: string = step.result;
|
||||
const cmdName = text.split(' ')[0];
|
||||
|
||||
await step.context.sendActivity(Messages[locale].working(cmdName));
|
||||
await min.conversationalService.sendText(min, step, Messages[locale].working(cmdName));
|
||||
let unknownCommand = false;
|
||||
|
||||
try {
|
||||
|
@ -109,18 +110,18 @@ export class AdminDialog extends IGBDialog {
|
|||
|
||||
return await step.replaceDialog('/admin', { firstRun: false });
|
||||
} else if (cmdName === 'redeployPackage' || cmdName === 'rp') {
|
||||
await step.context.sendActivity('The package is being *unloaded*...');
|
||||
await min.conversationalService.sendText(min, step, 'The package is being *unloaded*...');
|
||||
await GBAdminService.undeployPackageCommand(text, min);
|
||||
await step.context.sendActivity('Now, *deploying* package...');
|
||||
await min.conversationalService.sendText(min, step, 'Now, *deploying* package...');
|
||||
await GBAdminService.deployPackageCommand(min, text, deployer);
|
||||
await step.context.sendActivity('Package deployed. Just need to rebuild the index... Doing it right now.');
|
||||
await min.conversationalService.sendText(min, step, 'Package deployed. Just need to rebuild the index... Doing it right now.');
|
||||
await GBAdminService.rebuildIndexPackageCommand(min, deployer);
|
||||
await step.context.sendActivity('Finished importing of that .gbkb package. Thanks.');
|
||||
await min.conversationalService.sendText(min, step, 'Finished importing of that .gbkb package. Thanks.');
|
||||
return await step.replaceDialog('/admin', { firstRun: false });
|
||||
} else if (cmdName === 'undeployPackage' || cmdName === 'up') {
|
||||
await step.context.sendActivity('The package is being *undeployed*...');
|
||||
await min.conversationalService.sendText(min, step, 'The package is being *undeployed*...');
|
||||
await GBAdminService.undeployPackageCommand(text, min);
|
||||
await step.context.sendActivity('Package *undeployed*.');
|
||||
await min.conversationalService.sendText(min, step, 'Package *undeployed*.');
|
||||
return await step.replaceDialog('/admin', { firstRun: false });
|
||||
} else if (cmdName === 'rebuildIndex' || cmdName === 'ri') {
|
||||
await GBAdminService.rebuildIndexPackageCommand(min, deployer);
|
||||
|
@ -137,13 +138,13 @@ export class AdminDialog extends IGBDialog {
|
|||
}
|
||||
|
||||
if (unknownCommand) {
|
||||
await step.context.sendActivity(Messages[locale].unknown_command);
|
||||
await min.conversationalService.sendText(min, step, Messages[locale].unknown_command);
|
||||
} else {
|
||||
await step.context.sendActivity(Messages[locale].finished_working);
|
||||
await min.conversationalService.sendText(min, step, Messages[locale].finished_working);
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
await step.context.sendActivity(error.message);
|
||||
await min.conversationalService.sendText(min, step, error.message);
|
||||
}
|
||||
await step.replaceDialog('/ask', { isReturning: true });
|
||||
}
|
||||
|
@ -156,14 +157,14 @@ export class AdminDialog extends IGBDialog {
|
|||
async step => {
|
||||
const botId = min.instance.botId;
|
||||
const locale = step.context.activity.locale;
|
||||
await step.context.sendActivity(Messages[locale].working('Publishing'));
|
||||
await min.conversationalService.sendText(min, step, Messages[locale].working('Publishing'));
|
||||
|
||||
step.activeDialog.state.options.args = (step.options as any).args;
|
||||
let args = step.activeDialog.state.options.args.split(' ');
|
||||
let filename = args[0];
|
||||
const packages = [];
|
||||
if (filename === null) {
|
||||
await step.context.sendActivity(`Starting publishing for all bot packages...`);
|
||||
await min.conversationalService.sendText(min, step, `Starting publishing for all bot packages...`);
|
||||
packages.push(`${botId}.gbkb`);
|
||||
packages.push(`${botId}.gbdialog`);
|
||||
packages.push(`${botId}.gbot`);
|
||||
|
@ -171,7 +172,7 @@ export class AdminDialog extends IGBDialog {
|
|||
packages.push(`${botId}.gbapp`);
|
||||
packages.push(`${botId}.gblib`);
|
||||
} else {
|
||||
await step.context.sendActivity(`Starting publishing for ${filename}...`);
|
||||
await min.conversationalService.sendText(min, step, `Starting publishing for ${filename}...`);
|
||||
packages.push(filename);
|
||||
}
|
||||
|
||||
|
@ -188,16 +189,16 @@ export class AdminDialog extends IGBDialog {
|
|||
}
|
||||
await GBAdminService.deployPackageCommand(min, cmd1, deployer);
|
||||
if (packageName.endsWith('.gbkb')) {
|
||||
await step.context.sendActivity('Rebuilding my own index, wait a minute, please...');
|
||||
await min.conversationalService.sendText(min, step, 'Rebuilding my own index, wait a minute, please...');
|
||||
await GBAdminService.rebuildIndexPackageCommand(min, deployer);
|
||||
}
|
||||
await step.context.sendActivity(`Finished publishing ${packageName}.`);
|
||||
await min.conversationalService.sendText(min, step, `Finished publishing ${packageName}.`);
|
||||
});
|
||||
|
||||
return await step.replaceDialog('/ask', { isReturning: true });
|
||||
|
||||
} catch (error) {
|
||||
await step.context.sendActivity(error.message);
|
||||
await min.conversationalService.sendText(min, step, error.message);
|
||||
}
|
||||
await step.replaceDialog('/ask', { isReturning: true });
|
||||
|
||||
|
@ -212,14 +213,14 @@ export class AdminDialog extends IGBDialog {
|
|||
const locale = step.context.activity.locale;
|
||||
const prompt = Messages[locale].enter_authenticator_tenant;
|
||||
|
||||
return await step.prompt('textPrompt', prompt);
|
||||
return await min.conversationalService.prompt (min, step, prompt);
|
||||
},
|
||||
async step => {
|
||||
step.activeDialog.state.authenticatorTenant = step.result;
|
||||
const locale = step.context.activity.locale;
|
||||
const prompt = Messages[locale].enter_authenticator_authority_host_url;
|
||||
|
||||
return await step.prompt('textPrompt', prompt);
|
||||
return await min.conversationalService.prompt (min, step, prompt);
|
||||
},
|
||||
async step => {
|
||||
step.activeDialog.state.authenticatorAuthorityHostUrl = step.result;
|
||||
|
@ -244,7 +245,7 @@ export class AdminDialog extends IGBDialog {
|
|||
'/token'
|
||||
)}&state=${state}&response_mode=query`;
|
||||
|
||||
await step.context.sendActivity(Messages[locale].consent(url));
|
||||
await min.conversationalService.sendText(min, step, Messages[locale].consent(url));
|
||||
|
||||
return await step.replaceDialog('/ask', { isReturning: true });
|
||||
}
|
||||
|
|
|
@ -42,6 +42,7 @@ import { GBMinInstance, IGBDialog } from 'botlib';
|
|||
import { Messages } from '../strings';
|
||||
import { SecService } from '../../security.gblib/services/SecService';
|
||||
import { GBServer } from '../../../src/app';
|
||||
import { GBConversationalService } from '../services/GBConversationalService';
|
||||
/**
|
||||
* Dialog for the bot explains about itself.
|
||||
*/
|
||||
|
@ -58,7 +59,7 @@ export class SwitchBotDialog extends IGBDialog {
|
|||
async step => {
|
||||
const locale = step.context.activity.locale;
|
||||
|
||||
return await step.prompt('textPrompt', "Qual seria o código de ativação?");
|
||||
return await min.conversationalService.prompt (min, step, "Qual seria o código de ativação?");
|
||||
},
|
||||
async step => {
|
||||
let sec = new SecService();
|
||||
|
@ -66,7 +67,7 @@ export class SwitchBotDialog extends IGBDialog {
|
|||
const botId = step.result;
|
||||
const instance = await min.core.loadInstanceByBotId(botId);
|
||||
await sec.updateUserInstance(from, instance.instanceId);
|
||||
await step.context.sendActivity(`Opa, vamos lá!`);
|
||||
await min.conversationalService.sendText(min, step, `Opa, vamos lá!`);
|
||||
|
||||
return await step.next();
|
||||
}
|
||||
|
|
|
@ -41,6 +41,7 @@ import {WaterfallDialog } from 'botbuilder-dialogs';
|
|||
import { GBMinInstance, IGBDialog } from 'botlib';
|
||||
import { Messages } from '../strings';
|
||||
import { GBServer } from '../../../src/app';
|
||||
import { GBConversationalService } from '../services/GBConversationalService';
|
||||
|
||||
/**
|
||||
* Dialog for Welcoming people.
|
||||
|
@ -79,7 +80,7 @@ export class WelcomeDialog extends IGBDialog {
|
|||
? Messages[locale].good_evening
|
||||
: Messages[locale].good_night;
|
||||
|
||||
await step.context.sendActivity(Messages[locale].hi(msg));
|
||||
await min.conversationalService.sendText(min, step, Messages[locale].hi(msg));
|
||||
await step.replaceDialog('/ask', { firstTime: true });
|
||||
|
||||
if (
|
||||
|
|
|
@ -40,6 +40,7 @@ import { BotAdapter } from 'botbuilder';
|
|||
import { WaterfallDialog } from 'botbuilder-dialogs';
|
||||
import { GBMinInstance, IGBDialog } from 'botlib';
|
||||
import { Messages } from '../strings';
|
||||
import { GBConversationalService } from '../services/GBConversationalService';
|
||||
/**
|
||||
* Dialog for the bot explains about itself.
|
||||
*/
|
||||
|
@ -54,11 +55,11 @@ export class WhoAmIDialog extends IGBDialog {
|
|||
min.dialogs.add(new WaterfallDialog('/whoAmI', [
|
||||
async step => {
|
||||
const locale = step.context.activity.locale;
|
||||
await step.context.sendActivity(`${min.instance.description}`);
|
||||
await min.conversationalService.sendText(min, step, `${min.instance.description}`);
|
||||
|
||||
if (min.instance.whoAmIVideo !== undefined) {
|
||||
await step.context.sendActivity(Messages[locale].show_video);
|
||||
await min.conversationalService.sendEvent(step, 'play', {
|
||||
await min.conversationalService.sendText(min, step, Messages[locale].show_video);
|
||||
await min.conversationalService.sendEvent(min, step, 'play', {
|
||||
playerType: 'video',
|
||||
data: min.instance.whoAmIVideo.trim()
|
||||
});
|
||||
|
|
|
@ -43,6 +43,7 @@ import { GBDeployer } from './GBDeployer';
|
|||
const MicrosoftGraph = require("@microsoft/microsoft-graph-client");
|
||||
import { Messages } from "../strings";
|
||||
import { GBServer } from '../../../src/app';
|
||||
import { GBConversationalService } from './GBConversationalService';
|
||||
const request = require('request-promise-native');
|
||||
|
||||
/**
|
||||
|
@ -294,7 +295,7 @@ export class DialogClass {
|
|||
async step => {
|
||||
const locale = step.context.activity.locale;
|
||||
if ((step.options as any).ask) {
|
||||
await step.context.sendActivity(Messages[locale].whats_email);
|
||||
await min.conversationalService.sendText(min, step, Messages[locale].whats_email);
|
||||
}
|
||||
return await step.prompt("textPrompt", {});
|
||||
},
|
||||
|
@ -308,7 +309,7 @@ export class DialogClass {
|
|||
const value = extractEntity(step.result);
|
||||
|
||||
if (value === null) {
|
||||
await step.context.sendActivity(Messages[locale].validation_enter_valid_email);
|
||||
await min.conversationalService.sendText(min, step, Messages[locale].validation_enter_valid_email);
|
||||
return await step.replaceDialog('/gbasic-email', { ask: true });
|
||||
}
|
||||
else {
|
||||
|
@ -378,6 +379,6 @@ export class DialogClass {
|
|||
}
|
||||
|
||||
public async talk(step, text: string) {
|
||||
return await step.context.sendActivity(text);
|
||||
return await this.min.conversationalService.sendText(this.min, step, text);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -99,7 +99,7 @@ export class GBConversationalService {
|
|||
await min.whatsAppDirectLine.sendFileToDevice(mobile, url, filename, caption);
|
||||
}
|
||||
else {
|
||||
await step.context.sendActivity(url);
|
||||
await min.conversationalService.sendText(min, step, url);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -109,7 +109,7 @@ export class GBConversationalService {
|
|||
await min.whatsAppDirectLine.sendAudioToDevice(mobile, url);
|
||||
}
|
||||
|
||||
public async sendEvent(step: GBDialogStep, name: string, value: Object): Promise<any> {
|
||||
public async sendEvent(min: GBMinInstance, step: GBDialogStep, name: string, value: Object): Promise<any> {
|
||||
if (step.context.activity.channelId === 'webchat') {
|
||||
const msg = MessageFactory.text('');
|
||||
msg.value = value;
|
||||
|
@ -439,6 +439,7 @@ export class GBConversationalService {
|
|||
if (currentText !== '') {
|
||||
if (mobile === null) {
|
||||
await step.context.sendActivity(currentText);
|
||||
|
||||
}
|
||||
else {
|
||||
this.sendToMobile(min, mobile, currentText);
|
||||
|
@ -546,7 +547,7 @@ export class GBConversationalService {
|
|||
|
||||
try {
|
||||
const results = await request(options);
|
||||
|
||||
|
||||
return results[0].translations[0].text;
|
||||
} catch (error) {
|
||||
const msg = `Error calling Translator service layer. Error is: ${error}.`;
|
||||
|
@ -555,7 +556,7 @@ export class GBConversationalService {
|
|||
}
|
||||
}
|
||||
|
||||
public async sendText(min, step, text) {
|
||||
public async prompt(min: GBMinInstance, step: GBDialogStep, text: string) {
|
||||
|
||||
let sec = new SecService();
|
||||
const member = step.context.activity.from;
|
||||
|
@ -565,9 +566,26 @@ export class GBConversationalService {
|
|||
min.instance.translatorKey,
|
||||
min.instance.translatorEndpoint,
|
||||
text,
|
||||
user.locale
|
||||
user.locale ? user.locale : 'pt'
|
||||
);
|
||||
|
||||
return await step.prompt("textPrompt", text ? text : {});
|
||||
}
|
||||
|
||||
public async sendText(min, step, text) {
|
||||
|
||||
let sec = new SecService();
|
||||
const member = step.context.activity.from;
|
||||
const user = await sec.ensureUser(min.instance.instanceId, member.id,
|
||||
member.name, "", "web", member.name);
|
||||
text = await min.conversationalService.translate(
|
||||
min.instance.translatorKey,
|
||||
min.instance.translatorEndpoint,
|
||||
text,
|
||||
user.locale? user.locale: 'pt'
|
||||
);
|
||||
|
||||
await step.context.sendActivity(text);
|
||||
}
|
||||
|
||||
public async checkLanguage(step: GBDialogStep, min, text) {
|
||||
|
@ -576,14 +594,14 @@ export class GBConversationalService {
|
|||
switch (locale) {
|
||||
case 'pt':
|
||||
step.context.activity.locale = 'pt-BR';
|
||||
await step.context.sendActivity(Messages[locale].changing_language);
|
||||
await min.conversationalService.sendText(min, step, Messages[locale].changing_language);
|
||||
break;
|
||||
case 'en':
|
||||
step.context.activity.locale = 'en-US';
|
||||
await step.context.sendActivity(Messages[locale].changing_language);
|
||||
await min.conversationalService.sendText(min, step, Messages[locale].changing_language);
|
||||
break;
|
||||
default:
|
||||
await step.context.sendActivity(`; Unknown; language: $;{locale;}`);
|
||||
await min.conversationalService.sendText(min, step, `; Unknown; language: $;{locale;}`);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -68,6 +68,7 @@ import { SecService } from '../../security.gblib/services/SecService';
|
|||
import { AnalyticsService } from '../../analytics.gblib/services/AnalyticsService';
|
||||
import { WhatsappDirectLine } from '../../whatsapp.gblib/services/WhatsappDirectLine';
|
||||
import fs = require('fs');
|
||||
import { GBConversationalService } from './GBConversationalService';
|
||||
|
||||
/**
|
||||
* Minimal service layer for a bot.
|
||||
|
@ -532,7 +533,7 @@ export class GBMinService {
|
|||
// First time processing.
|
||||
|
||||
if (!user.loaded) {
|
||||
await min.conversationalService.sendEvent(step, 'loadInstance', {
|
||||
await min.conversationalService.sendEvent(min, step, 'loadInstance', {
|
||||
instanceId: instance.instanceId,
|
||||
botId: instance.botId,
|
||||
theme: instance.theme ? instance.theme : 'default.gbtheme',
|
||||
|
@ -594,7 +595,7 @@ export class GBMinService {
|
|||
const msg = `ERROR: ${error.message} ${error.stack ? error.stack : ''}`;
|
||||
GBLog.error(msg);
|
||||
|
||||
await step.context.sendActivity(Messages[step.context.activity.locale].very_sorry_about_error);
|
||||
await min.conversationalService.sendText(min, step, Messages[step.context.activity.locale].very_sorry_about_error);
|
||||
await step.beginDialog('/ask', { isReturning: true });
|
||||
}
|
||||
});
|
||||
|
@ -666,7 +667,7 @@ export class GBMinService {
|
|||
|
||||
} else if (globalQuit(step.context.activity.locale, context.activity.text)) { // TODO: Hard-code additional languages.
|
||||
await step.cancelAllDialogs();
|
||||
await step.context.sendActivity(Messages[step.context.activity.locale].canceled);
|
||||
await min.conversationalService.sendText(min, step, Messages[step.context.activity.locale].canceled);
|
||||
} else if (context.activity.text === 'admin') {
|
||||
await step.beginDialog('/admin');
|
||||
|
||||
|
|
|
@ -44,6 +44,7 @@ const vm = require('vm');
|
|||
import urlJoin = require('url-join');
|
||||
import { DialogClass } from './GBAPIService';
|
||||
import { Messages } from '../strings';
|
||||
import { GBConversationalService } from './GBConversationalService';
|
||||
//tslint:disable-next-line:no-submodule-imports
|
||||
const vb2ts = require('vbscript-to-typescript/dist/converter');
|
||||
const beautify = require('js-beautify').js;
|
||||
|
@ -318,7 +319,7 @@ export class GBVMService extends GBService {
|
|||
step.activeDialog.state.options = {};
|
||||
step.activeDialog.state.options.cbId = (step.options as any).id;
|
||||
step.activeDialog.state.options.previousResolve = (step.options as any).previousResolve;
|
||||
return await step.prompt('textPrompt', {});
|
||||
return await min.conversationalService.prompt (min, step,null);
|
||||
},
|
||||
async step => {
|
||||
const cbId = step.activeDialog.state.options.cbId;
|
||||
|
|
|
@ -43,6 +43,7 @@ import { AzureText } from 'pragmatismo-io-framework';
|
|||
import { CSService } from '../services/CSService';
|
||||
import { Messages } from '../strings';
|
||||
import { SecService } from '../../security.gblib/services/SecService';
|
||||
import { GBConversationalService } from '../../core.gbapp/services/GBConversationalService';
|
||||
|
||||
/**
|
||||
* Dialog for feedback collecting.
|
||||
|
@ -61,7 +62,7 @@ export class FeedbackDialog extends IGBDialog {
|
|||
new WaterfallDialog('/pleaseNoBadWords', [
|
||||
async step => {
|
||||
const locale = step.context.activity.locale;
|
||||
await step.context.sendActivity(Messages[locale].please_no_bad_words);
|
||||
await min.conversationalService.sendText(min, step, Messages[locale].please_no_bad_words);
|
||||
|
||||
return await step.next();
|
||||
}
|
||||
|
@ -77,7 +78,7 @@ export class FeedbackDialog extends IGBDialog {
|
|||
let sec = new SecService();
|
||||
let from = step.context.activity.from.id;
|
||||
|
||||
await step.context.sendActivity(Messages[locale].please_wait_transfering);
|
||||
await min.conversationalService.sendText(min, step, Messages[locale].please_wait_transfering);
|
||||
let agentSystemId = await sec.assignHumanAgent(from, min.instance.instanceId);
|
||||
|
||||
await min.whatsAppDirectLine.sendToDevice(agentSystemId,
|
||||
|
@ -98,7 +99,7 @@ export class FeedbackDialog extends IGBDialog {
|
|||
let from = step.context.activity.from.id;
|
||||
|
||||
await sec.updateCurrentAgent(from, min.instance.instanceId, null);
|
||||
await step.context.sendActivity(Messages[locale].notify_end_transfer(min.instance.botId));
|
||||
await min.conversationalService.sendText(min, step, Messages[locale].notify_end_transfer(min.instance.botId));
|
||||
|
||||
return await step.next();
|
||||
}
|
||||
|
@ -118,7 +119,7 @@ export class FeedbackDialog extends IGBDialog {
|
|||
const rate = step.result.entity;
|
||||
const user = await min.userProfile.get(step.context, {});
|
||||
await service.updateConversationRate(user.conversation, rate);
|
||||
await step.context.sendActivity(Messages[locale].thanks);
|
||||
await min.conversationalService.sendText(min, step, Messages[locale].thanks);
|
||||
|
||||
return await step.next();
|
||||
}
|
||||
|
@ -130,10 +131,10 @@ export class FeedbackDialog extends IGBDialog {
|
|||
async step => {
|
||||
const locale = step.context.activity.locale;
|
||||
|
||||
await step.context.sendActivity(Messages[locale].about_suggestions);
|
||||
await min.conversationalService.sendText(min, step, Messages[locale].about_suggestions);
|
||||
step.activeDialog.state.cbId = (step.options as any).id;
|
||||
|
||||
return await step.prompt('textPrompt', Messages[locale].what_about_service);
|
||||
return await min.conversationalService.prompt (min, step, Messages[locale].what_about_service);
|
||||
},
|
||||
async step => {
|
||||
const locale = step.context.activity.locale;
|
||||
|
@ -145,9 +146,9 @@ export class FeedbackDialog extends IGBDialog {
|
|||
);
|
||||
|
||||
if (rate > 0.5) {
|
||||
await step.context.sendActivity(Messages[locale].glad_you_liked);
|
||||
await min.conversationalService.sendText(min, step, Messages[locale].glad_you_liked);
|
||||
} else {
|
||||
await step.context.sendActivity(Messages[locale].we_will_improve);
|
||||
await min.conversationalService.sendText(min, step, Messages[locale].we_will_improve);
|
||||
}
|
||||
|
||||
return await step.replaceDialog('/ask', { isReturning: true });
|
||||
|
|
|
@ -43,6 +43,7 @@ import { WaterfallDialog } from 'botbuilder-dialogs';
|
|||
import { CSService } from '../services/CSService';
|
||||
import { Messages } from '../strings';
|
||||
import { AnalyticsService } from '../../analytics.gblib/services/AnalyticsService';
|
||||
import { GBConversationalService } from '../../core.gbapp/services/GBConversationalService';
|
||||
|
||||
/**
|
||||
* Dialog for collecting quality of answer.
|
||||
|
@ -65,14 +66,14 @@ export class QualityDialog extends IGBDialog {
|
|||
const score = step.result;
|
||||
|
||||
setTimeout(
|
||||
() => min.conversationalService.sendEvent(step, 'stop', undefined),
|
||||
() => min.conversationalService.sendEvent(min, step, 'stop', undefined),
|
||||
400
|
||||
);
|
||||
|
||||
if (score === 0) {
|
||||
await step.context.sendActivity(Messages[locale].im_sorry_lets_try);
|
||||
await min.conversationalService.sendText(min, step, Messages[locale].im_sorry_lets_try);
|
||||
} else {
|
||||
await step.context.sendActivity(Messages[locale].great_thanks);
|
||||
await min.conversationalService.sendText(min, step, Messages[locale].great_thanks);
|
||||
|
||||
await service.insertQuestionAlternate(
|
||||
min.instance.instanceId,
|
||||
|
|
|
@ -45,6 +45,7 @@ import { KBService } from './../services/KBService';
|
|||
import { GuaribasAnswer } from '../models';
|
||||
import { GBMinService } from '../../../packages/core.gbapp/services/GBMinService';
|
||||
import { SecService } from '../../security.gblib/services/SecService';
|
||||
import { GBConversationalService } from '../../core.gbapp/services/GBConversationalService';
|
||||
|
||||
/**
|
||||
* Dialog arguments.
|
||||
|
@ -92,7 +93,7 @@ export class AskDialog extends IGBDialog {
|
|||
throw new Error('Invalid use of /ask');
|
||||
}
|
||||
if (text.length > 0) {
|
||||
return await step.prompt('textPrompt', text);
|
||||
return await min.conversationalService.prompt(min, step, text);
|
||||
}
|
||||
|
||||
return await step.next();
|
||||
|
@ -101,6 +102,24 @@ export class AskDialog extends IGBDialog {
|
|||
if (step.result) {
|
||||
|
||||
let query = step.result;
|
||||
|
||||
const locale = await AzureText.getLocale(min.instance.textAnalyticsKey,
|
||||
min.instance.textAnalyticsEndpoint, query);
|
||||
|
||||
let sec = new SecService();
|
||||
const member = step.context.activity.from;
|
||||
|
||||
const user = await sec.ensureUser(min.instance.instanceId, member.id,
|
||||
member.name, "", "web", member.name);
|
||||
user.locale = locale;
|
||||
await user.save();
|
||||
|
||||
query = await min.conversationalService.translate(
|
||||
min.instance.translatorKey,
|
||||
min.instance.translatorEndpoint,
|
||||
query,
|
||||
'pt');
|
||||
GBLog.info(`Translated text: ${query}.`)
|
||||
return await step.replaceDialog('/answer', { query: query });
|
||||
} else {
|
||||
return await step.next();
|
||||
|
@ -114,17 +133,29 @@ export class AskDialog extends IGBDialog {
|
|||
async step => {
|
||||
const user = await min.userProfile.get(step.context, {});
|
||||
let text = step.options.query;
|
||||
|
||||
let sec = new SecService();
|
||||
const member = step.context.activity.from;
|
||||
const userDb = await sec.ensureUser(min.instance.instanceId, member.id,
|
||||
member.name, "", "web", member.name);
|
||||
text = await min.conversationalService.translate(
|
||||
min.instance.translatorKey,
|
||||
min.instance.translatorEndpoint,
|
||||
text,
|
||||
userDb.locale ? userDb.locale : 'pt'
|
||||
);
|
||||
|
||||
if (!text) {
|
||||
throw new Error(`/answer being called with no args query text.`);
|
||||
}
|
||||
const locale = step.context.activity.locale;
|
||||
// Stops any content on projector.
|
||||
await min.conversationalService.sendEvent(step, 'stop', undefined);
|
||||
await min.conversationalService.sendEvent(min, step, 'stop', undefined);
|
||||
// Handle extra text from FAQ.
|
||||
if (step.options && step.options.query) {
|
||||
text = step.options.query;
|
||||
} else if (step.options && step.options.fromFaq) {
|
||||
await step.context.sendActivity(Messages[locale].going_answer);
|
||||
await min.conversationalService.sendText(min, step, Messages[locale].going_answer);
|
||||
}
|
||||
// Spells check the input text before sending Search or NLP.
|
||||
if (min.instance.spellcheckerKey !== undefined) {
|
||||
|
@ -164,7 +195,7 @@ export class AskDialog extends IGBDialog {
|
|||
await min.userProfile.set(step.context, user2);
|
||||
// Informs user that a broader search will be used.
|
||||
if (user2.subjects.length > 0) {
|
||||
await step.context.sendActivity(Messages[locale].wider_answer);
|
||||
await min.conversationalService.sendText(min, step, Messages[locale].wider_answer);
|
||||
}
|
||||
|
||||
if (resultsB.answer)
|
||||
|
@ -174,7 +205,7 @@ export class AskDialog extends IGBDialog {
|
|||
return await AskDialog.handleAnswer(service, min, step, resultsA.answer);
|
||||
} else {
|
||||
if (!(await min.conversationalService.routeNLP(step, min, text))) {
|
||||
await step.context.sendActivity(Messages[locale].did_not_find);
|
||||
await min.conversationalService.sendText(min, step, Messages[locale].did_not_find);
|
||||
|
||||
return await step.replaceDialog('/ask', { isReturning: true });
|
||||
}
|
||||
|
|
|
@ -41,6 +41,7 @@ import { WaterfallDialog } from 'botbuilder-dialogs';
|
|||
import { GBMinInstance, IGBDialog } from 'botlib';
|
||||
import { Messages } from '../strings';
|
||||
import { KBService } from './../services/KBService';
|
||||
import { GBConversationalService } from '../../core.gbapp/services/GBConversationalService';
|
||||
|
||||
/**
|
||||
* Handle display of FAQ allowing direct access to KB.
|
||||
|
@ -61,12 +62,12 @@ export class FaqDialog extends IGBDialog {
|
|||
const data = await service.getFaqBySubjectArray('faq', undefined);
|
||||
const locale = step.context.activity.locale;
|
||||
if (data !== undefined) {
|
||||
await min.conversationalService.sendEvent(step, 'play', {
|
||||
await min.conversationalService.sendEvent(min, step, 'play', {
|
||||
playerType: 'bullet',
|
||||
data: data.slice(0, 10)
|
||||
});
|
||||
|
||||
await step.context.sendActivity(Messages[locale].see_faq);
|
||||
await min.conversationalService.sendText(min, step, Messages[locale].see_faq);
|
||||
|
||||
return await step.next();
|
||||
}
|
||||
|
|
|
@ -44,6 +44,7 @@ import { GBMinInstance, IGBDialog } from 'botlib';
|
|||
import { GuaribasSubject } from '../models';
|
||||
import { KBService } from '../services/KBService';
|
||||
import { Messages } from '../strings';
|
||||
import { GBConversationalService } from '../../core.gbapp/services/GBConversationalService';
|
||||
|
||||
/**
|
||||
* Dialog arguments.
|
||||
|
@ -94,14 +95,14 @@ export class MenuDialog extends IGBDialog {
|
|||
// Whenever a subject is selected, shows a faq about it.
|
||||
if (user.subjects.length > 0) {
|
||||
const list = await service.getFaqBySubjectArray('menu', user.subjects);
|
||||
await min.conversationalService.sendEvent(step, 'play', {
|
||||
await min.conversationalService.sendEvent(min, step, 'play', {
|
||||
playerType: 'bullet',
|
||||
data: list.slice(0, 10)
|
||||
});
|
||||
}
|
||||
} else {
|
||||
user.subjects = [];
|
||||
await step.context.sendActivity(Messages[locale].here_is_subjects);
|
||||
await min.conversationalService.sendText(min, step, Messages[locale].here_is_subjects);
|
||||
user.isAsking = false;
|
||||
}
|
||||
const msg = MessageFactory.text('');
|
||||
|
@ -133,7 +134,7 @@ export class MenuDialog extends IGBDialog {
|
|||
if (attachments.length === 0) {
|
||||
|
||||
if (user.subjects && user.subjects.length > 0) {
|
||||
await step.context.sendActivity(
|
||||
await min.conversationalService.sendText(min, step,
|
||||
Messages[locale].lets_search(KBService.getFormattedSubjectItems(user.subjects))
|
||||
);
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ import { GuaribasAnswer, GuaribasQuestion, GuaribasSubject } from '../models';
|
|||
import { Messages } from '../strings';
|
||||
import { GBConfigService } from './../../core.gbapp/services/GBConfigService';
|
||||
import { CSService } from '../../customer-satisfaction.gbapp/services/CSService';
|
||||
|
||||
import { SecService } from '../../security.gblib/services/SecService';
|
||||
|
||||
/**
|
||||
* Result for quey on KB data.
|
||||
|
@ -376,7 +376,7 @@ export class KBService implements IGBKBService {
|
|||
|
||||
public async sendAnswer(min: GBMinInstance, channel: string, step: GBDialogStep, answer: GuaribasAnswer) {
|
||||
if (answer.content.endsWith('.mp4')) {
|
||||
await this.playVideo(min.conversationalService, step, answer);
|
||||
await this.playVideo(min, min.conversationalService, step, answer);
|
||||
}
|
||||
else if (answer.format === '.md') {
|
||||
|
||||
|
@ -386,8 +386,8 @@ export class KBService implements IGBKBService {
|
|||
|
||||
await this.playAudio(min, answer, channel, step, min.conversationalService);
|
||||
} else {
|
||||
await step.context.sendActivity(answer.content);
|
||||
await min.conversationalService.sendEvent(step, 'stop', undefined);
|
||||
await min.conversationalService.sendText(min, step, answer.content);
|
||||
await min.conversationalService.sendEvent(min, step, 'stop', undefined);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -411,21 +411,45 @@ export class KBService implements IGBKBService {
|
|||
html = marked(answer.content);
|
||||
if (channel === 'webchat' &&
|
||||
GBConfigService.get('DISABLE_WEB') !== 'true') {
|
||||
await this.sendMarkdownToWeb(step, conversationalService, html, answer);
|
||||
|
||||
await this.sendMarkdownToWeb(min, step, conversationalService, html, answer);
|
||||
}
|
||||
else if (channel === 'whatsapp') {
|
||||
let sec = new SecService();
|
||||
const member = step.context.activity.from;
|
||||
const user = await sec.ensureUser(min.instance.instanceId, member.id,
|
||||
member.name, "", "web", member.name);
|
||||
let text = await min.conversationalService.translate(
|
||||
min.instance.translatorKey,
|
||||
min.instance.translatorEndpoint,
|
||||
answer.content,
|
||||
user.locale ? user.locale : 'pt'
|
||||
);
|
||||
|
||||
await conversationalService.sendMarkdownToMobile(min, step, null, answer.content);
|
||||
}
|
||||
else {
|
||||
await step.context.sendActivity(html);
|
||||
await min.conversationalService.sendText(min, step, html);
|
||||
}
|
||||
}
|
||||
|
||||
private async sendMarkdownToWeb(step: GBDialogStep, conversationalService: IGBConversationalService, html: string, answer: GuaribasAnswer) {
|
||||
private async sendMarkdownToWeb(min, step: GBDialogStep, conversationalService: IGBConversationalService, html: string, answer: GuaribasAnswer) {
|
||||
|
||||
let sec = new SecService();
|
||||
const member = step.context.activity.from;
|
||||
const user = await sec.ensureUser(min.instance.instanceId, member.id,
|
||||
member.name, "", "web", member.name);
|
||||
html = await min.conversationalService.translate(
|
||||
min.instance.translatorKey,
|
||||
min.instance.translatorEndpoint,
|
||||
html,
|
||||
user.locale ? user.locale : 'pt'
|
||||
);
|
||||
|
||||
const locale = step.context.activity.locale;
|
||||
await step.context.sendActivity(Messages[locale].will_answer_projector);
|
||||
await min.conversationalService.sendText( min, step, Messages[locale].will_answer_projector);
|
||||
html = html.replace(/src\=\"kb\//g, `src=\"../kb/`);
|
||||
await conversationalService.sendEvent(step, 'play', {
|
||||
await conversationalService.sendEvent(min, step, 'play', {
|
||||
playerType: 'markdown',
|
||||
data: {
|
||||
content: html,
|
||||
|
@ -437,8 +461,8 @@ export class KBService implements IGBKBService {
|
|||
}
|
||||
|
||||
|
||||
private async playVideo(conversationalService: IGBConversationalService, step: GBDialogStep, answer: GuaribasAnswer) {
|
||||
await conversationalService.sendEvent(step, 'play', {
|
||||
private async playVideo(min, conversationalService: IGBConversationalService, step: GBDialogStep, answer: GuaribasAnswer) {
|
||||
await conversationalService.sendEvent(min, step, 'play', {
|
||||
playerType: 'video',
|
||||
data: answer.content
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue