Skip to content

Commit

Permalink
fix(core.gbapp): Language improvements tested.
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigorodriguez committed Nov 19, 2020
1 parent f71b435 commit a618c71
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 28 deletions.
3 changes: 1 addition & 2 deletions packages/admin.gbapp/dialogs/AdminDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
3 changes: 2 additions & 1 deletion packages/admin.gbapp/services/GBAdminService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
21 changes: 13 additions & 8 deletions packages/core.gbapp/dialogs/LanguageDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
});
Expand All @@ -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 });
}
]));
}
Expand Down
3 changes: 3 additions & 0 deletions packages/core.gbapp/services/GBConfigService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion packages/core.gbapp/services/GBDeployer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
32 changes: 17 additions & 15 deletions packages/core.gbapp/services/GBMinService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
Expand Down Expand Up @@ -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;
Expand All @@ -758,15 +753,15 @@ 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 });
} else {
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);
Expand All @@ -781,21 +776,28 @@ 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);
await min.userProfile.set(step.context, user);
}
}

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',
Expand Down
2 changes: 1 addition & 1 deletion packages/core.gbapp/services/GBVMService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit a618c71

Please sign in to comment.