Skip to content

Commit 47df1f1

Browse files
fix(whatsapp.gblib): BASIC enabled with Promises.
1 parent fa9f260 commit 47df1f1

File tree

5 files changed

+151
-54
lines changed

5 files changed

+151
-54
lines changed

package-lock.json

Lines changed: 116 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
"azure-arm-search": "1.3.0-preview",
5959
"azure-arm-sql": "5.7.0",
6060
"azure-arm-website": "5.7.0",
61-
"azure-search-client": "^3.1.5",
61+
"azure-search-client": "3.1.5",
6262
"bluebird": "3.5.4",
6363
"body-parser": "1.19.0",
6464
"botbuilder": "4.4.0",
@@ -67,18 +67,18 @@
6767
"botbuilder-choices": "4.0.0-preview1.2",
6868
"botbuilder-dialogs": "4.4.0",
6969
"botbuilder-prompts": "4.0.0-preview1.2",
70-
"botlib": "1.2.2",
70+
"botlib": "1.2.3",
7171
"chai": "4.2.0",
7272
"child_process": "1.0.2",
7373
"chokidar": "3.0.0",
7474
"cli-spinner": "0.2.10",
75-
"commonmark": "^0.29.0",
75+
"commonmark": "0.29.0",
7676
"csv-parse": "4.4.1",
7777
"dotenv-extended": "2.4.0",
78-
"exceljs": "^1.15.0",
78+
"exceljs": "1.15.0",
7979
"express": "4.16.4",
8080
"express-promise-router": "3.0.3",
81-
"express-remove-route": "^1.0.0",
81+
"express-remove-route": "1.0.0",
8282
"fs-extra": "8.0.0",
8383
"ip": "1.1.5",
8484
"js-beautify": "1.10.0",
@@ -104,10 +104,10 @@
104104
"sequelize-typescript": "0.6.10",
105105
"shx": "0.3.2",
106106
"simple-git": "1.113.0",
107-
"sppull": "^2.4.1",
107+
"sppull": "2.4.1",
108108
"sqlite3": "4.0.8",
109109
"strict-password-generator": "1.1.2",
110-
"swagger-client": "^2.1.18",
110+
"swagger-client": "2.1.18",
111111
"tedious": "6.1.1",
112112
"temperature-js": "0.1.0",
113113
"ts-node": "8.1.0",
@@ -120,7 +120,7 @@
120120
"wait-until": "0.0.2",
121121
"walk-promise": "0.2.0",
122122
"winston": "3.2.1",
123-
"xlsx": "^0.15.1"
123+
"xlsx": "0.15.1"
124124
},
125125
"devDependencies": {
126126
"@semantic-release/changelog": "3.0.2",

packages/core.gbapp/services/GBAPIService.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,16 +132,16 @@ export class DialogClass {
132132
return this.internalSys;
133133
}
134134

135-
public async hear(cb) {
135+
public async hear(step, promise, previousResolve) {
136136
function random(low, high) {
137137
return Math.random() * (high - low) + low
138138
}
139-
const idCallback = random(0, 120000000);
140-
this.min.cbMap[idCallback] = cb;
141-
await this.step.beginDialog('/hear', { id: idCallback });
139+
const idPromise = random(0, 120000000);
140+
this.min.cbMap[idPromise] = promise;
141+
return await step.beginDialog('/hear', { id: idPromise, previousResolve: previousResolve });
142142
}
143143

144-
public async talk(text: string) {
145-
return await this.context.sendActivity(text);
144+
public async talk(step, text: string) {
145+
return await step.context.sendActivity(text);
146146
}
147147
}

packages/core.gbapp/services/GBMinService.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,9 @@ export class GBMinService {
195195
}
196196
GBServer.globals.minInstances.push(min);
197197

198-
// Install default VBA module.
199-
//this.deployer.deployPackage(min, 'packages/default.gbdialog');
198+
// Install default BASIC module.
199+
200+
this.deployer.deployPackage(min, 'packages/default.gbdialog');
200201

201202
// Call the loadBot context.activity for all packages.
202203
this.invokeLoadBot(GBServer.globals.appPackages, GBServer.globals.sysPackages, min, GBServer.globals.server);
@@ -537,16 +538,12 @@ export class GBMinService {
537538
return utterance.match(Messages[locale].global_quit);
538539
}
539540

540-
541541
const isVMCall = Object.keys(min.scriptMap).find(key => min.scriptMap[key] === context.activity.text) !== undefined;
542542

543543
if (isVMCall) {
544544
const mainMethod = context.activity.text;
545-
546-
min.sandBoxMap[mainMethod].context = context;
547-
min.sandBoxMap[mainMethod].step = step;
548545
min.sandBoxMap[mainMethod][mainMethod].bind(min.sandBoxMap[mainMethod]);
549-
await min.sandBoxMap[mainMethod][mainMethod]();
546+
await min.sandBoxMap[mainMethod][mainMethod](step);
550547
} else if (context.activity.text.charAt(0) === '/') {
551548
await step.beginDialog(context.activity.text);
552549

packages/core.gbapp/services/GBVMService.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ export class GBVMService extends GBService {
122122
});
123123

124124
code = code.replace(/(talk)(\s)(.*)/g, ($0, $1, $2, $3) => {
125-
return `talk (${$3})\n`;
125+
return `talk (step, ${$3})\n`;
126126
});
127127

128128
code = `${code}\n%>`;
@@ -144,7 +144,7 @@ export class GBVMService extends GBService {
144144
// Convert TS into JS.
145145
const tsfile: string = `${filename}.ts`;
146146
let tsCode: string = fs.readFileSync(tsfile, 'utf8');
147-
tsCode = tsCode.replace(/export.*\n/g, `export function ${mainName}() {`);
147+
tsCode = tsCode.replace(/export.*\n/g, `export function ${mainName}(step) { let resolve = undefined;`);
148148
fs.writeFileSync(tsfile, tsCode);
149149

150150
const tsc = new TSCompiler();
@@ -171,9 +171,12 @@ export class GBVMService extends GBService {
171171
// Writes async body.
172172

173173
const variable = match1[1]; // Construct variable = hear ().
174+
const promiseName = `promiseFor${variable}`;
174175

175176
parsedCode = code.substring(pos, pos + match1.index);
176-
parsedCode += `hear (async (${variable}) => {\n`;
177+
parsedCode += ``;
178+
parsedCode += `const ${promiseName}= async (step, ${variable}) => {`
179+
parsedCode += ` return new Promise(async (resolve) => {`
177180

178181
// Skips old construction and point to the async block.
179182

@@ -205,6 +208,8 @@ export class GBVMService extends GBService {
205208

206209
parsedCode += code.substring(start + match1[0].length + 1, pos + match1[0].length);
207210
parsedCode += '});\n';
211+
parsedCode += '}\n';
212+
parsedCode += `hear (step, ${promiseName}, resolve);\n`;
208213
parsedCode += code.substring(pos + match1[0].length);
209214

210215
// A interaction will be made for each hear.
@@ -252,15 +257,19 @@ export class GBVMService extends GBService {
252257
min.dialogs.add(
253258
new WaterfallDialog('/hear', [
254259
async step => {
255-
step.activeDialog.state.cbId = (step.options as any).id;
260+
step.activeDialog.state.options = {};
261+
step.activeDialog.state.options.cbId = (step.options as any).id;
262+
step.activeDialog.state.options.previousResolve = (step.options as any).previousResolve;
256263

257264
return await step.prompt('textPrompt', {});
258265
},
259266
async step => {
260-
const cbId = step.activeDialog.state.cbId;
261-
const cb = min.cbMap[cbId];
262-
cb.bind({ step: step, context: step.context });
263-
await cb(step.result);
267+
const cbId = step.activeDialog.state.options.cbId;
268+
const promise = min.cbMap[cbId];
269+
const res = await promise(step, step.result);
270+
if (step.activeDialog.state.options.previousResolve != undefined){
271+
step.activeDialog.state.options.previousResolve();
272+
}
264273
return await step.next();
265274
}
266275
])

0 commit comments

Comments
 (0)