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> {
|
public async getLanguage(min: GBMinInstance, text: string): Promise<string> {
|
||||||
return await AzureText.getLocale(
|
return await AzureText.getLocale(
|
||||||
min.instance.textAnalyticsKey ? min.instance.textAnalyticsKey : min.instance.textAnalyticsKey,
|
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
|
text
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -612,14 +611,16 @@ export class GBConversationalService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public async prompt(min: GBMinInstance, step: GBDialogStep, text: string) {
|
public async prompt(min: GBMinInstance, step: GBDialogStep, text: string) {
|
||||||
let sec = new SecService();
|
const user = await min.userProfile.get(step.context, {});
|
||||||
const member = step.context.activity.from;
|
const systemUser = user.systemUser;
|
||||||
const user = await sec.ensureUser(min.instance.instanceId, member.id, member.name, '', 'web', member.name);
|
|
||||||
if (text !== null) {
|
if (text !== null) {
|
||||||
text = await min.conversationalService.translate(
|
text = await min.conversationalService.translate(
|
||||||
min,
|
min,
|
||||||
text,
|
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}.`);
|
GBLog.info(`Translated text(prompt): ${text}.`);
|
||||||
}
|
}
|
||||||
|
@ -628,27 +629,27 @@ export class GBConversationalService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public async sendText(min: GBMinInstance, step, text) {
|
public async sendText(min: GBMinInstance, step, text) {
|
||||||
let sec = new SecService();
|
|
||||||
const member = step.context.activity.from;
|
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(
|
||||||
text = await min.conversationalService.translate(
|
min,
|
||||||
min,
|
text,
|
||||||
text,
|
systemUser.locale
|
||||||
user.locale ? user.locale : min.core.getParam<string>(min.instance, 'Locale', GBConfigService.get('LOCALE'))
|
? systemUser.locale
|
||||||
);
|
: min.core.getParam<string>(min.instance, 'Locale', GBConfigService.get('LOCALE'))
|
||||||
GBLog.info(`Translated text(sendText): ${text}.`);
|
);
|
||||||
|
GBLog.info(`Translated text(sendText): ${text}.`);
|
||||||
|
|
||||||
const analytics = new AnalyticsService();
|
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)) {
|
if (!isNaN(member.id)) {
|
||||||
await min.whatsAppDirectLine.sendToDevice(member.id, text);
|
await min.whatsAppDirectLine.sendToDevice(member.id, text);
|
||||||
} else {
|
} else {
|
||||||
await step.context.sendActivity(text);
|
await step.context.sendActivity(text);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -787,14 +787,20 @@ export class GBMinService {
|
||||||
const systemUser = user.systemUser;
|
const systemUser = user.systemUser;
|
||||||
if (systemUser.locale != locale) {
|
if (systemUser.locale != locale) {
|
||||||
let sec = new SecService();
|
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.
|
// Translates the input text if is turned on instance params.
|
||||||
|
|
||||||
const originalText = context.text;
|
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}.`);
|
GBLog.info(`Translated text (processMessageActivity): ${text}.`);
|
||||||
context.activity.text = text;
|
context.activity.text = text;
|
||||||
context.activity.originalText = originalText;
|
context.activity.originalText = originalText;
|
||||||
|
|
|
@ -439,7 +439,7 @@ export class KBService implements IGBKBService {
|
||||||
min,
|
min,
|
||||||
answer.content,
|
answer.content,
|
||||||
user.systemUser.locale
|
user.systemUser.locale
|
||||||
? user.locale
|
? user.systemUser.locale
|
||||||
: min.core.getParam<string>(min.instance, 'Locale', GBConfigService.get('LOCALE'))
|
: min.core.getParam<string>(min.instance, 'Locale', GBConfigService.get('LOCALE'))
|
||||||
);
|
);
|
||||||
GBLog.info(`Translated text(playMarkdown): ${text}.`);
|
GBLog.info(`Translated text(playMarkdown): ${text}.`);
|
||||||
|
|
|
@ -69,7 +69,7 @@ export class GuaribasUser extends Model<GuaribasUser> {
|
||||||
@Column public email: string;
|
@Column public email: string;
|
||||||
|
|
||||||
@Column(DataType.STRING(5))
|
@Column(DataType.STRING(5))
|
||||||
@Column public locale: string;
|
public locale: string;
|
||||||
|
|
||||||
@ForeignKey(() => GuaribasInstance)
|
@ForeignKey(() => GuaribasInstance)
|
||||||
@Column
|
@Column
|
||||||
|
|
|
@ -10,7 +10,6 @@ import { CollectionUtil } from 'pragmatismo-io-framework';
|
||||||
* Security service layer.
|
* Security service layer.
|
||||||
*/
|
*/
|
||||||
export class SecService extends GBService {
|
export class SecService extends GBService {
|
||||||
|
|
||||||
public async importSecurityFile(localPath: string, instance: IGBInstance) {
|
public async importSecurityFile(localPath: string, instance: IGBInstance) {
|
||||||
const security = JSON.parse(Fs.readFileSync(urlJoin(localPath, 'security.json'), 'utf8'));
|
const security = JSON.parse(Fs.readFileSync(urlJoin(localPath, 'security.json'), 'utf8'));
|
||||||
await CollectionUtil.asyncForEach(security.groups, async group => {
|
await CollectionUtil.asyncForEach(security.groups, async group => {
|
||||||
|
@ -82,14 +81,13 @@ export class SecService extends GBService {
|
||||||
await user.save();
|
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({
|
let user = await GuaribasUser.findOne({
|
||||||
where: {
|
where: {
|
||||||
userSystemId: userSystemId
|
userId: userId
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
user.locale = locale;
|
user.locale = locale;
|
||||||
|
|
||||||
return await user.save();
|
return await user.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -183,8 +181,6 @@ export class SecService extends GBService {
|
||||||
return agentSystemId;
|
return agentSystemId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public async getUserFromSystemId(systemId: string): Promise<GuaribasUser> {
|
public async getUserFromSystemId(systemId: string): Promise<GuaribasUser> {
|
||||||
return await GuaribasUser.findOne({
|
return await GuaribasUser.findOne({
|
||||||
where: {
|
where: {
|
||||||
|
|
Loading…
Add table
Reference in a new issue