fix(all): Locale in Audio is dynamic.

This commit is contained in:
Rodrigo Rodriguez 2024-02-17 20:33:08 -03:00
parent 3717f8b1fe
commit e0980bc480
4 changed files with 45 additions and 22 deletions

View file

@ -1109,12 +1109,12 @@ export class GBConversationalService {
false) != false;
if (text != '' && detectLanguage) {
if (text.indexOf(' ') !== -1 && detectLanguage) {
locale = await min.conversationalService.getLanguage(min, text);
if (user.locale != locale) {
GBLog.info(`Changed language to: ${locale}`);
user = await sec.updateUserLocale(user.userId, locale);
await min.conversationalService.sendText(min,
step, `Changed language to: ${locale}`);
}
}
@ -1163,7 +1163,6 @@ export class GBConversationalService {
}
public async sendTextWithOptions(min: GBMinInstance, step, text, translate, keepTextList) {
const member = step.context.activity.from;
let sec = new SecService();
let user = await sec.getUserFromSystemId(step.context.activity.from.id);
await this['sendTextWithOptionsAndUser'](min, user, step, text, true, null);

View file

@ -897,12 +897,10 @@ export class WhatsappDirectLine extends GBService {
to = to + '@c.us';
}
}
if (await this.customClient.getState() === WAState.CONNECTED)
{
if (await this.customClient.getState() === WAState.CONNECTED) {
await this.customClient.sendMessage(to, msg);
}
else
{
else {
GBLog.info(`WhatsApp OFFLINE ${to}: ${msg}`);
}
@ -1046,9 +1044,34 @@ export class WhatsappDirectLine extends GBService {
const botNumber = urlMin ? urlMin.core.getParam(urlMin.instance, 'Bot Number', null) : null;
if (botNumber && GBServer.globals.minBoot.botId !== urlMin.botId) {
GBLog.info(`${id} fixed by bot number talked to: ${botId}.`);
let locale;
if (!user) {
user = await sec.ensureUser(urlMin, id, '', '', 'omnichannel', '','');
// Detects user typed language and updates their locale profile if applies.
const min = urlMin;
locale = min.core.getParam(
min.instance,
'Default User Language',
GBConfigService.get('DEFAULT_USER_LANGUAGE'));
const detectLanguage =
min.core.getParam(
min.instance,
'Language Detector',
false) != false;
if (text != '' && detectLanguage) {
locale = await min.conversationalService.getLanguage(min, text);
}
}
user = await sec.ensureUser(urlMin, id, '', '', 'omnichannel', '', '');
user = await sec.updateUserInstance(id, urlMin.instance.instanceId);
user = await sec.updateUserLocale(user.userId, locale);
}
@ -1116,11 +1139,12 @@ export class WhatsappDirectLine extends GBService {
// If bot has a fixed Find active bot instance.
activeMin = botNumber ? urlMin : toSwitchMin ? toSwitchMin : GBServer.globals.minBoot;
const min = activeMin;
// If it is the first time for the user, tries to auto-execute
// start dialog if any is specified in Config.xlsx.
if (user === null || user.hearOnDialog) {
user = await sec.ensureUser(activeMin, id, senderName, '', 'whatsapp', senderName, null);
const startDialog = user.hearOnDialog

View file

@ -33,7 +33,7 @@
*/
'use strict';
import tags from 'language-tags';
export class GBUtil {