new(all): TRUE multicloud.

This commit is contained in:
Rodrigo Rodriguez 2024-08-20 15:26:07 -03:00
parent 3d1624ac23
commit 367e45f5f5
3 changed files with 25 additions and 19 deletions

View file

@ -173,8 +173,9 @@ export class GBMinService {
await CollectionUtil.asyncForEach( await CollectionUtil.asyncForEach(
instances, instances,
(async instance => { (async instance => {
if (!GBConfigService.get('STORAGE_NAME')) {
startRouter(GBServer.globals.server, instance.botId); startRouter(GBServer.globals.server, instance.botId);
}
try { try {
GBLog.info(`Mounting ${instance.botId}...`); GBLog.info(`Mounting ${instance.botId}...`);
@ -284,7 +285,7 @@ export class GBMinService {
const gbai = DialogKeywords.getGBAIPath(min.botId); const gbai = DialogKeywords.getGBAIPath(min.botId);
let dir = `work/${gbai}/cache`; let dir = `work/${gbai}/cache`;
const botId = gbai.replace(/\.[^/.]+$/, ''); const botId = gbai.replace(/\.[^/.]+$/, '');
if (!Fs.existsSync(dir)) { if (!Fs.existsSync(dir)) {
mkdirp.sync(dir); mkdirp.sync(dir);
} }
@ -677,12 +678,12 @@ export class GBMinService {
if (!theme) { if (!theme) {
theme = `default.gbtheme`; theme = `default.gbtheme`;
} }
let config = { let config = {
instanceId: instance.instanceId, instanceId: instance.instanceId,
botId: botId, botId: botId,
theme: theme, theme: theme,
speechToken: speechToken, speechToken: speechToken,
authenticatorTenant: instance.authenticatorTenant, authenticatorTenant: instance.authenticatorTenant,
authenticatorClientId: instance.marketplaceId, authenticatorClientId: instance.marketplaceId,
paramLogoImageUrl: this.core.getParam(instance, 'Logo Image Url', null), 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}`; config['domain'] = `http://localhost:${process.env.PORT}/directline/${botId}`;
} else { } else {
const webchatTokenContainer = await this.getWebchatToken(instance); const webchatTokenContainer = await this.getWebchatToken(instance);
config['conversationId']= webchatTokenContainer.conversationId, (config['conversationId'] = webchatTokenContainer.conversationId),
config['webchatToken'] = webchatTokenContainer.token; (config['webchatToken'] = webchatTokenContainer.token);
} }
res.send(JSON.stringify(config)); res.send(JSON.stringify(config));
@ -844,8 +845,7 @@ export class GBMinService {
GBServer.globals.minBoot = min; GBServer.globals.minBoot = min;
GBServer.globals.minBoot.instance.marketplaceId = GBConfigService.get('MARKETPLACE_ID'); GBServer.globals.minBoot.instance.marketplaceId = GBConfigService.get('MARKETPLACE_ID');
GBServer.globals.minBoot.instance.marketplacePassword = GBConfigService.get('MARKETPLACE_SECRET'); GBServer.globals.minBoot.instance.marketplacePassword = GBConfigService.get('MARKETPLACE_SECRET');
} } else {
else{
url = `/api/messages`; url = `/api/messages`;
GBServer.globals.server.post(url, receiver); GBServer.globals.server.post(url, receiver);
} }

View file

@ -124,7 +124,7 @@ export class GBServer {
process.on('uncaughtException', (err, p) => { process.on('uncaughtException', (err, p) => {
GBLogEx.error( GBLogEx.error(
0, 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) { if (!bypass) {
GBLogEx.error( GBLogEx.error(
0, 0,
`GBREJECTION: ${GBUtil.toYAML(JSON.parse(JSON.stringify(err, Object.getOwnPropertyNames(err))))}` `GBREJECTION: ${GBUtil.toYAML(err)}`
); );
} }
}); });

View file

@ -68,14 +68,13 @@ export class GBUtil {
} }
public static async getDirectLineClient(min) { public static async getDirectLineClient(min) {
let config = { 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')), spec: JSON.parse(Fs.readFileSync('directline-3.0.json', 'utf8')),
requestInterceptor: req => { requestInterceptor: req => {
req.headers['Authorization'] = `Bearer ${min.instance.webchatKey}`; req.headers['Authorization'] = `Bearer ${min.instance.webchatKey}`;
} }
}; };
if (!GBConfigService.get('STORAGE_NAME')) { if (!GBConfigService.get('STORAGE_NAME')) {
config['spec'].servers = [{ url: `http://127.0.0.1:${GBConfigService.getServerPort()}/api/messages` }]; config['spec'].servers = [{ url: `http://127.0.0.1:${GBConfigService.getServerPort()}/api/messages` }];
config['openapi'] = '3.0.0'; config['openapi'] = '3.0.0';
@ -83,11 +82,18 @@ export class GBUtil {
return await new SwaggerClient(config); return await new SwaggerClient(config);
} }
public static toYAML(json) { public static toYAML(data) {
const doc = new YAML.Document(); const extractProps = (obj) => {
doc.contents = json; return Object.getOwnPropertyNames(obj).reduce((acc, key) => {
return doc.toString(); 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) { public static sleep(ms) {
return new Promise(resolve => { return new Promise(resolve => {