diff --git a/packages/basic.gblib/services/GBVMService.ts b/packages/basic.gblib/services/GBVMService.ts index aaeffdd9..1a972bea 100644 --- a/packages/basic.gblib/services/GBVMService.ts +++ b/packages/basic.gblib/services/GBVMService.ts @@ -274,17 +274,22 @@ export class GBVMService extends GBService { } if (text) { - text = text.replace('¨', '"'); - text = text.replace('“', '"'); - text = text.replace('”', '"'); - text = text.replace('‘', "'"); - text = text.replace('’', "'"); + text = GBVMService.normalizeQuotes(text); } resolve(text); }); }); } + public static normalizeQuotes(text: any) { + text = text.replace('¨', '"'); + text = text.replace('“', '"'); + text = text.replace('”', '"'); + text = text.replace('‘', "'"); + text = text.replace('’', "'"); + return text; + } + /** * Converts General Bots BASIC * @@ -319,7 +324,14 @@ export class GBVMService extends GBService { /** * Executes the converted JavaScript from BASIC code inside execution context. */ - public static async callVM(text: string, min: GBMinInstance, step, user:GuaribasUser, deployer: GBDeployer, debug: boolean = false) { + public static async callVM( + text: string, + min: GBMinInstance, + step, + user: GuaribasUser, + deployer: GBDeployer, + debug: boolean = false + ) { // Creates a class DialogKeywords which is the *this* pointer // in BASIC. @@ -331,17 +343,18 @@ export class GBVMService extends GBService { GBConfigService.get('DEFAULT_CONTENT_LANGUAGE') ); + // TODO: https://github.com/GeneralBots/BotServer/issues/217 // Auto-NLP generates BASIC variables related to entities. - if (step && step.context.activity['originalText']) { - const entities = await min['nerEngine'].findEntities(step.context.activity['originalText'], contentLocale); + // if (step && step.context.activity['originalText'] && min['nerEngine']) { + // const entities = await min['nerEngine'].findEntities(step.context.activity['originalText'], contentLocale); - for (let i = 0; i < entities.length; i++) { - const v = entities[i]; - const variableName = `${v.entity}`; - sandbox[variableName] = v.option; - } - } + // for (let i = 0; i < entities.length; i++) { + // const v = entities[i]; + // const variableName = `${v.entity}`; + // sandbox[variableName] = v.option; + // } + // } const botId = min.botId; const gbdialogPath = urlJoin(process.cwd(), 'work', `${botId}.gbai`, `${botId}.gbdialog`); diff --git a/packages/core.gbapp/services/GBSSR.ts b/packages/core.gbapp/services/GBSSR.ts index ef216046..5e33cfc9 100644 --- a/packages/core.gbapp/services/GBSSR.ts +++ b/packages/core.gbapp/services/GBSSR.ts @@ -272,7 +272,10 @@ export class GBSSR { // Reads from static HTML when a bot is crawling. const botId = req.originalUrl ? req.originalUrl.substr(1) : GBServer.globals.minInstances[0].botId; // TODO: Get only bot. - const min: GBMinInstance = GBServer.globals.minInstances.filter(p => p.instance.botId === botId)[0]; + let min: GBMinInstance = req.url === '/'? + GBServer.globals.minInstances[0]: + GBServer.globals.minInstances.filter(p => p.instance.botId === botId)[0]; + if (min && req.originalUrl && prerender && exclude) { const path = Path.join( process.env.PWD, @@ -285,16 +288,26 @@ export class GBSSR { res.status(200).send(html); return true; } else { + const path = Path.join( process.env.PWD, GBDeployer.deployFolder, GBMinService.uiPackage, 'build', - min ? 'index.html' : req.url - ); - + min ? `index.html` : req.url + ); if (Fs.existsSync(path)) { - res.sendFile(path); + if (min){ + let html = Fs.readFileSync(path, 'utf8'); + html = html.replace(/\{botId\}/gi, min.botId); + html = html.replace(/\{theme\}/gi, min.instance.theme); + html = html.replace(/\{title\}/gi, min.instance.title); + res.send(html).end(); + } + else + { + res.sendFile(path); + } return true; } else { GBLogEx.info(min, `HTTP 404: ${req.url}.`); diff --git a/packages/default.gbui/public/index.html b/packages/default.gbui/public/index.html index bd3f7602..af8a7119 100644 --- a/packages/default.gbui/public/index.html +++ b/packages/default.gbui/public/index.html @@ -38,11 +38,18 @@ - - + + + + + + + + + -