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 => {
|
||||
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
|
||||
await min.conversationalService.sendText(min, step, Messages[locale].welcome);
|
||||
|
||||
|
|
|
@ -218,7 +218,8 @@ export class GBAdminService implements IGBAdminService {
|
|||
const packageName = text.split(' ')[1];
|
||||
const importer = new GBImporter(min.core);
|
||||
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) {
|
||||
|
|
|
@ -59,25 +59,30 @@ export class LanguageDialog extends IGBDialog {
|
|||
|
||||
async step => {
|
||||
const locale = step.context.activity.locale;
|
||||
|
||||
|
||||
return await min.conversationalService.prompt(min, step,
|
||||
Messages[locale].which_language);
|
||||
},
|
||||
async step => {
|
||||
|
||||
},
|
||||
async step => {
|
||||
|
||||
const locale = step.context.activity.locale;
|
||||
const user = await min.userProfile.get(step.context, {});
|
||||
|
||||
|
||||
const list = [
|
||||
{ name: 'english', code: 'en' },
|
||||
{ name: 'inglês', code: 'en' },
|
||||
{ name: 'portuguese', code: 'pt' },
|
||||
{ name: 'português', code: 'pt' },
|
||||
{ name: 'spanish', code: 'es' },
|
||||
{ name: 'espanõl', code: 'es' },
|
||||
{ name: 'german', code: 'de' },
|
||||
{ name: 'deutsch', code: 'de' }
|
||||
];
|
||||
let translatorLocale = null;
|
||||
const text = step.context.activity['originalText'];
|
||||
|
||||
await CollectionUtil.asyncForEach(list, async item => {
|
||||
if (GBConversationalService.kmpSearch(step.result, item.name) != -1) {
|
||||
if (GBConversationalService.kmpSearch(text, item.name) != -1) {
|
||||
translatorLocale = item.code;
|
||||
}
|
||||
});
|
||||
|
@ -87,9 +92,9 @@ export class LanguageDialog extends IGBDialog {
|
|||
|
||||
await min.userProfile.set(step.context, user);
|
||||
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.
|
||||
*/
|
||||
export class GBConfigService {
|
||||
static getBoolean(value: string): boolean {
|
||||
return this.get(value) as unknown as boolean;
|
||||
}
|
||||
public static getServerPort(): string {
|
||||
if (process.env.PORT) {
|
||||
return process.env.PORT;
|
||||
|
|
|
@ -346,7 +346,6 @@ export class GBDeployer implements IGBDeployer {
|
|||
}
|
||||
GBServer.globals.minService.unmountBot(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> {
|
||||
return GuaribasPackage.create({
|
||||
|
|
|
@ -353,9 +353,8 @@ export class GBMinService {
|
|||
min.instance.authenticatorTenant,
|
||||
'/oauth2/authorize'
|
||||
);
|
||||
authorizationUrl = `${authorizationUrl}?response_type=code&client_id=${
|
||||
min.instance.marketplaceId
|
||||
}&redirect_uri=${urlJoin(min.instance.botEndpoint, min.instance.botId, 'token')}`;
|
||||
authorizationUrl = `${authorizationUrl}?response_type=code&client_id=${min.instance.marketplaceId
|
||||
}&redirect_uri=${urlJoin(min.instance.botEndpoint, min.instance.botId, 'token')}`;
|
||||
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 simpleLocale = context.activity.locale.substring(0, 2);
|
||||
const hasBadWord = wash.check(simpleLocale, context.activity.text);
|
||||
|
||||
if (hasBadWord) {
|
||||
await step.beginDialog('/pleaseNoBadWords');
|
||||
} else if (isVMCall) {
|
||||
if (isVMCall) {
|
||||
await GBVMService.callVM(context.activity.text, min, step, this.deployer);
|
||||
} else if (context.activity.text.charAt(0) === '/') {
|
||||
let text = context.activity.text;
|
||||
|
@ -758,7 +753,7 @@ export class GBMinService {
|
|||
await step.beginDialog('/menu', JSON.parse(context.activity.text));
|
||||
// Otherwise, continue to the active dialog in the stack.
|
||||
} 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.`
|
||||
);
|
||||
await step.beginDialog('/publish', { confirm: true, firstTime: true });
|
||||
|
@ -766,7 +761,7 @@ export class GBMinService {
|
|||
let text = context.activity.text;
|
||||
const originalText = text;
|
||||
text = text.replace(/<([^>]+?)([^>]*?)>(.*?)<\/\1>/gi, '');
|
||||
|
||||
|
||||
// Spells check the input text before translating.
|
||||
|
||||
text = await min.conversationalService.spellCheck(min, text);
|
||||
|
@ -781,11 +776,12 @@ export class GBMinService {
|
|||
let detectLanguage = min.core.getParam<boolean>(
|
||||
min.instance,
|
||||
'Language Detector',
|
||||
GBConfigService.get('LANGUAGE_DETECTOR') as any
|
||||
);
|
||||
if (detectLanguage) {
|
||||
GBConfigService.getBoolean('LANGUAGE_DETECTOR')
|
||||
) === 'true';
|
||||
const systemUser = user.systemUser;
|
||||
locale = systemUser.locale;
|
||||
if (detectLanguage || !locale) {
|
||||
locale = await min.conversationalService.getLanguage(min, text);
|
||||
const systemUser = user.systemUser;
|
||||
if (systemUser.locale != locale) {
|
||||
let sec = new SecService();
|
||||
user.systemUser = await sec.updateUserLocale(systemUser.userId, locale);
|
||||
|
@ -793,9 +789,15 @@ 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.
|
||||
|
||||
|
||||
|
||||
let contentLocale = min.core.getParam<string>(
|
||||
min.instance,
|
||||
'Default Content Language',
|
||||
|
|
|
@ -396,7 +396,7 @@ export class GBVMService extends GBService {
|
|||
} catch (error) {
|
||||
GBLog.error(`Error running BASIC code: ${error}`);
|
||||
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 });
|
||||
}
|
||||
} else {
|
||||
|
|
Loading…
Add table
Reference in a new issue