fix(core.gbapp): Language improvements tested.
This commit is contained in:
parent
f71b435d19
commit
a618c7100b
7 changed files with 37 additions and 28 deletions
|
@ -82,9 +82,8 @@ export class AdminDialog extends IGBDialog {
|
||||||
},
|
},
|
||||||
async step => {
|
async step => {
|
||||||
const locale = step.context.activity.locale;
|
const locale = step.context.activity.locale;
|
||||||
const sensitive = step.result;
|
|
||||||
|
|
||||||
if (sensitive === process.env.ADMIN_PASS) {
|
if (step.context.activity['originalText'] === process.env.ADMIN_PASS) {
|
||||||
// TODO: Per bot: min.instance.adminPass
|
// TODO: Per bot: min.instance.adminPass
|
||||||
await min.conversationalService.sendText(min, step, Messages[locale].welcome);
|
await min.conversationalService.sendText(min, step, Messages[locale].welcome);
|
||||||
|
|
||||||
|
|
|
@ -218,7 +218,8 @@ export class GBAdminService implements IGBAdminService {
|
||||||
const packageName = text.split(' ')[1];
|
const packageName = text.split(' ')[1];
|
||||||
const importer = new GBImporter(min.core);
|
const importer = new GBImporter(min.core);
|
||||||
const deployer = new GBDeployer(min.core, importer);
|
const deployer = new GBDeployer(min.core, importer);
|
||||||
await deployer.undeployPackageFromLocalPath(min.instance, urlJoin(GBDeployer.workFolder, packageName));
|
let localFolder = Path.join('work', `${min.instance.botId}.gbai`, Path.basename(packageName));
|
||||||
|
await deployer.undeployPackageFromLocalPath(min.instance, localFolder);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static isSharePointPath(path: string) {
|
public static isSharePointPath(path: string) {
|
||||||
|
|
|
@ -70,14 +70,19 @@ export class LanguageDialog extends IGBDialog {
|
||||||
|
|
||||||
const list = [
|
const list = [
|
||||||
{ name: 'english', code: 'en' },
|
{ name: 'english', code: 'en' },
|
||||||
|
{ name: 'inglês', code: 'en' },
|
||||||
{ name: 'portuguese', code: 'pt' },
|
{ name: 'portuguese', code: 'pt' },
|
||||||
|
{ name: 'português', code: 'pt' },
|
||||||
{ name: 'spanish', code: 'es' },
|
{ name: 'spanish', code: 'es' },
|
||||||
|
{ name: 'espanõl', code: 'es' },
|
||||||
{ name: 'german', code: 'de' },
|
{ name: 'german', code: 'de' },
|
||||||
{ name: 'deutsch', code: 'de' }
|
{ name: 'deutsch', code: 'de' }
|
||||||
];
|
];
|
||||||
let translatorLocale = null;
|
let translatorLocale = null;
|
||||||
|
const text = step.context.activity['originalText'];
|
||||||
|
|
||||||
await CollectionUtil.asyncForEach(list, async item => {
|
await CollectionUtil.asyncForEach(list, async item => {
|
||||||
if (GBConversationalService.kmpSearch(step.result, item.name) != -1) {
|
if (GBConversationalService.kmpSearch(text, item.name) != -1) {
|
||||||
translatorLocale = item.code;
|
translatorLocale = item.code;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -89,7 +94,7 @@ export class LanguageDialog extends IGBDialog {
|
||||||
await min.conversationalService.sendText(min, step,
|
await min.conversationalService.sendText(min, step,
|
||||||
Messages[locale].language_chosen);
|
Messages[locale].language_chosen);
|
||||||
|
|
||||||
return await step.next();
|
await step.replaceDialog('/ask', { firstTime: true });
|
||||||
}
|
}
|
||||||
]));
|
]));
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,6 +42,9 @@ import { GBLog } from 'botlib';
|
||||||
* Base configuration for the server like storage.
|
* Base configuration for the server like storage.
|
||||||
*/
|
*/
|
||||||
export class GBConfigService {
|
export class GBConfigService {
|
||||||
|
static getBoolean(value: string): boolean {
|
||||||
|
return this.get(value) as unknown as boolean;
|
||||||
|
}
|
||||||
public static getServerPort(): string {
|
public static getServerPort(): string {
|
||||||
if (process.env.PORT) {
|
if (process.env.PORT) {
|
||||||
return process.env.PORT;
|
return process.env.PORT;
|
||||||
|
|
|
@ -346,7 +346,6 @@ export class GBDeployer implements IGBDeployer {
|
||||||
}
|
}
|
||||||
GBServer.globals.minService.unmountBot(botId);
|
GBServer.globals.minService.unmountBot(botId);
|
||||||
await this.core.deleteInstance(botId);
|
await this.core.deleteInstance(botId);
|
||||||
const packageFolder = Path.join(process.env.PWD, 'work', `${botId}.gbai`, packageName);
|
|
||||||
}
|
}
|
||||||
public async deployPackageToStorage(instanceId: number, packageName: string): Promise<GuaribasPackage> {
|
public async deployPackageToStorage(instanceId: number, packageName: string): Promise<GuaribasPackage> {
|
||||||
return GuaribasPackage.create({
|
return GuaribasPackage.create({
|
||||||
|
|
|
@ -353,8 +353,7 @@ export class GBMinService {
|
||||||
min.instance.authenticatorTenant,
|
min.instance.authenticatorTenant,
|
||||||
'/oauth2/authorize'
|
'/oauth2/authorize'
|
||||||
);
|
);
|
||||||
authorizationUrl = `${authorizationUrl}?response_type=code&client_id=${
|
authorizationUrl = `${authorizationUrl}?response_type=code&client_id=${min.instance.marketplaceId
|
||||||
min.instance.marketplaceId
|
|
||||||
}&redirect_uri=${urlJoin(min.instance.botEndpoint, min.instance.botId, 'token')}`;
|
}&redirect_uri=${urlJoin(min.instance.botEndpoint, min.instance.botId, 'token')}`;
|
||||||
res.redirect(authorizationUrl);
|
res.redirect(authorizationUrl);
|
||||||
});
|
});
|
||||||
|
@ -728,11 +727,7 @@ export class GBMinService {
|
||||||
const isVMCall = Object.keys(min.scriptMap).find(key => min.scriptMap[key] === context.activity.text) !== undefined;
|
const isVMCall = Object.keys(min.scriptMap).find(key => min.scriptMap[key] === context.activity.text) !== undefined;
|
||||||
|
|
||||||
const simpleLocale = context.activity.locale.substring(0, 2);
|
const simpleLocale = context.activity.locale.substring(0, 2);
|
||||||
const hasBadWord = wash.check(simpleLocale, context.activity.text);
|
if (isVMCall) {
|
||||||
|
|
||||||
if (hasBadWord) {
|
|
||||||
await step.beginDialog('/pleaseNoBadWords');
|
|
||||||
} else if (isVMCall) {
|
|
||||||
await GBVMService.callVM(context.activity.text, min, step, this.deployer);
|
await GBVMService.callVM(context.activity.text, min, step, this.deployer);
|
||||||
} else if (context.activity.text.charAt(0) === '/') {
|
} else if (context.activity.text.charAt(0) === '/') {
|
||||||
let text = context.activity.text;
|
let text = context.activity.text;
|
||||||
|
@ -758,7 +753,7 @@ export class GBMinService {
|
||||||
await step.beginDialog('/menu', JSON.parse(context.activity.text));
|
await step.beginDialog('/menu', JSON.parse(context.activity.text));
|
||||||
// Otherwise, continue to the active dialog in the stack.
|
// Otherwise, continue to the active dialog in the stack.
|
||||||
} else if (!(await this.deployer.getStoragePackageByName(min.instance.instanceId, `${min.instance.botId}.gbkb`))) {
|
} else if (!(await this.deployer.getStoragePackageByName(min.instance.instanceId, `${min.instance.botId}.gbkb`))) {
|
||||||
await step.context.sendActivity(
|
await min.conversationalService.sendText(min, step,
|
||||||
`Oi, ainda não possuo pacotes de conhecimento publicados. Por favor, aguarde alguns segundos enquanto eu auto-publico alguns pacotes.`
|
`Oi, ainda não possuo pacotes de conhecimento publicados. Por favor, aguarde alguns segundos enquanto eu auto-publico alguns pacotes.`
|
||||||
);
|
);
|
||||||
await step.beginDialog('/publish', { confirm: true, firstTime: true });
|
await step.beginDialog('/publish', { confirm: true, firstTime: true });
|
||||||
|
@ -781,11 +776,12 @@ export class GBMinService {
|
||||||
let detectLanguage = min.core.getParam<boolean>(
|
let detectLanguage = min.core.getParam<boolean>(
|
||||||
min.instance,
|
min.instance,
|
||||||
'Language Detector',
|
'Language Detector',
|
||||||
GBConfigService.get('LANGUAGE_DETECTOR') as any
|
GBConfigService.getBoolean('LANGUAGE_DETECTOR')
|
||||||
);
|
) === 'true';
|
||||||
if (detectLanguage) {
|
|
||||||
locale = await min.conversationalService.getLanguage(min, text);
|
|
||||||
const systemUser = user.systemUser;
|
const systemUser = user.systemUser;
|
||||||
|
locale = systemUser.locale;
|
||||||
|
if (detectLanguage || !locale) {
|
||||||
|
locale = await min.conversationalService.getLanguage(min, text);
|
||||||
if (systemUser.locale != locale) {
|
if (systemUser.locale != locale) {
|
||||||
let sec = new SecService();
|
let sec = new SecService();
|
||||||
user.systemUser = await sec.updateUserLocale(systemUser.userId, locale);
|
user.systemUser = await sec.updateUserLocale(systemUser.userId, locale);
|
||||||
|
@ -793,6 +789,12 @@ export class GBMinService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const hasBadWord = wash.check(locale, context.activity.text);
|
||||||
|
|
||||||
|
if (hasBadWord) {
|
||||||
|
return await step.beginDialog('/pleaseNoBadWords');
|
||||||
|
}
|
||||||
|
|
||||||
// Translates the input text if is turned on instance params.
|
// Translates the input text if is turned on instance params.
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -396,7 +396,7 @@ export class GBVMService extends GBService {
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
GBLog.error(`Error running BASIC code: ${error}`);
|
GBLog.error(`Error running BASIC code: ${error}`);
|
||||||
const locale = step.context.activity.locale;
|
const locale = step.context.activity.locale;
|
||||||
step.context.sendActivity(Messages[locale].very_sorry_about_error);
|
min.conversationalService.sendText(min, step, Messages[locale].very_sorry_about_error);
|
||||||
return await step.replaceDialog('/ask', { isReturning: true });
|
return await step.replaceDialog('/ask', { isReturning: true });
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Reference in a new issue