Skip to content

Commit

Permalink
fix(core.gbapp): WebChat now can be made private.
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigorodriguez committed Jan 10, 2020
1 parent c51ff7a commit 99b5a4a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 13 deletions.
16 changes: 10 additions & 6 deletions packages/core.gbapp/services/GBMinService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
})
Expand Down Expand Up @@ -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);

Expand All @@ -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);
}
}
2 changes: 1 addition & 1 deletion packages/default.gbui/src/GBUIApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
35 changes: 29 additions & 6 deletions packages/kb.gbapp/dialogs/AskDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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;
}
Expand Down

0 comments on commit 99b5a4a

Please sign in to comment.