fix(core.gbapp): Language and translator improvements.
This commit is contained in:
parent
933729ae4d
commit
f967d8f9e8
5 changed files with 36 additions and 33 deletions
|
@ -538,8 +538,7 @@ export class GBConversationalService {
|
|||
public async getLanguage(min: GBMinInstance, text: string): Promise<string> {
|
||||
return await AzureText.getLocale(
|
||||
min.instance.textAnalyticsKey ? min.instance.textAnalyticsKey : min.instance.textAnalyticsKey,
|
||||
min.instance.textAnalyticsEndpoint ? min.instance.textAnalyticsEndpoint :
|
||||
min.instance.textAnalyticsEndpoint,
|
||||
min.instance.textAnalyticsEndpoint ? min.instance.textAnalyticsEndpoint : min.instance.textAnalyticsEndpoint,
|
||||
text
|
||||
);
|
||||
}
|
||||
|
@ -612,14 +611,16 @@ export class GBConversationalService {
|
|||
}
|
||||
|
||||
public async prompt(min: GBMinInstance, step: GBDialogStep, text: string) {
|
||||
let sec = new SecService();
|
||||
const member = step.context.activity.from;
|
||||
const user = await sec.ensureUser(min.instance.instanceId, member.id, member.name, '', 'web', member.name);
|
||||
const user = await min.userProfile.get(step.context, {});
|
||||
const systemUser = user.systemUser;
|
||||
|
||||
if (text !== null) {
|
||||
text = await min.conversationalService.translate(
|
||||
min,
|
||||
text,
|
||||
user.locale ? user.locale : min.core.getParam<string>(min.instance, 'Locale', GBConfigService.get('LOCALE'))
|
||||
systemUser.locale
|
||||
? systemUser.locale
|
||||
: min.core.getParam<string>(min.instance, 'Locale', GBConfigService.get('LOCALE'))
|
||||
);
|
||||
GBLog.info(`Translated text(prompt): ${text}.`);
|
||||
}
|
||||
|
@ -628,21 +629,22 @@ export class GBConversationalService {
|
|||
}
|
||||
|
||||
public async sendText(min: GBMinInstance, step, text) {
|
||||
let sec = new SecService();
|
||||
const member = step.context.activity.from;
|
||||
const user = await sec.ensureUser(min.instance.instanceId, member.id, member.name, '', 'web', member.name);
|
||||
const user = await min.userProfile.get(step.context, {});
|
||||
const systemUser = user.systemUser;
|
||||
|
||||
if (user) {
|
||||
text = await min.conversationalService.translate(
|
||||
min,
|
||||
text,
|
||||
user.locale ? user.locale : min.core.getParam<string>(min.instance, 'Locale', GBConfigService.get('LOCALE'))
|
||||
systemUser.locale
|
||||
? systemUser.locale
|
||||
: min.core.getParam<string>(min.instance, 'Locale', GBConfigService.get('LOCALE'))
|
||||
);
|
||||
GBLog.info(`Translated text(sendText): ${text}.`);
|
||||
|
||||
const analytics = new AnalyticsService();
|
||||
const userProfile = await min.userProfile.get(step.context, {});
|
||||
analytics.createMessage(min.instance.instanceId, userProfile.conversation, null, text);
|
||||
|
||||
analytics.createMessage(min.instance.instanceId, user.conversation, null, text);
|
||||
|
||||
if (!isNaN(member.id)) {
|
||||
await min.whatsAppDirectLine.sendToDevice(member.id, text);
|
||||
|
@ -650,7 +652,6 @@ export class GBConversationalService {
|
|||
await step.context.sendActivity(text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async broadcast(min: GBMinInstance, message: string) {
|
||||
GBLog.info(`Sending broadcast notifications...`);
|
||||
|
|
|
@ -787,14 +787,20 @@ export class GBMinService {
|
|||
const systemUser = user.systemUser;
|
||||
if (systemUser.locale != locale) {
|
||||
let sec = new SecService();
|
||||
await sec.updateUserLocale(systemUser.userSystemId, locale);
|
||||
await sec.updateUserLocale(systemUser.userId, locale);
|
||||
}
|
||||
}
|
||||
|
||||
// Translates the input text if is turned on instance params.
|
||||
|
||||
const originalText = context.text;
|
||||
text = await min.conversationalService.translate(min, text, locale);
|
||||
let contentLocale = min.core.getParam<string>(
|
||||
min.instance,
|
||||
'Default Content Language',
|
||||
GBConfigService.get('DEFAULT_CONTENT_LANGUAGE')
|
||||
);
|
||||
|
||||
text = await min.conversationalService.translate(min, text, contentLocale);
|
||||
GBLog.info(`Translated text (processMessageActivity): ${text}.`);
|
||||
context.activity.text = text;
|
||||
context.activity.originalText = originalText;
|
||||
|
|
|
@ -439,7 +439,7 @@ export class KBService implements IGBKBService {
|
|||
min,
|
||||
answer.content,
|
||||
user.systemUser.locale
|
||||
? user.locale
|
||||
? user.systemUser.locale
|
||||
: min.core.getParam<string>(min.instance, 'Locale', GBConfigService.get('LOCALE'))
|
||||
);
|
||||
GBLog.info(`Translated text(playMarkdown): ${text}.`);
|
||||
|
|
|
@ -69,7 +69,7 @@ export class GuaribasUser extends Model<GuaribasUser> {
|
|||
@Column public email: string;
|
||||
|
||||
@Column(DataType.STRING(5))
|
||||
@Column public locale: string;
|
||||
public locale: string;
|
||||
|
||||
@ForeignKey(() => GuaribasInstance)
|
||||
@Column
|
||||
|
|
|
@ -10,7 +10,6 @@ import { CollectionUtil } from 'pragmatismo-io-framework';
|
|||
* Security service layer.
|
||||
*/
|
||||
export class SecService extends GBService {
|
||||
|
||||
public async importSecurityFile(localPath: string, instance: IGBInstance) {
|
||||
const security = JSON.parse(Fs.readFileSync(urlJoin(localPath, 'security.json'), 'utf8'));
|
||||
await CollectionUtil.asyncForEach(security.groups, async group => {
|
||||
|
@ -82,14 +81,13 @@ export class SecService extends GBService {
|
|||
await user.save();
|
||||
}
|
||||
|
||||
public async updateUserLocale(userSystemId: number, locale: any) : Promise<GuaribasUser> {
|
||||
public async updateUserLocale(userId: number, locale: any): Promise<GuaribasUser> {
|
||||
let user = await GuaribasUser.findOne({
|
||||
where: {
|
||||
userSystemId: userSystemId
|
||||
userId: userId
|
||||
}
|
||||
});
|
||||
user.locale = locale;
|
||||
|
||||
return await user.save();
|
||||
}
|
||||
|
||||
|
@ -183,8 +181,6 @@ export class SecService extends GBService {
|
|||
return agentSystemId;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public async getUserFromSystemId(systemId: string): Promise<GuaribasUser> {
|
||||
return await GuaribasUser.findOne({
|
||||
where: {
|
||||
|
|
Loading…
Add table
Reference in a new issue