diff --git a/packages/basic.gblib/services/DialogKeywords.ts b/packages/basic.gblib/services/DialogKeywords.ts index 77e650d6..0f499f69 100644 --- a/packages/basic.gblib/services/DialogKeywords.ts +++ b/packages/basic.gblib/services/DialogKeywords.ts @@ -58,13 +58,16 @@ export class DialogKeywords { */ public internalSys: SystemKeywords; + private user; + /** * When creating this keyword facade, a bot instance is * specified among the deployer service. */ - constructor(min: GBMinInstance, deployer: GBDeployer, step: GBDialogStep) { + constructor(min: GBMinInstance, deployer: GBDeployer, step: GBDialogStep, user) { this.min = min; - this.internalSys = new SystemKeywords(min, deployer, step); + this.internalSys = new SystemKeywords(min, deployer, user); + this.user = user; } /** diff --git a/packages/basic.gblib/services/GBVMService.ts b/packages/basic.gblib/services/GBVMService.ts index 56054a81..d3eae916 100644 --- a/packages/basic.gblib/services/GBVMService.ts +++ b/packages/basic.gblib/services/GBVMService.ts @@ -698,7 +698,9 @@ export class GBVMService extends GBService { // } const opts = await promise(step, result); - return await step.replaceDialog('/hear', opts); + if (Object.keys(min.cbMap).length) { + return await step.replaceDialog('/hear', opts); + } } catch (error) { GBLog.error(`Error in BASIC code: ${error}`); const locale = step.context.activity.locale; @@ -718,13 +720,14 @@ export class GBVMService extends GBService { // Creates a class DialogKeywords which is the *this* pointer // in BASIC. - - const sandbox: DialogKeywords = new DialogKeywords(min, deployer, step); + const user = await min.userProfile.get(step.context, {}); + const sandbox: DialogKeywords = new DialogKeywords(min, deployer, step, user); // Injects the .gbdialog generated code into the VM. const context = vm.createContext(sandbox); const code = min.sandBoxMap[text]; + try { vm.runInContext(code, context); } catch (error) { diff --git a/packages/basic.gblib/services/SystemKeywords.ts b/packages/basic.gblib/services/SystemKeywords.ts index d3070955..9dd136c6 100644 --- a/packages/basic.gblib/services/SystemKeywords.ts +++ b/packages/basic.gblib/services/SystemKeywords.ts @@ -60,17 +60,14 @@ export class SystemKeywords { */ private readonly deployer: GBDeployer; - /** - * Reference to the deployer service. - */ - private readonly step: GBDialogStep; + private user; /** * When creating this keyword facade, a bot instance is * specified among the deployer service. */ - constructor(min: GBMinInstance, deployer: GBDeployer, step: GBDialogStep) { - this.step = step; + constructor(min: GBMinInstance, deployer: GBDeployer, user) { + this.user = user; this.min = min; this.deployer = deployer; } @@ -291,11 +288,11 @@ export class SystemKeywords { throw `File '${file}' has a FIND call with more than 1 arguments. Check the .gbdialog associated.`; } - const user = await this.min.userProfile.get(this.step.context, {}); + let maxLines = 100; - if (user.basicOptions && user.basicOptions.maxLines) { - if (user.basicOptions.maxLines.toString().toLowerCase() !== "default") { - maxLines = Number.parseInt(user.basicOptions.maxLines).valueOf(); + if (this.user.basicOptions && this.user.basicOptions.maxLines) { + if (this.user.basicOptions.maxLines.toString().toLowerCase() !== "default") { + maxLines = Number.parseInt(this.user.basicOptions.maxLines).valueOf(); } }