new(core.gbapp): Refactorings.
This commit is contained in:
parent
7af0b8755a
commit
9759797036
3 changed files with 46 additions and 14 deletions
|
@ -585,4 +585,32 @@ STORAGE_SYNC=true
|
||||||
const serverName = GBConfigService.get('STORAGE_SERVER').split('.database.windows.net')[0];
|
const serverName = GBConfigService.get('STORAGE_SERVER').split('.database.windows.net')[0];
|
||||||
await installationDeployer.openStorageFirewall(group, serverName);
|
await installationDeployer.openStorageFirewall(group, serverName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a dynamic param from instance. Dynamic params are defined in Config.xlsx
|
||||||
|
* and loaded into the work folder from /publish command.
|
||||||
|
*
|
||||||
|
* @param name Name of param to get from instance.
|
||||||
|
* @param defaultValue Value returned when no param is defined in Config.xlsx.
|
||||||
|
*/
|
||||||
|
public static getParam<T>(instance, name: string, defaultValue?: T): any {
|
||||||
|
let value = null;
|
||||||
|
if (instance.params) {
|
||||||
|
const params = JSON.parse(instance.params);
|
||||||
|
value = params ? params[name] : defaultValue;
|
||||||
|
}
|
||||||
|
if (typeof (defaultValue) === "boolean") {
|
||||||
|
return new Boolean(value ? value.toLowerCase() === "true" : defaultValue);
|
||||||
|
}
|
||||||
|
if (typeof (defaultValue) === "string") {
|
||||||
|
return value ? value : defaultValue;
|
||||||
|
}
|
||||||
|
if (typeof (defaultValue) === "number") {
|
||||||
|
return new Number(value ? defaultValue : (defaultValue ? defaultValue : 0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,6 +69,7 @@ import { AnalyticsService } from '../../analytics.gblib/services/AnalyticsServic
|
||||||
import { WhatsappDirectLine } from '../../whatsapp.gblib/services/WhatsappDirectLine';
|
import { WhatsappDirectLine } from '../../whatsapp.gblib/services/WhatsappDirectLine';
|
||||||
import fs = require('fs');
|
import fs = require('fs');
|
||||||
import { GBConversationalService } from './GBConversationalService';
|
import { GBConversationalService } from './GBConversationalService';
|
||||||
|
import { GuaribasConversationMessage } from 'packages/analytics.gblib/models';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Minimal service layer for a bot.
|
* Minimal service layer for a bot.
|
||||||
|
@ -642,6 +643,8 @@ export class GBMinService {
|
||||||
|
|
||||||
private async processMessageActivity(context, min: GBMinInstance, step: GBDialogStep) {
|
private async processMessageActivity(context, min: GBMinInstance, step: GBDialogStep) {
|
||||||
|
|
||||||
|
let message: GuaribasConversationMessage;
|
||||||
|
|
||||||
if (process.env.PRIVACY_STORE_MESSAGES === "true") {
|
if (process.env.PRIVACY_STORE_MESSAGES === "true") {
|
||||||
|
|
||||||
// Adds message to the analytics layer.
|
// Adds message to the analytics layer.
|
||||||
|
@ -649,7 +652,7 @@ export class GBMinService {
|
||||||
const analytics = new AnalyticsService();
|
const analytics = new AnalyticsService();
|
||||||
const user = await min.userProfile.get(context, {});
|
const user = await min.userProfile.get(context, {});
|
||||||
if (user) {
|
if (user) {
|
||||||
analytics.createMessage(min.instance.instanceId,
|
message = await analytics.createMessage(min.instance.instanceId,
|
||||||
user.conversation, user.systemUser.userId,
|
user.conversation, user.systemUser.userId,
|
||||||
context.activity.text);
|
context.activity.text);
|
||||||
}
|
}
|
||||||
|
@ -701,16 +704,9 @@ export class GBMinService {
|
||||||
|
|
||||||
let query = context.activity.text;
|
let query = context.activity.text;
|
||||||
|
|
||||||
const translatorEnabled = () => {
|
|
||||||
if (min.instance.params) {
|
|
||||||
const params = JSON.parse(min.instance.params);
|
|
||||||
return params ? params['Enable Worldwide Translator'] === "TRUE" : false;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
} // TODO: Encapsulate.
|
|
||||||
|
|
||||||
let locale = 'pt';
|
let locale = 'pt';
|
||||||
if (process.env.TRANSLATOR_DISABLED !== "true" || translatorEnabled()) {
|
if (process.env.TRANSLATOR_DISABLED !== "true" || min.getParam('Enable Worldwide Translator') ) {
|
||||||
const minBoot = GBServer.globals.minBoot as any; // TODO: Switch keys automatically to master/per bot.
|
const minBoot = GBServer.globals.minBoot as any; // TODO: Switch keys automatically to master/per bot.
|
||||||
locale = await AzureText.getLocale(minBoot.instance.textAnalyticsKey ?
|
locale = await AzureText.getLocale(minBoot.instance.textAnalyticsKey ?
|
||||||
minBoot.instance.textAnalyticsKey : minBoot.instance.textAnalyticsKey,
|
minBoot.instance.textAnalyticsKey : minBoot.instance.textAnalyticsKey,
|
||||||
|
@ -726,18 +722,22 @@ export class GBMinService {
|
||||||
user.locale = locale;
|
user.locale = locale;
|
||||||
await user.save();
|
await user.save();
|
||||||
const minBoot = GBServer.globals.minBoot as any;
|
const minBoot = GBServer.globals.minBoot as any;
|
||||||
|
const notTranslatedQuery = query;
|
||||||
query = await min.conversationalService.translate(min,
|
query = await min.conversationalService.translate(min,
|
||||||
min.instance.translatorKey ? min.instance.translatorKey : minBoot.instance.translatorKey,
|
min.instance.translatorKey ? min.instance.translatorKey : minBoot.instance.translatorKey,
|
||||||
min.instance.translatorEndpoint ? min.instance.translatorEndpoint : minBoot.instance.translatorEndpoint,
|
min.instance.translatorEndpoint ? min.instance.translatorEndpoint : minBoot.instance.translatorEndpoint,
|
||||||
query,
|
query,
|
||||||
'pt');
|
'pt');
|
||||||
GBLog.info(`Translated text: ${query}.`)
|
GBLog.info(`Translated text: ${query}.`);
|
||||||
|
|
||||||
// Checks if any .gbapp will handle this answer, if not goes to kb.gbapp.
|
// Checks if any .gbapp will handle this answer, if not goes to kb.gbapp.
|
||||||
|
|
||||||
let handled = false;
|
let handled = false;
|
||||||
await CollectionUtil.asyncForEach(min.appPackages, async (e: IGBPackage) => {
|
await CollectionUtil.asyncForEach(min.appPackages, async (e: IGBPackage) => {
|
||||||
if (await e.onExchangeData(min, "handleAnswer", { query: query, step: step })) {
|
if (await e.onExchangeData(min, "handleAnswer", { query: query, step: step,
|
||||||
|
notTranslatedQuery: notTranslatedQuery,
|
||||||
|
message: message,
|
||||||
|
user })) {
|
||||||
handled = true;
|
handled = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -593,14 +593,18 @@ export class KBService implements IGBKBService {
|
||||||
await GuaribasSubject.destroy({
|
await GuaribasSubject.destroy({
|
||||||
where: { instanceId: instance.instanceId, packageId: packageId }
|
where: { instanceId: instance.instanceId, packageId: packageId }
|
||||||
});
|
});
|
||||||
await GuaribasPackage.destroy({
|
await this.undeployPackageFromStorage(instance, packageId);
|
||||||
where: { instanceId: instance.instanceId, packageId: packageId }
|
|
||||||
});
|
|
||||||
|
|
||||||
GBLog.info("Remember to call rebuild index manually after package removal.");
|
GBLog.info("Remember to call rebuild index manually after package removal.");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async undeployPackageFromStorage(instance: any, packageId: number) {
|
||||||
|
await GuaribasPackage.destroy({
|
||||||
|
where: { instanceId: instance.instanceId, packageId: packageId }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deploys a knowledge base to the storage using the .gbkb format.
|
* Deploys a knowledge base to the storage using the .gbkb format.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Reference in a new issue