fix(whatsapp.gblib): BASIC enabled with Promises.
This commit is contained in:
parent
fa9f2600a2
commit
47df1f154a
5 changed files with 150 additions and 53 deletions
139
package-lock.json
generated
139
package-lock.json
generated
|
@ -2919,7 +2919,7 @@
|
|||
"@types/node-fetch": "^1.6.7",
|
||||
"@types/uuid": "^3.4.3",
|
||||
"fetch-cookie": "^0.7.0",
|
||||
"fetch-ponyfill": "github:amarzavery/fetch-ponyfill#master",
|
||||
"fetch-ponyfill": "github:amarzavery/fetch-ponyfill#136e6f8192bdb2aa0b7983f0b3b4361c357be9db",
|
||||
"form-data": "^2.3.2",
|
||||
"is-buffer": "^2.0.0",
|
||||
"is-stream": "^1.1.0",
|
||||
|
@ -3241,7 +3241,7 @@
|
|||
"@types/node-fetch": "^1.6.7",
|
||||
"@types/uuid": "^3.4.3",
|
||||
"fetch-cookie": "^0.7.0",
|
||||
"fetch-ponyfill": "github:amarzavery/fetch-ponyfill#master",
|
||||
"fetch-ponyfill": "github:amarzavery/fetch-ponyfill#136e6f8192bdb2aa0b7983f0b3b4361c357be9db",
|
||||
"form-data": "^2.3.2",
|
||||
"is-buffer": "^2.0.0",
|
||||
"is-stream": "^1.1.0",
|
||||
|
@ -3367,6 +3367,30 @@
|
|||
"resolved": "https://registry.npmjs.org/botframework-schema/-/botframework-schema-4.4.0.tgz",
|
||||
"integrity": "sha512-3BWQEbArzHkw49BCdyNxqmSnLzkrL396Q0c+VcdabT3t75wV+dc4bwzSBuLfG0KW+fBjhSR4BXM8IQfnIZU0Vg=="
|
||||
},
|
||||
"botlib": {
|
||||
"version": "1.2.3",
|
||||
"resolved": "https://registry.npmjs.org/botlib/-/botlib-1.2.3.tgz",
|
||||
"integrity": "sha512-D4HmQ4YakjeUAqVESzSrbi3ZunUNWRab0wzhn0rIU3mIi61rxWgVhabx5OPDvy2Gqj4Nyk69Q9EF9Pv4uDo+Zg==",
|
||||
"requires": {
|
||||
"async": "2.6.2",
|
||||
"botbuilder": "4.4.0",
|
||||
"botbuilder-ai": "4.4.0",
|
||||
"botbuilder-azure": "4.4.0",
|
||||
"botbuilder-choices": "4.0.0-preview1.2",
|
||||
"botbuilder-dialogs": "4.4.0",
|
||||
"botbuilder-prompts": "4.0.0-preview1.2",
|
||||
"chrono-node": "1.3.11",
|
||||
"dotenv-extended": "2.4.0",
|
||||
"iconv-lite": "0.4.24",
|
||||
"ms": "2.1.1",
|
||||
"pragmatismo-io-framework": "1.0.19",
|
||||
"reflect-metadata": "0.1.13",
|
||||
"sequelize": "5.8.6",
|
||||
"sequelize-typescript": "0.6.10",
|
||||
"wait-until": "0.0.2",
|
||||
"winston": "3.2.1"
|
||||
}
|
||||
},
|
||||
"bottleneck": {
|
||||
"version": "2.18.1",
|
||||
"resolved": "https://registry.npmjs.org/bottleneck/-/bottleneck-2.18.1.tgz",
|
||||
|
@ -3802,6 +3826,21 @@
|
|||
"resolved": "https://registry.npmjs.org/chownr/-/chownr-1.1.1.tgz",
|
||||
"integrity": "sha512-j38EvO5+LHX84jlo6h4UzmOwi0UgW61WRyPtJz4qaadK5eY3BTS5TY/S1Stc3Uk2lIM6TPevAlULiEJwie860g=="
|
||||
},
|
||||
"chrono-node": {
|
||||
"version": "1.3.11",
|
||||
"resolved": "https://registry.npmjs.org/chrono-node/-/chrono-node-1.3.11.tgz",
|
||||
"integrity": "sha512-jDWRnY6nYvzfV3HPYBqo+tot7tcsUs9i3arGbMdI0TouPSXP2C2y/Ctp27rxKTQDi6yuTxAB2cw+Q6igGhOhdQ==",
|
||||
"requires": {
|
||||
"moment": "2.21.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"moment": {
|
||||
"version": "2.21.0",
|
||||
"resolved": "https://registry.npmjs.org/moment/-/moment-2.21.0.tgz",
|
||||
"integrity": "sha512-TCZ36BjURTeFTM/CwRcViQlfkMvL1/vFISuNLO5GkcVm1+QHfbSiNqZuWeMFjj1/3+uAjXswgRk30j1kkLYJBQ=="
|
||||
}
|
||||
}
|
||||
},
|
||||
"circular-json": {
|
||||
"version": "0.3.3",
|
||||
"resolved": "https://registry.npmjs.org/circular-json/-/circular-json-0.3.3.tgz",
|
||||
|
@ -14951,6 +14990,11 @@
|
|||
"esprima": "~4.0.0"
|
||||
}
|
||||
},
|
||||
"reduce-component": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/reduce-component/-/reduce-component-1.0.1.tgz",
|
||||
"integrity": "sha1-4Mk1QsV0UhvqE98PlIjtgqt3xdo="
|
||||
},
|
||||
"reflect-metadata": {
|
||||
"version": "0.1.13",
|
||||
"resolved": "https://registry.npmjs.org/reflect-metadata/-/reflect-metadata-0.1.13.tgz",
|
||||
|
@ -16540,20 +16584,21 @@
|
|||
}
|
||||
},
|
||||
"superagent": {
|
||||
"version": "2.3.0",
|
||||
"resolved": "https://registry.npmjs.org/superagent/-/superagent-2.3.0.tgz",
|
||||
"integrity": "sha1-cDUpoHFOV+EjlZ3e+84ZOy5Q0RU=",
|
||||
"version": "1.8.5",
|
||||
"resolved": "https://registry.npmjs.org/superagent/-/superagent-1.8.5.tgz",
|
||||
"integrity": "sha1-HA3cOvMOgOuE68BcshItqP6UC1U=",
|
||||
"requires": {
|
||||
"component-emitter": "^1.2.0",
|
||||
"cookiejar": "^2.0.6",
|
||||
"debug": "^2.2.0",
|
||||
"extend": "^3.0.0",
|
||||
"form-data": "1.0.0-rc4",
|
||||
"formidable": "^1.0.17",
|
||||
"methods": "^1.1.1",
|
||||
"mime": "^1.3.4",
|
||||
"qs": "^6.1.0",
|
||||
"readable-stream": "^2.0.5"
|
||||
"component-emitter": "~1.2.0",
|
||||
"cookiejar": "2.0.6",
|
||||
"debug": "2",
|
||||
"extend": "3.0.0",
|
||||
"form-data": "1.0.0-rc3",
|
||||
"formidable": "~1.0.14",
|
||||
"methods": "~1.1.1",
|
||||
"mime": "1.3.4",
|
||||
"qs": "2.3.3",
|
||||
"readable-stream": "1.0.27-1",
|
||||
"reduce-component": "1.0.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"async": {
|
||||
|
@ -16561,6 +16606,16 @@
|
|||
"resolved": "https://registry.npmjs.org/async/-/async-1.5.2.tgz",
|
||||
"integrity": "sha1-7GphrlZIDAw8skHJVhjiCJL5Zyo="
|
||||
},
|
||||
"component-emitter": {
|
||||
"version": "1.2.1",
|
||||
"resolved": "https://registry.npmjs.org/component-emitter/-/component-emitter-1.2.1.tgz",
|
||||
"integrity": "sha1-E3kY1teCg/ffemt8WmPhQOaUJeY="
|
||||
},
|
||||
"cookiejar": {
|
||||
"version": "2.0.6",
|
||||
"resolved": "https://registry.npmjs.org/cookiejar/-/cookiejar-2.0.6.tgz",
|
||||
"integrity": "sha1-Cr81atANHFohnYjURRgEbdAmrP4="
|
||||
},
|
||||
"debug": {
|
||||
"version": "2.6.9",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
|
||||
|
@ -16569,20 +16624,56 @@
|
|||
"ms": "2.0.0"
|
||||
}
|
||||
},
|
||||
"extend": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/extend/-/extend-3.0.0.tgz",
|
||||
"integrity": "sha1-WkdDU7nzNT3dgXbf03uRyDpG8dQ="
|
||||
},
|
||||
"form-data": {
|
||||
"version": "1.0.0-rc4",
|
||||
"resolved": "https://registry.npmjs.org/form-data/-/form-data-1.0.0-rc4.tgz",
|
||||
"integrity": "sha1-BaxrwiIntD5EYfSIFhVUaZ1Pi14=",
|
||||
"version": "1.0.0-rc3",
|
||||
"resolved": "https://registry.npmjs.org/form-data/-/form-data-1.0.0-rc3.tgz",
|
||||
"integrity": "sha1-01vGLn+8KTeuePlIqqDTjZBgdXc=",
|
||||
"requires": {
|
||||
"async": "^1.5.2",
|
||||
"async": "^1.4.0",
|
||||
"combined-stream": "^1.0.5",
|
||||
"mime-types": "^2.1.10"
|
||||
"mime-types": "^2.1.3"
|
||||
}
|
||||
},
|
||||
"formidable": {
|
||||
"version": "1.0.16",
|
||||
"resolved": "https://registry.npmjs.org/formidable/-/formidable-1.0.16.tgz",
|
||||
"integrity": "sha1-SRbP38TL7QILJXpqlQWpqzjCzQ4="
|
||||
},
|
||||
"isarray": {
|
||||
"version": "0.0.1",
|
||||
"resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz",
|
||||
"integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8="
|
||||
},
|
||||
"mime": {
|
||||
"version": "1.3.4",
|
||||
"resolved": "https://registry.npmjs.org/mime/-/mime-1.3.4.tgz",
|
||||
"integrity": "sha1-EV+eO2s9rylZmDyzjxSaLUDrXVM="
|
||||
},
|
||||
"ms": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
|
||||
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
|
||||
},
|
||||
"qs": {
|
||||
"version": "2.3.3",
|
||||
"resolved": "https://registry.npmjs.org/qs/-/qs-2.3.3.tgz",
|
||||
"integrity": "sha1-6eha2+ddoLvkyOBHaghikPhjtAQ="
|
||||
},
|
||||
"readable-stream": {
|
||||
"version": "1.0.27-1",
|
||||
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.0.27-1.tgz",
|
||||
"integrity": "sha1-a2eYPCA1fO/QfwFlABoW1xDZEHg=",
|
||||
"requires": {
|
||||
"core-util-is": "~1.0.0",
|
||||
"inherits": "~2.0.1",
|
||||
"isarray": "0.0.1",
|
||||
"string_decoder": "~0.10.x"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -16630,16 +16721,16 @@
|
|||
}
|
||||
},
|
||||
"swagger-client": {
|
||||
"version": "2.2.21",
|
||||
"resolved": "https://registry.npmjs.org/swagger-client/-/swagger-client-2.2.21.tgz",
|
||||
"integrity": "sha1-WWa+I0dyRm5EcW9l4yAIFm2u66Q=",
|
||||
"version": "2.1.18",
|
||||
"resolved": "https://registry.npmjs.org/swagger-client/-/swagger-client-2.1.18.tgz",
|
||||
"integrity": "sha1-0zrd7Li438Qjh931t1pAXlQ32M8=",
|
||||
"requires": {
|
||||
"btoa": "^1.1.2",
|
||||
"cookiejar": "^2.0.1",
|
||||
"js-yaml": "^3.3.0",
|
||||
"lodash-compat": "^3.5.0",
|
||||
"q": "^1.4.1",
|
||||
"superagent": "^2.2"
|
||||
"superagent": "^1.2"
|
||||
}
|
||||
},
|
||||
"symbol-observable": {
|
||||
|
|
16
package.json
16
package.json
|
@ -58,7 +58,7 @@
|
|||
"azure-arm-search": "1.3.0-preview",
|
||||
"azure-arm-sql": "5.7.0",
|
||||
"azure-arm-website": "5.7.0",
|
||||
"azure-search-client": "^3.1.5",
|
||||
"azure-search-client": "3.1.5",
|
||||
"bluebird": "3.5.4",
|
||||
"body-parser": "1.19.0",
|
||||
"botbuilder": "4.4.0",
|
||||
|
@ -67,18 +67,18 @@
|
|||
"botbuilder-choices": "4.0.0-preview1.2",
|
||||
"botbuilder-dialogs": "4.4.0",
|
||||
"botbuilder-prompts": "4.0.0-preview1.2",
|
||||
"botlib": "1.2.2",
|
||||
"botlib": "1.2.3",
|
||||
"chai": "4.2.0",
|
||||
"child_process": "1.0.2",
|
||||
"chokidar": "3.0.0",
|
||||
"cli-spinner": "0.2.10",
|
||||
"commonmark": "^0.29.0",
|
||||
"commonmark": "0.29.0",
|
||||
"csv-parse": "4.4.1",
|
||||
"dotenv-extended": "2.4.0",
|
||||
"exceljs": "^1.15.0",
|
||||
"exceljs": "1.15.0",
|
||||
"express": "4.16.4",
|
||||
"express-promise-router": "3.0.3",
|
||||
"express-remove-route": "^1.0.0",
|
||||
"express-remove-route": "1.0.0",
|
||||
"fs-extra": "8.0.0",
|
||||
"ip": "1.1.5",
|
||||
"js-beautify": "1.10.0",
|
||||
|
@ -104,10 +104,10 @@
|
|||
"sequelize-typescript": "0.6.10",
|
||||
"shx": "0.3.2",
|
||||
"simple-git": "1.113.0",
|
||||
"sppull": "^2.4.1",
|
||||
"sppull": "2.4.1",
|
||||
"sqlite3": "4.0.8",
|
||||
"strict-password-generator": "1.1.2",
|
||||
"swagger-client": "^2.1.18",
|
||||
"swagger-client": "2.1.18",
|
||||
"tedious": "6.1.1",
|
||||
"temperature-js": "0.1.0",
|
||||
"ts-node": "8.1.0",
|
||||
|
@ -120,7 +120,7 @@
|
|||
"wait-until": "0.0.2",
|
||||
"walk-promise": "0.2.0",
|
||||
"winston": "3.2.1",
|
||||
"xlsx": "^0.15.1"
|
||||
"xlsx": "0.15.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@semantic-release/changelog": "3.0.2",
|
||||
|
|
|
@ -132,16 +132,16 @@ export class DialogClass {
|
|||
return this.internalSys;
|
||||
}
|
||||
|
||||
public async hear(cb) {
|
||||
public async hear(step, promise, previousResolve) {
|
||||
function random(low, high) {
|
||||
return Math.random() * (high - low) + low
|
||||
}
|
||||
const idCallback = random(0, 120000000);
|
||||
this.min.cbMap[idCallback] = cb;
|
||||
await this.step.beginDialog('/hear', { id: idCallback });
|
||||
const idPromise = random(0, 120000000);
|
||||
this.min.cbMap[idPromise] = promise;
|
||||
return await step.beginDialog('/hear', { id: idPromise, previousResolve: previousResolve });
|
||||
}
|
||||
|
||||
public async talk(text: string) {
|
||||
return await this.context.sendActivity(text);
|
||||
public async talk(step, text: string) {
|
||||
return await step.context.sendActivity(text);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -195,8 +195,9 @@ export class GBMinService {
|
|||
}
|
||||
GBServer.globals.minInstances.push(min);
|
||||
|
||||
// Install default VBA module.
|
||||
//this.deployer.deployPackage(min, 'packages/default.gbdialog');
|
||||
// Install default BASIC module.
|
||||
|
||||
this.deployer.deployPackage(min, 'packages/default.gbdialog');
|
||||
|
||||
// Call the loadBot context.activity for all packages.
|
||||
this.invokeLoadBot(GBServer.globals.appPackages, GBServer.globals.sysPackages, min, GBServer.globals.server);
|
||||
|
@ -537,16 +538,12 @@ export class GBMinService {
|
|||
return utterance.match(Messages[locale].global_quit);
|
||||
}
|
||||
|
||||
|
||||
const isVMCall = Object.keys(min.scriptMap).find(key => min.scriptMap[key] === context.activity.text) !== undefined;
|
||||
|
||||
if (isVMCall) {
|
||||
const mainMethod = context.activity.text;
|
||||
|
||||
min.sandBoxMap[mainMethod].context = context;
|
||||
min.sandBoxMap[mainMethod].step = step;
|
||||
min.sandBoxMap[mainMethod][mainMethod].bind(min.sandBoxMap[mainMethod]);
|
||||
await min.sandBoxMap[mainMethod][mainMethod]();
|
||||
await min.sandBoxMap[mainMethod][mainMethod](step);
|
||||
} else if (context.activity.text.charAt(0) === '/') {
|
||||
await step.beginDialog(context.activity.text);
|
||||
|
||||
|
|
|
@ -122,7 +122,7 @@ export class GBVMService extends GBService {
|
|||
});
|
||||
|
||||
code = code.replace(/(talk)(\s)(.*)/g, ($0, $1, $2, $3) => {
|
||||
return `talk (${$3})\n`;
|
||||
return `talk (step, ${$3})\n`;
|
||||
});
|
||||
|
||||
code = `${code}\n%>`;
|
||||
|
@ -144,7 +144,7 @@ export class GBVMService extends GBService {
|
|||
// Convert TS into JS.
|
||||
const tsfile: string = `${filename}.ts`;
|
||||
let tsCode: string = fs.readFileSync(tsfile, 'utf8');
|
||||
tsCode = tsCode.replace(/export.*\n/g, `export function ${mainName}() {`);
|
||||
tsCode = tsCode.replace(/export.*\n/g, `export function ${mainName}(step) { let resolve = undefined;`);
|
||||
fs.writeFileSync(tsfile, tsCode);
|
||||
|
||||
const tsc = new TSCompiler();
|
||||
|
@ -171,9 +171,12 @@ export class GBVMService extends GBService {
|
|||
// Writes async body.
|
||||
|
||||
const variable = match1[1]; // Construct variable = hear ().
|
||||
const promiseName = `promiseFor${variable}`;
|
||||
|
||||
parsedCode = code.substring(pos, pos + match1.index);
|
||||
parsedCode += `hear (async (${variable}) => {\n`;
|
||||
parsedCode += ``;
|
||||
parsedCode += `const ${promiseName}= async (step, ${variable}) => {`
|
||||
parsedCode += ` return new Promise(async (resolve) => {`
|
||||
|
||||
// Skips old construction and point to the async block.
|
||||
|
||||
|
@ -205,6 +208,8 @@ export class GBVMService extends GBService {
|
|||
|
||||
parsedCode += code.substring(start + match1[0].length + 1, pos + match1[0].length);
|
||||
parsedCode += '});\n';
|
||||
parsedCode += '}\n';
|
||||
parsedCode += `hear (step, ${promiseName}, resolve);\n`;
|
||||
parsedCode += code.substring(pos + match1[0].length);
|
||||
|
||||
// A interaction will be made for each hear.
|
||||
|
@ -252,15 +257,19 @@ export class GBVMService extends GBService {
|
|||
min.dialogs.add(
|
||||
new WaterfallDialog('/hear', [
|
||||
async step => {
|
||||
step.activeDialog.state.cbId = (step.options as any).id;
|
||||
step.activeDialog.state.options = {};
|
||||
step.activeDialog.state.options.cbId = (step.options as any).id;
|
||||
step.activeDialog.state.options.previousResolve = (step.options as any).previousResolve;
|
||||
|
||||
return await step.prompt('textPrompt', {});
|
||||
},
|
||||
async step => {
|
||||
const cbId = step.activeDialog.state.cbId;
|
||||
const cb = min.cbMap[cbId];
|
||||
cb.bind({ step: step, context: step.context });
|
||||
await cb(step.result);
|
||||
const cbId = step.activeDialog.state.options.cbId;
|
||||
const promise = min.cbMap[cbId];
|
||||
const res = await promise(step, step.result);
|
||||
if (step.activeDialog.state.options.previousResolve != undefined){
|
||||
step.activeDialog.state.options.previousResolve();
|
||||
}
|
||||
return await step.next();
|
||||
}
|
||||
])
|
||||
|
|
Loading…
Add table
Reference in a new issue