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": {
|
"botlib": {
|
||||||
"version": "0.1.7",
|
"version": "0.1.8",
|
||||||
"resolved": "https://registry.npmjs.org/botlib/-/botlib-0.1.7.tgz",
|
"resolved": "https://registry.npmjs.org/botlib/-/botlib-0.1.8.tgz",
|
||||||
"integrity": "sha512-vp8htUT/AL+pYXdiy9s13HFLbygCUorELw1dg1FEqHsfXQOoTlUvr52rNEeKikHvNYaXEEHqhv2F4pLRvEHIYw==",
|
"integrity": "sha512-66v6koaZnEZBMtnFlMs6wGyD6lu+CUg0YXuPPhTEMROrJtWu25aTlCXgkxlhhuGjQvxRpkqwvP8Ta5fsAGqvPg==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"async": "2.6.1",
|
"async": "2.6.1",
|
||||||
"botbuilder": "4.1.3",
|
"botbuilder": "4.1.3",
|
||||||
|
|
|
@ -66,7 +66,7 @@
|
||||||
"botbuilder-choices": "^4.0.0-preview1.2",
|
"botbuilder-choices": "^4.0.0-preview1.2",
|
||||||
"botbuilder-dialogs": "^4.1.5",
|
"botbuilder-dialogs": "^4.1.5",
|
||||||
"botbuilder-prompts": "^4.0.0-preview1.2",
|
"botbuilder-prompts": "^4.0.0-preview1.2",
|
||||||
"botlib": "^0.1.7",
|
"botlib": "0.1.8",
|
||||||
"chai": "4.2.0",
|
"chai": "4.2.0",
|
||||||
"child_process": "^1.0.2",
|
"child_process": "^1.0.2",
|
||||||
"chokidar": "2.0.4",
|
"chokidar": "2.0.4",
|
||||||
|
|
|
@ -51,9 +51,9 @@ export class DialogClass {
|
||||||
}
|
}
|
||||||
|
|
||||||
public async hear(cb) {
|
public async hear(cb) {
|
||||||
const id = Math.floor(Math.random() * 1000000000000);
|
let idCallback = Math.floor(Math.random() * 1000000000000);
|
||||||
this.min.cbMap[id] = cb;
|
this.min.cbMap[idCallback] = cb;
|
||||||
await this.step.beginDialog('/feedback', { id: id });
|
await this.step.beginDialog('/hear', { id: idCallback});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async talk(text: string) {
|
public async talk(text: string) {
|
||||||
|
|
|
@ -315,7 +315,7 @@ export class GBMinService {
|
||||||
min.conversationalService = this.conversationalService;
|
min.conversationalService = this.conversationalService;
|
||||||
min.adminService = this.adminService;
|
min.adminService = this.adminService;
|
||||||
min.instance = await this.core.loadInstance(min.botId);
|
min.instance = await this.core.loadInstance(min.botId);
|
||||||
|
min.cbMap = {};
|
||||||
min.userProfile = conversationState.createProperty('userProfile');
|
min.userProfile = conversationState.createProperty('userProfile');
|
||||||
const dialogState = conversationState.createProperty('dialogState');
|
const dialogState = conversationState.createProperty('dialogState');
|
||||||
|
|
||||||
|
@ -408,14 +408,12 @@ export class GBMinService {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Processes messages.
|
// Processes messages.
|
||||||
|
|
||||||
} else if (context.activity.type === 'message') {
|
} else if (context.activity.type === 'message') {
|
||||||
// Checks for /admin request.
|
// Checks for /admin request.
|
||||||
if (context.activity.text === 'vba') {
|
if (context.activity.text === 'vba') {
|
||||||
min.sandbox.context = context;
|
min.sandbox.context = context;
|
||||||
min.sandbox.step = step;
|
min.sandbox.step = step;
|
||||||
min.sandbox['bot'].bind(min.sandbox);
|
min.sandbox['bot'].bind(min.sandbox);
|
||||||
|
|
||||||
await min.sandbox['bot']();
|
await min.sandbox['bot']();
|
||||||
} else if (context.activity.text === 'admin') {
|
} else if (context.activity.text === 'admin') {
|
||||||
await step.beginDialog('/admin');
|
await step.beginDialog('/admin');
|
||||||
|
|
|
@ -37,6 +37,7 @@ import * as fs from 'fs';
|
||||||
import { DialogClass } from './GBAPIService';
|
import { DialogClass } from './GBAPIService';
|
||||||
import { GBDeployer } from './GBDeployer';
|
import { GBDeployer } from './GBDeployer';
|
||||||
import { TSCompiler } from './TSCompiler';
|
import { TSCompiler } from './TSCompiler';
|
||||||
|
import { WaterfallDialog } from 'botbuilder-dialogs';
|
||||||
const util = require('util');
|
const util = require('util');
|
||||||
const logger = require('../../../src/logger');
|
const logger = require('../../../src/logger');
|
||||||
const vm = require('vm');
|
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);
|
||||||
});
|
});
|
||||||
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) {
|
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.
|
// Run JS into the GB context.
|
||||||
const jsfile = `bot.js`;
|
const jsfile = `bot.js`;
|
||||||
localPath = UrlJoin(path, jsfile);
|
localPath = UrlJoin(path, jsfile);
|
||||||
|
|
||||||
if (fs.existsSync(localPath)) {
|
if (fs.existsSync(localPath)) {
|
||||||
let code: string = fs.readFileSync(localPath, 'utf8');
|
let code: string = fs.readFileSync(localPath, 'utf8');
|
||||||
code = code.replace(/^.*exports.*$/gm, '');
|
code = code.replace(/^.*exports.*$/gm, '');
|
||||||
code = code.replace(/this\./gm, 'await this.');
|
code = code.replace(/this\./gm, 'await this.');
|
||||||
code = code.replace(/function/gm, 'async function');
|
code = code.replace(/function/gm, 'async function');
|
||||||
|
//code = code.replace(/this\.hear\(\){/gm, 'this.hear(async () => { ');
|
||||||
|
|
||||||
const sandbox: DialogClass = new DialogClass(min);
|
const sandbox: DialogClass = new DialogClass(min);
|
||||||
const context = vm.createContext(sandbox);
|
const context = vm.createContext(sandbox);
|
||||||
vm.runInContext(code, context);
|
vm.runInContext(code, context);
|
||||||
|
|
|
@ -90,34 +90,23 @@ export class FeedbackDialog extends IGBDialog {
|
||||||
},
|
},
|
||||||
async step => {
|
async step => {
|
||||||
|
|
||||||
console.log(step.result);
|
const locale = step.context.activity.locale;
|
||||||
|
const rate = await AzureText.getSentiment(
|
||||||
|
min.instance.textAnalyticsKey,
|
||||||
|
min.instance.textAnalyticsEndpoint,
|
||||||
|
min.conversationalService.getCurrentLanguage(step),
|
||||||
|
step.result
|
||||||
|
);
|
||||||
|
|
||||||
// min.sandbox.context = step.context;
|
if (rate > 0.5) {
|
||||||
// min.sandbox.step = step;
|
await step.context.sendActivity(Messages[locale].glad_you_liked);
|
||||||
|
} else {
|
||||||
|
await step.context.sendActivity(Messages[locale].we_will_improve);
|
||||||
|
|
||||||
let cbId = step.activeDialog.state.cbId;
|
// TODO: Record.
|
||||||
let cb = min.cbMap[cbId];
|
}
|
||||||
cb.bind({ step: step, context: step.context });
|
return await step.replaceDialog('/ask', { isReturning: true });
|
||||||
await cb();
|
|
||||||
|
|
||||||
// const locale = step.context.activity.locale;
|
|
||||||
// const rate = await AzureText.getSentiment(
|
|
||||||
// min.instance.textAnalyticsKey,
|
|
||||||
// min.instance.textAnalyticsEndpoint,
|
|
||||||
// min.conversationalService.getCurrentLanguage(step),
|
|
||||||
// step.result
|
|
||||||
// );
|
|
||||||
|
|
||||||
// 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