fix(core.gbapp): WebChat now can be made private.

This commit is contained in:
Rodrigo Rodriguez 2020-01-10 10:04:26 -03:00
parent c51ff7a78f
commit 99b5a4a2e9
3 changed files with 40 additions and 13 deletions

View file

@ -286,7 +286,7 @@ export class GBMinService {
}
const instance = await this.core.loadInstance(botId);
if (instance !== null) {
const webchatToken = await this.getWebchatToken(instance);
const webchatTokenContainer = await this.getWebchatToken(instance);
const speechToken = instance.speechKey != null ? await this.getSTSToken(instance) : null;
let theme = instance.theme;
if (theme === undefined) {
@ -297,9 +297,9 @@ export class GBMinService {
instanceId: instance.instanceId,
botId: botId,
theme: theme,
webchatToken: webchatToken,
webchatToken: webchatTokenContainer.token,
speechToken: speechToken,
conversationId: webchatToken.conversationId,
conversationId: webchatTokenContainer.conversationId,
authenticatorTenant: instance.authenticatorTenant,
authenticatorClientId: instance.authenticatorClientId
})
@ -541,9 +541,7 @@ export class GBMinService {
const isVMCall = Object.keys(min.scriptMap).find(key => min.scriptMap[key] === context.activity.text) !== undefined;
if (isVMCall) {
const mainMethod = context.activity.text;
min.sandBoxMap[mainMethod][mainMethod].bind(min.sandBoxMap[mainMethod]);
await min.sandBoxMap[mainMethod][mainMethod](step);
await GBMinService.callVM(context.activity.text, min, step);
} else if (context.activity.text.charAt(0) === '/') {
await step.beginDialog(context.activity.text);
@ -568,4 +566,10 @@ export class GBMinService {
}
}
}
public static async callVM(text: string, min: GBMinInstance, step: GBDialogStep) {
const mainMethod = text;
min.sandBoxMap[mainMethod][mainMethod].bind(min.sandBoxMap[mainMethod]);
return await min.sandBoxMap[mainMethod][mainMethod](step);
}
}

View file

@ -173,7 +173,7 @@ class GBUIApp extends React.Component {
window['botchatDebug'] = true;
const line = new DirectLine({
token: this.state.instanceClient.token
token: this.state.instanceClient.webchatToken
});
line.connectionStatus$.subscribe(connectionStatus => {

View file

@ -42,6 +42,8 @@ import { GBLog, GBMinInstance, IGBDialog } from 'botlib';
import { AzureText } from 'pragmatismo-io-framework';
import { Messages } from '../strings';
import { KBService } from './../services/KBService';
import { GuaribasAnswer } from '../models';
import { GBMinService } from '../../../packages/core.gbapp/services/GBMinService';
/**
* Dialog arguments.
@ -144,10 +146,8 @@ export class AskDialog extends IGBDialog {
// Sends the answer to all outputs, including projector.
await service.sendAnswer(min, AskDialog.getChannel(step), step, resultsA.answer);
return await AskDialog.handleAnswer(service, min, step, resultsA.answer);
// Goes to ask loop, again.
return await step.replaceDialog('/ask', { isReturning: true });
} else {
// Second time running Search, now with no filter.
const resultsB = await service.ask(min.instance, text, min.instance.searchScore, undefined);
@ -163,10 +163,12 @@ export class AskDialog extends IGBDialog {
if (user2.subjects.length > 0) {
await step.context.sendActivity(Messages[locale].wider_answer);
}
// Sends the answer to all outputs, including projector.
await service.sendAnswer(min, AskDialog.getChannel(step), step, resultsB.answer);
return await step.replaceDialog('/ask', { isReturning: true });
if (resultsB.answer)
// Sends the answer to all outputs, including projector.
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);
@ -179,6 +181,27 @@ export class AskDialog extends IGBDialog {
];
}
private static async handleAnswer(service: KBService, min: GBMinInstance, step: any, answer: GuaribasAnswer) {
const dialogSufix = 'dialog:';
const urlSufix = 'url:';
const scriptSufix = 'script:';
if (answer.content.startsWith(dialogSufix)) {
let dialogName = answer.content.substring(dialogSufix.length);
return await step.replaceDialog(`/${dialogName}`, { isReturning: true });
} else if (answer.content.startsWith(scriptSufix)) {
let scriptName = answer.content.substring(scriptSufix.length);
return await GBMinService.callVM(scriptName, min, step);
} else {
await service.sendAnswer(min, AskDialog.getChannel(step), step, answer);
return await step.replaceDialog('/ask', { isReturning: true });
}
}
private static getChannel(step): string {
return !isNaN(step.context.activity.from.id) ? 'whatsapp' : step.context.activity.channelId;
}