fix(gbdialog): VBA loop done - one thing left to automate: Hear wrapper.
This commit is contained in:
parent
ce04290fcd
commit
776fe03503
6 changed files with 51 additions and 35 deletions
6
package-lock.json
generated
6
package-lock.json
generated
|
@ -3548,9 +3548,9 @@
|
|||
}
|
||||
},
|
||||
"botlib": {
|
||||
"version": "0.1.7",
|
||||
"resolved": "https://registry.npmjs.org/botlib/-/botlib-0.1.7.tgz",
|
||||
"integrity": "sha512-vp8htUT/AL+pYXdiy9s13HFLbygCUorELw1dg1FEqHsfXQOoTlUvr52rNEeKikHvNYaXEEHqhv2F4pLRvEHIYw==",
|
||||
"version": "0.1.8",
|
||||
"resolved": "https://registry.npmjs.org/botlib/-/botlib-0.1.8.tgz",
|
||||
"integrity": "sha512-66v6koaZnEZBMtnFlMs6wGyD6lu+CUg0YXuPPhTEMROrJtWu25aTlCXgkxlhhuGjQvxRpkqwvP8Ta5fsAGqvPg==",
|
||||
"requires": {
|
||||
"async": "2.6.1",
|
||||
"botbuilder": "4.1.3",
|
||||
|
|
|
@ -66,7 +66,7 @@
|
|||
"botbuilder-choices": "^4.0.0-preview1.2",
|
||||
"botbuilder-dialogs": "^4.1.5",
|
||||
"botbuilder-prompts": "^4.0.0-preview1.2",
|
||||
"botlib": "^0.1.7",
|
||||
"botlib": "0.1.8",
|
||||
"chai": "4.2.0",
|
||||
"child_process": "^1.0.2",
|
||||
"chokidar": "2.0.4",
|
||||
|
|
|
@ -51,9 +51,9 @@ export class DialogClass {
|
|||
}
|
||||
|
||||
public async hear(cb) {
|
||||
const id = Math.floor(Math.random() * 1000000000000);
|
||||
this.min.cbMap[id] = cb;
|
||||
await this.step.beginDialog('/feedback', { id: id });
|
||||
let idCallback = Math.floor(Math.random() * 1000000000000);
|
||||
this.min.cbMap[idCallback] = cb;
|
||||
await this.step.beginDialog('/hear', { id: idCallback});
|
||||
}
|
||||
|
||||
public async talk(text: string) {
|
||||
|
|
|
@ -315,7 +315,7 @@ export class GBMinService {
|
|||
min.conversationalService = this.conversationalService;
|
||||
min.adminService = this.adminService;
|
||||
min.instance = await this.core.loadInstance(min.botId);
|
||||
|
||||
min.cbMap = {};
|
||||
min.userProfile = conversationState.createProperty('userProfile');
|
||||
const dialogState = conversationState.createProperty('dialogState');
|
||||
|
||||
|
@ -408,14 +408,12 @@ export class GBMinService {
|
|||
}
|
||||
|
||||
// Processes messages.
|
||||
|
||||
} else if (context.activity.type === 'message') {
|
||||
// Checks for /admin request.
|
||||
if (context.activity.text === 'vba') {
|
||||
min.sandbox.context = context;
|
||||
min.sandbox.step = step;
|
||||
min.sandbox['bot'].bind(min.sandbox);
|
||||
|
||||
await min.sandbox['bot']();
|
||||
} else if (context.activity.text === 'admin') {
|
||||
await step.beginDialog('/admin');
|
||||
|
|
|
@ -37,6 +37,7 @@ import * as fs from 'fs';
|
|||
import { DialogClass } from './GBAPIService';
|
||||
import { GBDeployer } from './GBDeployer';
|
||||
import { TSCompiler } from './TSCompiler';
|
||||
import { WaterfallDialog } from 'botbuilder-dialogs';
|
||||
const util = require('util');
|
||||
const logger = require('../../../src/logger');
|
||||
const vm = require('vm');
|
||||
|
@ -66,6 +67,31 @@ export class GBVMService implements IGBCoreService {
|
|||
await this.run(source, path, localPath, min, deployer, filename);
|
||||
});
|
||||
await this.run(source, path, localPath, min, deployer, filename);
|
||||
this.addHearDialog(min);
|
||||
}
|
||||
|
||||
private addHearDialog(min) {
|
||||
min.dialogs.add(
|
||||
new WaterfallDialog('/hear', [
|
||||
async step => {
|
||||
step.activeDialog.state.cbId = step.options['id'];
|
||||
step.activeDialog.state.idResolve = step.options['idResolve'];
|
||||
|
||||
return await step.prompt('textPrompt', {});
|
||||
},
|
||||
async step => {
|
||||
min.sandbox.context = step.context;
|
||||
min.sandbox.step = step;
|
||||
|
||||
const cbId = step.activeDialog.state.cbId;
|
||||
const cb = min.cbMap[cbId];
|
||||
cb.bind({ step: step, context: step.context }); // TODO: Necessary or min.sandbox
|
||||
await cb();
|
||||
|
||||
return await step.next();
|
||||
}
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
private async run(source: any, path: string, localPath: string, min: any, deployer: GBDeployer, filename: string) {
|
||||
|
@ -80,11 +106,14 @@ export class GBVMService implements IGBCoreService {
|
|||
// Run JS into the GB context.
|
||||
const jsfile = `bot.js`;
|
||||
localPath = UrlJoin(path, jsfile);
|
||||
|
||||
if (fs.existsSync(localPath)) {
|
||||
let code: string = fs.readFileSync(localPath, 'utf8');
|
||||
code = code.replace(/^.*exports.*$/gm, '');
|
||||
code = code.replace(/this\./gm, 'await this.');
|
||||
code = code.replace(/function/gm, 'async function');
|
||||
//code = code.replace(/this\.hear\(\){/gm, 'this.hear(async () => { ');
|
||||
|
||||
const sandbox: DialogClass = new DialogClass(min);
|
||||
const context = vm.createContext(sandbox);
|
||||
vm.runInContext(code, context);
|
||||
|
|
|
@ -89,35 +89,24 @@ export class FeedbackDialog extends IGBDialog {
|
|||
return await step.prompt('textPrompt', Messages[locale].what_about_service);
|
||||
},
|
||||
async step => {
|
||||
|
||||
console.log(step.result);
|
||||
|
||||
// min.sandbox.context = step.context;
|
||||
// min.sandbox.step = step;
|
||||
const locale = step.context.activity.locale;
|
||||
const rate = await AzureText.getSentiment(
|
||||
min.instance.textAnalyticsKey,
|
||||
min.instance.textAnalyticsEndpoint,
|
||||
min.conversationalService.getCurrentLanguage(step),
|
||||
step.result
|
||||
);
|
||||
|
||||
let cbId = step.activeDialog.state.cbId;
|
||||
let cb = min.cbMap[cbId];
|
||||
cb.bind({ step: step, context: step.context });
|
||||
await cb();
|
||||
if (rate > 0.5) {
|
||||
await step.context.sendActivity(Messages[locale].glad_you_liked);
|
||||
} else {
|
||||
await step.context.sendActivity(Messages[locale].we_will_improve);
|
||||
|
||||
// const locale = step.context.activity.locale;
|
||||
// const rate = await AzureText.getSentiment(
|
||||
// min.instance.textAnalyticsKey,
|
||||
// min.instance.textAnalyticsEndpoint,
|
||||
// min.conversationalService.getCurrentLanguage(step),
|
||||
// step.result
|
||||
// );
|
||||
// TODO: Record.
|
||||
}
|
||||
return await step.replaceDialog('/ask', { isReturning: true });
|
||||
|
||||
// if (rate > 0.5) {
|
||||
// await step.context.sendActivity(Messages[locale].glad_you_liked);
|
||||
// } else {
|
||||
// await step.context.sendActivity(Messages[locale].we_will_improve);
|
||||
|
||||
// // TODO: Record.
|
||||
// }
|
||||
// await step.replaceDialog('/ask', { isReturning: true });
|
||||
|
||||
return await step.next();
|
||||
}
|
||||
])
|
||||
);
|
||||
|
|
Loading…
Add table
Reference in a new issue