diff --git a/packages/basic.gblib/dialogs/HearDialog.ts b/packages/basic.gblib/dialogs/HearDialog.ts index 869d6dc9..e98f8f4a 100644 --- a/packages/basic.gblib/dialogs/HearDialog.ts +++ b/packages/basic.gblib/dialogs/HearDialog.ts @@ -304,8 +304,9 @@ export class HearDialog { const list = step.activeDialog.state.options['args']; result = null; + const typed = step.context.activity['originalText']; await CollectionUtil.asyncForEach(list, async item => { - if (GBConversationalService.kmpSearch(step.result, item) != -1) { + if (GBConversationalService.kmpSearch(typed, item) != -1) { result = item; } }); diff --git a/packages/basic.gblib/services/DialogKeywords.ts b/packages/basic.gblib/services/DialogKeywords.ts index 8bf7e5b6..9bc25d92 100644 --- a/packages/basic.gblib/services/DialogKeywords.ts +++ b/packages/basic.gblib/services/DialogKeywords.ts @@ -407,6 +407,10 @@ export class DialogKeywords { } + public getCoded(text){ + return Buffer.from(text).toString("base64"); + } + /** * Returns specified date week day in format 'Mon'. * diff --git a/packages/basic.gblib/services/GBVMService.ts b/packages/basic.gblib/services/GBVMService.ts index 523fa675..0f3b1ff3 100644 --- a/packages/basic.gblib/services/GBVMService.ts +++ b/packages/basic.gblib/services/GBVMService.ts @@ -179,10 +179,10 @@ export class GBVMService extends GBService { mobile = step ? this.userMobile(step) : sys().getRandomId(); from = mobile; ubound = function(array){return array.length}; - base64 = function(text){return new Buffer(text).toString("base64");} isarray = function(array){return Array.isArray(array) }; weekday = this.getWeekFromDate.bind(this); hour = this.getHourFromDate.bind(this); + base64 = this.getCoded; tolist = this.getToLst; headers = {}; data = {}; @@ -398,7 +398,7 @@ export class GBVMService extends GBService { }); code = code.replace(/(\w+)\s*\=\s*post\s*(.*),\s*(.*)/gi, ($0, $1, $2, $3) => { - return `${$1} = sys().httpPost (${$2}, ${$3})`; + return `${$1} = sys().postByHttp (${$2}, ${$3}, headers)`; }); code = code.replace(/(\w+)\s*\=\s*download\s*(.*),\s*(.*)/gi, ($0, $1, $2, $3) => { @@ -736,13 +736,14 @@ export class GBVMService extends GBService { // await insertion. code = code.replace(/this\./gm, 'await this.'); - code = code.replace(/function/gm, 'async function'); + code = code.replace(/\nfunction/i, 'async function'); code = code.replace('ubound = async', 'ubound ='); // TODO: Improve this. code = code.replace('hour = await', 'hour ='); // TODO: Improve this. code = code.replace('weekday = await', 'weekday ='); // TODO: Improve this. code = code.replace('tolist = await', 'tolist ='); // TODO: Improve this. code = code.replace('isarray = async', 'isarray ='); // TODO: Waiting for a compiler. code = code.replace('isArray = async', 'isarray ='); // TODO: Waiting for a compiler. + code = code.replace('base64 = await', 'base64 ='); // TODO: Waiting for a compiler. return code; } @@ -785,6 +786,7 @@ export class GBVMService extends GBService { const code = min.sandBoxMap[text]; try { + // SEE https://github.com/patriksimek/vm2 vm.runInContext(code, context); } catch (error) { throw new Error(`INVALID BASIC CODE: ${error.message} ${error.stack}`); diff --git a/packages/basic.gblib/services/SystemKeywords.ts b/packages/basic.gblib/services/SystemKeywords.ts index 4af3a555..27740b4f 100644 --- a/packages/basic.gblib/services/SystemKeywords.ts +++ b/packages/basic.gblib/services/SystemKeywords.ts @@ -1396,16 +1396,17 @@ export class SystemKeywords { * talk "The updated user area is" + user.area * */ - public async postByHttp(url: string, data) { + public async postByHttp(url: string, data, headers) { const options = { uri: url, json: true, - body: data + body: data, + headers: headers }; let result = await request.post(options); GBLog.info(`[POST]: ${url} (${data}): ${result}`); - return JSON.parse(result); + return typeof (result) === 'object' ? result : JSON.parse(result); } public async numberOnly(text: string) {