From 367e45f5f55c5c841500693c162ca231ca53e023 Mon Sep 17 00:00:00 2001 From: Rodrigo Rodriguez Date: Tue, 20 Aug 2024 15:26:07 -0300 Subject: [PATCH] new(all): TRUE multicloud. --- packages/core.gbapp/services/GBMinService.ts | 18 ++++++++-------- src/app.ts | 4 ++-- src/util.ts | 22 +++++++++++++------- 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/packages/core.gbapp/services/GBMinService.ts b/packages/core.gbapp/services/GBMinService.ts index ec5a8a7d..179c7c83 100644 --- a/packages/core.gbapp/services/GBMinService.ts +++ b/packages/core.gbapp/services/GBMinService.ts @@ -173,8 +173,9 @@ export class GBMinService { await CollectionUtil.asyncForEach( instances, (async instance => { - - startRouter(GBServer.globals.server, instance.botId); + if (!GBConfigService.get('STORAGE_NAME')) { + startRouter(GBServer.globals.server, instance.botId); + } try { GBLog.info(`Mounting ${instance.botId}...`); @@ -284,7 +285,7 @@ export class GBMinService { const gbai = DialogKeywords.getGBAIPath(min.botId); let dir = `work/${gbai}/cache`; const botId = gbai.replace(/\.[^/.]+$/, ''); - + if (!Fs.existsSync(dir)) { mkdirp.sync(dir); } @@ -677,12 +678,12 @@ export class GBMinService { if (!theme) { theme = `default.gbtheme`; } - + let config = { instanceId: instance.instanceId, botId: botId, theme: theme, - speechToken: speechToken, + speechToken: speechToken, authenticatorTenant: instance.authenticatorTenant, authenticatorClientId: instance.marketplaceId, paramLogoImageUrl: this.core.getParam(instance, 'Logo Image Url', null), @@ -699,8 +700,8 @@ export class GBMinService { config['domain'] = `http://localhost:${process.env.PORT}/directline/${botId}`; } else { const webchatTokenContainer = await this.getWebchatToken(instance); - config['conversationId']= webchatTokenContainer.conversationId, - config['webchatToken'] = webchatTokenContainer.token; + (config['conversationId'] = webchatTokenContainer.conversationId), + (config['webchatToken'] = webchatTokenContainer.token); } res.send(JSON.stringify(config)); @@ -844,8 +845,7 @@ export class GBMinService { GBServer.globals.minBoot = min; GBServer.globals.minBoot.instance.marketplaceId = GBConfigService.get('MARKETPLACE_ID'); GBServer.globals.minBoot.instance.marketplacePassword = GBConfigService.get('MARKETPLACE_SECRET'); - } - else{ + } else { url = `/api/messages`; GBServer.globals.server.post(url, receiver); } diff --git a/src/app.ts b/src/app.ts index 0fa81b72..6938dca6 100644 --- a/src/app.ts +++ b/src/app.ts @@ -124,7 +124,7 @@ export class GBServer { process.on('uncaughtException', (err, p) => { GBLogEx.error( 0, - `GBEXCEPTION: ${GBUtil.toYAML(JSON.parse(JSON.stringify(err, Object.getOwnPropertyNames(err))))}` + `GBEXCEPTION: ${GBUtil.toYAML(err)}` ); }); @@ -140,7 +140,7 @@ export class GBServer { if (!bypass) { GBLogEx.error( 0, - `GBREJECTION: ${GBUtil.toYAML(JSON.parse(JSON.stringify(err, Object.getOwnPropertyNames(err))))}` + `GBREJECTION: ${GBUtil.toYAML(err)}` ); } }); diff --git a/src/util.ts b/src/util.ts index a418284f..ca2dadc1 100644 --- a/src/util.ts +++ b/src/util.ts @@ -68,14 +68,13 @@ export class GBUtil { } public static async getDirectLineClient(min) { - let config = { - url: `http://127.0.0.1:${GBConfigService.getServerPort()}/api/messages`, + url: `http://127.0.0.1:${GBConfigService.getServerPort()}/api/messages`, spec: JSON.parse(Fs.readFileSync('directline-3.0.json', 'utf8')), requestInterceptor: req => { req.headers['Authorization'] = `Bearer ${min.instance.webchatKey}`; } - }; + }; if (!GBConfigService.get('STORAGE_NAME')) { config['spec'].servers = [{ url: `http://127.0.0.1:${GBConfigService.getServerPort()}/api/messages` }]; config['openapi'] = '3.0.0'; @@ -83,11 +82,18 @@ export class GBUtil { return await new SwaggerClient(config); } - public static toYAML(json) { - const doc = new YAML.Document(); - doc.contents = json; - return doc.toString(); - } + public static toYAML(data) { + const extractProps = (obj) => { + return Object.getOwnPropertyNames(obj).reduce((acc, key) => { + const value = obj[key]; + acc[key] = value && typeof value === 'object' && !Array.isArray(value) ? extractProps(value) : value; + return acc; + }, {}); + }; + + const extractedError = extractProps(data); + return YAML.stringify(extractedError); +} public static sleep(ms) { return new Promise(resolve => {