diff --git a/packages/core.gbapp/services/GBAPIService.ts b/packages/core.gbapp/services/GBAPIService.ts index df91a70b..4c2802c1 100644 --- a/packages/core.gbapp/services/GBAPIService.ts +++ b/packages/core.gbapp/services/GBAPIService.ts @@ -40,8 +40,8 @@ import urlJoin = require('url-join'); import { GBAdminService } from '../../admin.gbapp/services/GBAdminService'; import { AzureDeployerService } from '../../azuredeployer.gbapp/services/AzureDeployerService'; import { GBDeployer } from './GBDeployer'; -const MicrosoftGraph = require("@microsoft/microsoft-graph-client"); -import { Messages } from "../strings"; +const MicrosoftGraph = require('@microsoft/microsoft-graph-client'); +import { Messages } from '../strings'; import { GBServer } from '../../../src/app'; const request = require('request-promise-native'); @@ -95,10 +95,10 @@ class SysClass { await timeout(seconds * 1000); } - public async save(file: string, ...args): Promise { + + public async set(file: string, address:string, value: any): Promise { try { - let token = - await this.min.adminService.acquireElevatedToken(this.min.instance.instanceId); + let token = await this.min.adminService.acquireElevatedToken(this.min.instance.instanceId); let siteId = process.env.STORAGE_SITE_ID; let libraryId = process.env.STORAGE_LIBRARY; @@ -111,16 +111,59 @@ class SysClass { const botId = this.min.instance.botId; const path = `/${botId}.gbai/${botId}.gbdata`; - let res = await client.api( - `https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${libraryId}/drive/root:${path}:/children`) + let res = await client + .api(`https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${libraryId}/drive/root:${path}:/children`) .get(); let document = res.value.filter(m => { - return m.name === file + return m.name === file; }); - await client.api( - `https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${libraryId}/drive/items/${document[0].id}/workbook/worksheets('Sheet1')/range(address='A1:Z1')/insert`) + if (document === undefined) { + throw `File '${file}' specified on save GBasic command SET not found. Check the .gbdata or the .gbdialog associated.`; + } + + let body = { values: [[]] }; + body.values[0][0] = value; + + let res2 = await client + .api( + `https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${libraryId}/drive/items/${document[0].id}/workbook/worksheets('Sheet1')/range(address='${address}')` + ) + .patch(body); + } catch (error) { + GBLog.error(`SAVE BASIC error: ${error.message}`); + throw error; + } + } + + public async save(file: string, ...args): Promise { + try { + let token = await this.min.adminService.acquireElevatedToken(this.min.instance.instanceId); + + let siteId = process.env.STORAGE_SITE_ID; + let libraryId = process.env.STORAGE_LIBRARY; + + let client = MicrosoftGraph.Client.init({ + authProvider: done => { + done(null, token); + } + }); + const botId = this.min.instance.botId; + const path = `/${botId}.gbai/${botId}.gbdata`; + + let res = await client + .api(`https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${libraryId}/drive/root:${path}:/children`) + .get(); + + let document = res.value.filter(m => { + return m.name === file; + }); + + await client + .api( + `https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${libraryId}/drive/items/${document[0].id}/workbook/worksheets('Sheet1')/range(address='A1:Z1')/insert` + ) .post({}); if (document === undefined) { @@ -130,27 +173,25 @@ class SysClass { throw `File '${file}' has a SAVE call with more than 27 arguments. Check the .gbdialog associated.`; } - let body = - { "values": [[]] }; + let body = { values: [[]] }; for (let index = 0; index < 26; index++) { body.values[0][index] = args[index]; } - let res2 = await client.api( - `https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${libraryId}/drive/items/${document[0].id}/workbook/worksheets('Sheet1')/range(address='A2:Z2')`) + let res2 = await client + .api( + `https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${libraryId}/drive/items/${document[0].id}/workbook/worksheets('Sheet1')/range(address='A2:Z2')` + ) .patch(body); } catch (error) { GBLog.error(`SAVE BASIC error: ${error.message}`); throw error; } - } - public async find(file: string, ...args): Promise { - - let token = - await this.min.adminService.acquireElevatedToken(this.min.instance.instanceId); + public async get(file: string, address: string): Promise { + let token = await this.min.adminService.acquireElevatedToken(this.min.instance.instanceId); let client = MicrosoftGraph.Client.init({ authProvider: done => { @@ -163,15 +204,55 @@ class SysClass { const path = `/${botId}.gbai/${botId}.gbdata`; try { - let res = await client.api( - `https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${libraryId}/drive/root:${path}:/children`) + let res = await client + .api(`https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${libraryId}/drive/root:${path}:/children`) .get(); - // Performs validation. let document = res.value.filter(m => { - return m.name === file + return m.name === file; + }); + + if (document === undefined) { + throw `File '${file}' specified on save GBasic command GET not found. Check the .gbdata or the .gbdialog associated.`; + } + + // Creates workbook session that will be discarded. + + let results = await client + .api( + `https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${libraryId}/drive/items/${document[0].id}/workbook/worksheets('Sheet1')/range(address='${address}')` + ) + .get(); + + return results.text[0][0]; + } catch (error) { + GBLog.error(error); + } + } + public async find(file: string, ...args): Promise { + let token = await this.min.adminService.acquireElevatedToken(this.min.instance.instanceId); + + let client = MicrosoftGraph.Client.init({ + authProvider: done => { + done(null, token); + } + }); + let siteId = process.env.STORAGE_SITE_ID; + let libraryId = process.env.STORAGE_LIBRARY; + const botId = this.min.instance.botId; + const path = `/${botId}.gbai/${botId}.gbdata`; + + try { + let res = await client + .api(`https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${libraryId}/drive/root:${path}:/children`) + .get(); + + // Performs validation. + + let document = res.value.filter(m => { + return m.name === file; }); if (document === undefined) { @@ -186,8 +267,10 @@ class SysClass { const filter = args[0].split('='); const columnName = filter[0]; const value = filter[1]; - let results = await client.api( - `https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${libraryId}/drive/items/${document[0].id}/workbook/worksheets('Sheet1')/range(address='A1:Z100')`) + let results = await client + .api( + `https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${libraryId}/drive/items/${document[0].id}/workbook/worksheets('Sheet1')/range(address='A1:Z100')` + ) .get(); let columnIndex = 0; @@ -206,8 +289,7 @@ class SysClass { } if (foundIndex === results.text.length) { return null; - } - else { + } else { let output = {}; const row = results.text[foundIndex]; for (let colIndex = 0; colIndex < row.length; colIndex++) { @@ -258,26 +340,40 @@ class SysClass { /** * Generic function to call any REST API. */ - public async httpGet(url: string, qs) { - + public async httpGet(url: string) { const options = { - uri: urlJoin(url, qs) + uri: url }; - return await request.get(options); + let result = await request.get(options); + GBLog.info(`[GET]: ${url} : ${result}`); + return JSON.parse(result); + } + + /** + * Generic function to call any REST API by POST. + */ + public async httpPost(url: string, data) { + const options = { + uri: url, + json: true, + body: data + }; + + let result = await request.post(options); + GBLog.info(`[POST]: ${url} (${data}): ${result}`); + return JSON.parse(result); } public async numberOnly(text: string) { - return text.replace(/\D/gi, ""); + return text.replace(/\D/gi, ''); } - } /** * Base services of conversation to be called by BASIC. */ export class DialogClass { - public min: GBMinInstance; public context: TurnContext; public step: WaterfallStepContext; @@ -289,49 +385,47 @@ export class DialogClass { } public static setup(bot: BotAdapter, min: GBMinInstance) { - min.dialogs.add(new WaterfallDialog('/gbasic-email', [ + min.dialogs.add( + new WaterfallDialog('/gbasic-email', [ + async step => { + const locale = step.context.activity.locale; + if ((step.options as any).ask) { + await min.conversationalService.sendText(min, step, Messages[locale].whats_email); + } + return await step.prompt('textPrompt', {}); + }, + async step => { + const locale = step.context.activity.locale; - async step => { - const locale = step.context.activity.locale; - if ((step.options as any).ask) { - await min.conversationalService.sendText(min, step, Messages[locale].whats_email); - } - return await step.prompt("textPrompt", {}); - }, - async step => { - const locale = step.context.activity.locale; + const extractEntity = text => { + return text.match(/([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9_-]+)/gi); + }; - const extractEntity = (text) => { - return text.match(/([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9_-]+)/gi); - } + const value = extractEntity(step.result); - const value = extractEntity(step.result); - - if (value === null) { - await min.conversationalService.sendText(min, step, Messages[locale].validation_enter_valid_email); - return await step.replaceDialog('/gbasic-email', { ask: true }); + if (value === null) { + await min.conversationalService.sendText(min, step, Messages[locale].validation_enter_valid_email); + return await step.replaceDialog('/gbasic-email', { ask: true }); + } else { + return await step.endDialog(value[0]); + } } - else { - return await step.endDialog(value[0]); - } - }])); + ]) + ); } public sys(): SysClass { return this.internalSys; } - public async getToday(step) { var d = new Date(), month = '' + (d.getMonth() + 1), day = '' + d.getDate(), year = d.getFullYear(); - if (month.length < 2) - month = '0' + month; - if (day.length < 2) - day = '0' + day; + if (month.length < 2) month = '0' + month; + if (day.length < 2) day = '0' + day; const locale = step.context.activity.locale; switch (locale) { @@ -348,8 +442,7 @@ export class DialogClass { public async sendFile(step, filename, caption) { let url = urlJoin(GBServer.globals.publicAddress, 'kb', this.min.botId + '.gbkb', 'assets', filename); - await this.min.conversationalService.sendFile(this.min, step, - null, url, caption); + await this.min.conversationalService.sendFile(this.min, step, null, url, caption); } public async getFrom(step) { @@ -361,16 +454,11 @@ export class DialogClass { } public async getUserMobile(step) { - - if (isNaN(step.context.activity.from.id)) - { - return ('No mobile available.'); + if (isNaN(step.context.activity.from.id)) { + return 'No mobile available.'; + } else { + return step.context.activity.from.id; } - else - { - return (step.context.activity.from.id); - } - } public async askEmail(step) { @@ -379,7 +467,7 @@ export class DialogClass { public async hear(step, promise, previousResolve) { function random(low, high) { - return Math.random() * (high - low) + low + return Math.random() * (high - low) + low; } const idPromise = random(0, 120000000); this.min.cbMap[idPromise] = {}; @@ -388,8 +476,7 @@ export class DialogClass { const opts = { id: idPromise, previousResolve: previousResolve }; if (previousResolve !== undefined) { previousResolve(opts); - } - else { + } else { await step.beginDialog('/hear', opts); } } diff --git a/packages/core.gbapp/services/GBConversationalService.ts b/packages/core.gbapp/services/GBConversationalService.ts index 2e6f5772..37734a90 100644 --- a/packages/core.gbapp/services/GBConversationalService.ts +++ b/packages/core.gbapp/services/GBConversationalService.ts @@ -250,9 +250,7 @@ export class GBConversationalService { const params = { audio: data, contentType: 'audio/l16; rate=44100', - model: "pt-BR_BroadbandModel", - keywords: ['azul', 'céu', 'sol'], - keywordsThreshold: 0.5 + model: "pt-BR_BroadbandModel" }; speechToText diff --git a/packages/core.gbapp/services/GBDeployer.ts b/packages/core.gbapp/services/GBDeployer.ts index 1aaa78dc..ff00f0af 100644 --- a/packages/core.gbapp/services/GBDeployer.ts +++ b/packages/core.gbapp/services/GBDeployer.ts @@ -55,7 +55,7 @@ import { GBConfigService } from './GBConfigService'; import { GBImporter } from './GBImporterService'; import { GBVMService } from './GBVMService'; import { CollectionUtil } from 'pragmatismo-io-framework'; -const MicrosoftGraph = require("@microsoft/microsoft-graph-client"); +const MicrosoftGraph = require('@microsoft/microsoft-graph-client'); /** * @@ -74,13 +74,7 @@ export class GBDeployer implements IGBDeployer { } public static getConnectionStringFromInstance(instance: IGBInstance) { - return `Server=tcp:${instance.storageServer}.database.windows.net,1433;Database=${ - instance.storageName - };User ID=${ - instance.storageUsername - };Password=${ - instance.storagePassword - };Trusted_Connection=False;Encrypt=True;Connection Timeout=30;`; + return `Server=tcp:${instance.storageServer}.database.windows.net,1433;Database=${instance.storageName};User ID=${instance.storageUsername};Password=${instance.storagePassword};Trusted_Connection=False;Encrypt=True;Connection Timeout=30;`; } /** @@ -110,9 +104,17 @@ export class GBDeployer implements IGBDeployer { const dirs = getDirectories(path); await CollectionUtil.asyncForEach(dirs, async element => { element = element.toLowerCase(); + if (element === '.') { GBLog.info(`Ignoring ${element}...`); } else { + const name = Path.basename(element).toLowerCase(); + + if (process.env.GBAPP_SKIP && (process.env.GBAPP_SKIP.toLowerCase().indexOf(name) !== -1 || + process.env.GBAPP_SKIP === "true")) { + return; + } + if (element.endsWith('.gbot')) { botPackages.push(element); } else if (element.endsWith('.gbapp') || element.endsWith('.gblib')) { @@ -148,34 +150,25 @@ export class GBDeployer implements IGBDeployer { GBLog.info(`App Package deployment done.`); - ({ generalPackages } = await this.deployDataPackages( - - core, - botPackages, - _this, - generalPackages - )); - + ({ generalPackages } = await this.deployDataPackages(core, botPackages, _this, generalPackages)); } public async deployBlankBot(botId: string) { let instance = await this.importer.createBotInstance(botId); const bootInstance = GBServer.globals.bootInstance; - const accessToken = await GBServer.globals.minBoot.adminService - .acquireElevatedToken(bootInstance.instanceId); + const accessToken = await GBServer.globals.minBoot.adminService.acquireElevatedToken(bootInstance.instanceId); const service = new AzureDeployerService(this); let application = await service.createApplication(accessToken, botId); instance.marketplaceId = (application as any).appId; - instance.marketplacePassword = await service.createApplicationSecret( - accessToken, (application as any).id); + instance.marketplacePassword = await service.createApplicationSecret(accessToken, (application as any).id); instance.adminPass = GBAdminService.getRndPassword(); instance.title = botId; instance.activationCode = instance.botId; instance.state = 'active'; - instance.nlpScore = 0.80; // TODO: Migrate to Excel Config.xlsx. + instance.nlpScore = 0.8; // TODO: Migrate to Excel Config.xlsx. instance.searchScore = 0.45; instance.whatsappServiceKey = bootInstance.whatsappServiceKey; instance.whatsappServiceNumber = bootInstance.whatsappServiceNumber; @@ -195,7 +188,6 @@ export class GBDeployer implements IGBDeployer { */ public async deployBotFull(instance: IGBInstance, publicAddress: string): Promise { - const service = new AzureDeployerService(this); const username = GBConfigService.get('CLOUD_USERNAME'); const password = GBConfigService.get('CLOUD_PASSWORD'); @@ -211,9 +203,7 @@ export class GBDeployer implements IGBDeployer { instance.description, `${publicAddress}/api/messages/${instance.botId}` ); - } else { - let botId = GBConfigService.get('BOT_ID'); let bootInstance = await this.core.loadInstanceByBotId(botId); @@ -251,7 +241,6 @@ export class GBDeployer implements IGBDeployer { await GBServer.globals.minService.mountBot(instance); } return await this.core.saveInstance(instance); - } /** @@ -259,16 +248,13 @@ export class GBDeployer implements IGBDeployer { */ public async deployBotFromLocalPath(localPath: string, publicAddress: string): Promise { - const packageName = Path.basename(localPath); let instance = await this.importer.importIfNotExistsBotPackage(undefined, packageName, localPath); this.deployBotFull(instance, publicAddress); } public async loadParamsFromExcel(min: GBMinInstance): Promise { - - let token = - await min.adminService.acquireElevatedToken(min.instance.instanceId); + let token = await min.adminService.acquireElevatedToken(min.instance.instanceId); let siteId = process.env.STORAGE_SITE_ID; let libraryId = process.env.STORAGE_LIBRARY; @@ -281,15 +267,14 @@ export class GBDeployer implements IGBDeployer { const botId = min.instance.botId; const path = `/${botId}.gbai/${botId}.gbot`; - let res = await client.api( - `https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${libraryId}/drive/root:${path}:/children`) + let res = await client + .api(`https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${libraryId}/drive/root:${path}:/children`) .get(); - // Performs validation. let document = res.value.filter(m => { - return m.name === "Config.xlsx" + return m.name === 'Config.xlsx'; }); if (document === undefined || document.length === 0) { GBLog.info(`Config.xlsx not found on .bot folder, check the package.`); @@ -298,14 +283,16 @@ export class GBDeployer implements IGBDeployer { // Creates workbook session that will be discarded. - let results = await client.api( - `https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${libraryId}/drive/items/${document[0].id}/workbook/worksheets('General')/range(address='A7:B100')`) + let results = await client + .api( + `https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${libraryId}/drive/items/${document[0].id}/workbook/worksheets('General')/range(address='A7:B100')` + ) .get(); let index = 0; let obj = {}; for (; index < results.text.length; index++) { - if (results.text[index][0] === "") { + if (results.text[index][0] === '') { return obj; } obj[results.text[index][0]] = results.text[index][1]; @@ -313,7 +300,6 @@ export class GBDeployer implements IGBDeployer { return obj; } - /** * UndDeploys a bot to the storage. */ @@ -324,11 +310,7 @@ export class GBDeployer implements IGBDeployer { const group = GBConfigService.get('CLOUD_GROUP'); if (await service.botExists(botId)) { - - await service.deleteBot( - botId, group - ); - + await service.deleteBot(botId, group); } GBServer.globals.minService.unmountBot(botId); await this.core.deleteInstance(botId); @@ -353,7 +335,7 @@ export class GBDeployer implements IGBDeployer { } }); - // TODO: Today a download only approach is used. + // TODO: Today a download only approach is used. } public async deployPackage(min: GBMinInstance, localPath: string) { @@ -366,20 +348,22 @@ export class GBDeployer implements IGBDeployer { // .gbapp package or platform package checking. await CollectionUtil.asyncForEach(min.appPackages, async (e: IGBPackage) => { - if (pck = await e.onExchangeData(min, "handlePackage", { - name: localPath, - createPackage: async (packageName) => { - return await _this.deployPackageToStorage(min.instance.instanceId, packageName); - }, updatePackage: async (p: GuaribasPackage) => { - p.save(); - } - })) { + if ( + (pck = await e.onExchangeData(min, 'handlePackage', { + name: localPath, + createPackage: async packageName => { + return await _this.deployPackageToStorage(min.instance.instanceId, packageName); + }, + updatePackage: async (p: GuaribasPackage) => { + p.save(); + } + })) + ) { handled = true; } }); if (handled) { - return pck; } @@ -445,7 +429,6 @@ export class GBDeployer implements IGBDeployer { return await service.undeployKbFromStorage(instance, this, p.packageId); case '.gbui': - break; case '.gbtheme': @@ -457,10 +440,8 @@ export class GBDeployer implements IGBDeployer { break; case '.gblib': - break; case '.gbapp': - break; default: const err = GBError.create(`Unhandled package type: ${packageType}.`); @@ -531,7 +512,6 @@ export class GBDeployer implements IGBDeployer { } private async deployDataPackages( - core: IGBCoreService, botPackages: string[], _this: this, @@ -557,16 +537,18 @@ export class GBDeployer implements IGBDeployer { const instances = core.loadInstances(); await CollectionUtil.asyncForEach(instances, async instance => { - this.mountGBKBAssets(`{instance.botId}.gbkb`, instance.botId, `{instance.botId}.gbkb`); }); GBLog.info(`Package deployment done.`); - return { generalPackages}; + return { generalPackages }; } public mountGBKBAssets(packageName: any, botId: string, filename: string) { - GBServer.globals.server.use(`/kb/${botId}.gbai/${packageName}/subjects`, express.static(urlJoin(filename, 'subjects'))); + GBServer.globals.server.use( + `/kb/${botId}.gbai/${packageName}/subjects`, + express.static(urlJoin(filename, 'subjects')) + ); GBServer.globals.server.use(`/kb/${botId}.gbai/${packageName}/assets`, express.static(urlJoin(filename, 'assets'))); GBServer.globals.server.use(`/kb/${botId}.gbai/${packageName}/images`, express.static(urlJoin(filename, 'images'))); GBServer.globals.server.use(`/kb/${botId}.gbai/${packageName}/audios`, express.static(urlJoin(filename, 'audios'))); @@ -575,7 +557,18 @@ export class GBDeployer implements IGBDeployer { } private isSystemPackage(name: string): Boolean { - const names = ['analytics.gblib', 'console.gblib', 'security.gbapp', 'whatsapp.gblib', 'sharepoint.gblib', 'core.gbapp', 'admin.gbapp', 'azuredeployer.gbapp', 'customer-satisfaction.gbapp', 'kb.gbapp']; + const names = [ + 'analytics.gblib', + 'console.gblib', + 'security.gbapp', + 'whatsapp.gblib', + 'sharepoint.gblib', + 'core.gbapp', + 'admin.gbapp', + 'azuredeployer.gbapp', + 'customer-satisfaction.gbapp', + 'kb.gbapp' + ]; return names.indexOf(name) > -1; } @@ -587,7 +580,6 @@ export class GBDeployer implements IGBDeployer { // Skips .gbapp inside deploy folder. if (this.isSystemPackage(filenameOnly) === false) { - appPackagesProcessed = await this.callGBAppCompiler(e, core, appPackages, appPackagesProcessed); } }); @@ -595,11 +587,15 @@ export class GBDeployer implements IGBDeployer { return appPackagesProcessed; } - public async callGBAppCompiler(gbappPath: string, core: IGBCoreService, - appPackages: any[] = undefined, appPackagesProcessed: number = 0) { + public async callGBAppCompiler( + gbappPath: string, + core: IGBCoreService, + appPackages: any[] = undefined, + appPackagesProcessed: number = 0 + ) { GBLog.info(`Deploying General Bots Application (.gbapp) or Library (.gblib): ${Path.basename(gbappPath)}...`); let folder = Path.join(gbappPath, 'node_modules'); - if (process.env.GBAPP_DISABLE_COMPILE !== "true") { + if (process.env.GBAPP_DISABLE_COMPILE !== 'true') { if (!Fs.existsSync(folder)) { GBLog.info(`Installing modules for ${gbappPath}...`); child_process.execSync('npm install', { cwd: gbappPath }); @@ -607,7 +603,7 @@ export class GBDeployer implements IGBDeployer { } folder = Path.join(gbappPath, 'dist'); try { - if (process.env.GBAPP_DISABLE_COMPILE !== "true") { + if (process.env.GBAPP_DISABLE_COMPILE !== 'true') { GBLog.info(`Compiling: ${gbappPath}.`); child_process.execSync(Path.join(process.env.PWD, 'node_modules/.bin/tsc'), { cwd: gbappPath }); } @@ -623,8 +619,7 @@ export class GBDeployer implements IGBDeployer { GBLog.info(`.gbapp or .gblib deployed: ${gbappPath}.`); appPackagesProcessed++; - } - catch (error) { + } catch (error) { GBLog.error(`Error compiling package, message: ${error.message}\n${error.stack}`); if (error.stdout) { GBLog.error(`Error compiling package, stdout: ${gbappPath}:\n${error.stdout.toString()}`); diff --git a/packages/core.gbapp/services/GBMinService.ts b/packages/core.gbapp/services/GBMinService.ts index 4cf808c4..88db562f 100644 --- a/packages/core.gbapp/services/GBMinService.ts +++ b/packages/core.gbapp/services/GBMinService.ts @@ -519,8 +519,18 @@ export class GBMinService { } private async invokeLoadBot(appPackages: IGBPackage[], sysPackages: IGBPackage[], min: GBMinInstance) { - await CollectionUtil.asyncForEach(sysPackages, async e => { - await e.loadBot(min); + await CollectionUtil.asyncForEach(sysPackages, async p => { + p.sysPackages = sysPackages; + if (p.getDialogs !== undefined) { + const dialogs = await p.getDialogs(min); + if (dialogs !== undefined) { + dialogs.forEach(dialog => { + min.dialogs.add(new WaterfallDialog(dialog.id, dialog.waterfall)); + }); + } + } + + await p.loadBot(min); }); await CollectionUtil.asyncForEach(appPackages, async p => { diff --git a/packages/core.gbapp/services/GBVMService.ts b/packages/core.gbapp/services/GBVMService.ts index a6074d42..05803183 100644 --- a/packages/core.gbapp/services/GBVMService.ts +++ b/packages/core.gbapp/services/GBVMService.ts @@ -137,6 +137,12 @@ export class GBVMService extends GBService { reject(error); } else { + text = text.replace('“', '\"'); + text = text.replace('”', '\"'); + text = text.replace('‘', '\''); + text = text.replace('’', '\''); + + resolve(text); } }); @@ -157,8 +163,8 @@ export class GBVMService extends GBService { from = this.getFrom(step) today = this.getToday(step) id = sys().getRandomId() - username = this.getUserName(); - mobile = this.getUserMobile(); + username = this.getUserName(step); + mobile = this.getUserMobile(step); ${code} `; @@ -183,8 +189,12 @@ export class GBVMService extends GBService { return `let stock = sys().getStock(${$2})`; }); - code = code.replace(/(get)(\s)(.*)/gi, ($0, $1, $2) => { - return `sys().httpGet (${$2})`; + code = code.replace(/(\w+)\s*\=\s*get\s(.*)/gi, ($0, $1, $2) => { + return `let ${$1} = sys().httpGet (${$2})`; + }); + + code = code.replace(/(\w+)\s*\=\s*post\s*(.*),\s*(.*)/gi, ($0, $1, $2, $3) => { + return `let ${$1} = sys().httpPost (${$2}, ${$3})`; }); code = code.replace(/(create a bot farm using)(\s)(.*)/gi, ($0, $1, $2, $3) => {