new(all): TRUE multicloud.
This commit is contained in:
parent
3d1624ac23
commit
367e45f5f5
3 changed files with 25 additions and 19 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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)}`
|
||||
);
|
||||
}
|
||||
});
|
||||
|
|
22
src/util.ts
22
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 => {
|
||||
|
|
Loading…
Add table
Reference in a new issue