diff --git a/package-lock.json b/package-lock.json index b7d49f64..29da2ceb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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", diff --git a/package.json b/package.json index 6e49b5cf..b5b86b8b 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/packages/core.gbapp/services/GBAPIService.ts b/packages/core.gbapp/services/GBAPIService.ts index b494ea19..118724e8 100644 --- a/packages/core.gbapp/services/GBAPIService.ts +++ b/packages/core.gbapp/services/GBAPIService.ts @@ -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) { diff --git a/packages/core.gbapp/services/GBMinService.ts b/packages/core.gbapp/services/GBMinService.ts index 9e3ea2cf..5dc7a75c 100644 --- a/packages/core.gbapp/services/GBMinService.ts +++ b/packages/core.gbapp/services/GBMinService.ts @@ -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'); diff --git a/packages/core.gbapp/services/GBVMService.ts b/packages/core.gbapp/services/GBVMService.ts index d4e45bae..0e5e4b3a 100644 --- a/packages/core.gbapp/services/GBVMService.ts +++ b/packages/core.gbapp/services/GBVMService.ts @@ -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); diff --git a/packages/customer-satisfaction.gbapp/dialogs/FeedbackDialog.ts b/packages/customer-satisfaction.gbapp/dialogs/FeedbackDialog.ts index 7074ed04..d0ee93c3 100644 --- a/packages/customer-satisfaction.gbapp/dialogs/FeedbackDialog.ts +++ b/packages/customer-satisfaction.gbapp/dialogs/FeedbackDialog.ts @@ -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(); } ]) );