fix(all): Locale in Audio is dynamic.
This commit is contained in:
parent
3717f8b1fe
commit
e0980bc480
4 changed files with 45 additions and 22 deletions
|
@ -1109,12 +1109,12 @@ export class GBConversationalService {
|
||||||
false) != false;
|
false) != false;
|
||||||
|
|
||||||
|
|
||||||
if (text != '' && detectLanguage) {
|
if (text.indexOf(' ') !== -1 && detectLanguage) {
|
||||||
locale = await min.conversationalService.getLanguage(min, text);
|
locale = await min.conversationalService.getLanguage(min, text);
|
||||||
if (user.locale != locale) {
|
if (user.locale != locale) {
|
||||||
|
|
||||||
GBLog.info(`Changed language to: ${locale}`);
|
|
||||||
user = await sec.updateUserLocale(user.userId, 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) {
|
public async sendTextWithOptions(min: GBMinInstance, step, text, translate, keepTextList) {
|
||||||
const member = step.context.activity.from;
|
|
||||||
let sec = new SecService();
|
let sec = new SecService();
|
||||||
let user = await sec.getUserFromSystemId(step.context.activity.from.id);
|
let user = await sec.getUserFromSystemId(step.context.activity.from.id);
|
||||||
await this['sendTextWithOptionsAndUser'](min, user, step, text, true, null);
|
await this['sendTextWithOptionsAndUser'](min, user, step, text, true, null);
|
||||||
|
|
|
@ -351,7 +351,7 @@ export class AskDialog extends IGBDialog {
|
||||||
return await step.replaceDialog('/ask', { isReturning: true });
|
return await step.replaceDialog('/ask', { isReturning: true });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static getChannel(step): string {
|
private static getChannel(step): string {
|
||||||
return !isNaN(step.context.activity['mobile']) ? 'whatsapp' : step.context.activity.channelId;
|
return !isNaN(step.context.activity['mobile']) ? 'whatsapp' : step.context.activity.channelId;
|
||||||
}
|
}
|
||||||
|
|
|
@ -155,7 +155,7 @@ export class WhatsappDirectLine extends GBService {
|
||||||
// Sends QR Code to boot bot admin.
|
// Sends QR Code to boot bot admin.
|
||||||
const msg = `Please, scan QR Code with for bot ${this.botId}.`;
|
const msg = `Please, scan QR Code with for bot ${this.botId}.`;
|
||||||
qrcode.generate(qr, { small: true, scale: 0.5 });
|
qrcode.generate(qr, { small: true, scale: 0.5 });
|
||||||
|
|
||||||
// TODO: While handling other bots uses boot instance of this class to send QR Codes.
|
// TODO: While handling other bots uses boot instance of this class to send QR Codes.
|
||||||
// const s = new DialogKeywords(min., null, null, null);
|
// const s = new DialogKeywords(min., null, null, null);
|
||||||
// const qrBuf = await s.getQRCode(qr);
|
// const qrBuf = await s.getQRCode(qr);
|
||||||
|
@ -169,7 +169,7 @@ export class WhatsappDirectLine extends GBService {
|
||||||
// );
|
// );
|
||||||
// GBServer.globals.minBoot.whatsAppDirectLine.sendFileToDevice(adminNumber, url, Path.basename(localName), msg);
|
// GBServer.globals.minBoot.whatsAppDirectLine.sendFileToDevice(adminNumber, url, Path.basename(localName), msg);
|
||||||
// s.sendEmail(adminEmail, `Check your WhatsApp for bot ${this.botId}`, msg);
|
// s.sendEmail(adminEmail, `Check your WhatsApp for bot ${this.botId}`, msg);
|
||||||
|
|
||||||
}).bind(this)
|
}).bind(this)
|
||||||
);
|
);
|
||||||
client.on('authenticated', async () => {
|
client.on('authenticated', async () => {
|
||||||
|
@ -414,7 +414,7 @@ export class WhatsappDirectLine extends GBService {
|
||||||
// Bot name must be specified on config.
|
// Bot name must be specified on config.
|
||||||
|
|
||||||
if (botGroupID === group) {
|
if (botGroupID === group) {
|
||||||
|
|
||||||
// Shortcut has been mentioned?
|
// Shortcut has been mentioned?
|
||||||
|
|
||||||
let found = false;
|
let found = false;
|
||||||
|
@ -448,7 +448,7 @@ export class WhatsappDirectLine extends GBService {
|
||||||
if (botNumber && !answerText && !found) {
|
if (botNumber && !answerText && !found) {
|
||||||
botNumber = botNumber.replace('+', '');
|
botNumber = botNumber.replace('+', '');
|
||||||
if (!message.body.startsWith('@' + botNumber)) {
|
if (!message.body.startsWith('@' + botNumber)) {
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -485,7 +485,7 @@ export class WhatsappDirectLine extends GBService {
|
||||||
if (process.env.AUDIO_DISABLED !== 'true') {
|
if (process.env.AUDIO_DISABLED !== 'true') {
|
||||||
const media = await message.downloadMedia();
|
const media = await message.downloadMedia();
|
||||||
const buf = Buffer.from(media.data, 'base64');
|
const buf = Buffer.from(media.data, 'base64');
|
||||||
|
|
||||||
text = await GBConversationalService.getTextFromAudioBuffer(
|
text = await GBConversationalService.getTextFromAudioBuffer(
|
||||||
this.min.instance.speechKey,
|
this.min.instance.speechKey,
|
||||||
this.min.instance.cloudLocation,
|
this.min.instance.cloudLocation,
|
||||||
|
@ -897,12 +897,10 @@ export class WhatsappDirectLine extends GBService {
|
||||||
to = to + '@c.us';
|
to = to + '@c.us';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (await this.customClient.getState() === WAState.CONNECTED)
|
if (await this.customClient.getState() === WAState.CONNECTED) {
|
||||||
{
|
|
||||||
await this.customClient.sendMessage(to, msg);
|
await this.customClient.sendMessage(to, msg);
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
GBLog.info(`WhatsApp OFFLINE ${to}: ${msg}`);
|
GBLog.info(`WhatsApp OFFLINE ${to}: ${msg}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1028,7 +1026,7 @@ export class WhatsappDirectLine extends GBService {
|
||||||
}
|
}
|
||||||
|
|
||||||
const sec = new SecService();
|
const sec = new SecService();
|
||||||
|
|
||||||
// Tries to find if user wants to switch bots.
|
// Tries to find if user wants to switch bots.
|
||||||
|
|
||||||
let toSwitchMin = GBServer.globals.minInstances.filter(
|
let toSwitchMin = GBServer.globals.minInstances.filter(
|
||||||
|
@ -1037,20 +1035,45 @@ export class WhatsappDirectLine extends GBService {
|
||||||
|
|
||||||
|
|
||||||
GBLog.info(`A WhatsApp mobile requested instance for: ${botId}.`);
|
GBLog.info(`A WhatsApp mobile requested instance for: ${botId}.`);
|
||||||
|
|
||||||
|
|
||||||
let urlMin: any = GBServer.globals.minInstances.filter(p => p.instance.botId === botId)[0];
|
let urlMin: any = GBServer.globals.minInstances.filter(p => p.instance.botId === botId)[0];
|
||||||
|
|
||||||
let user = await sec.getUserFromSystemId(id);
|
let user = await sec.getUserFromSystemId(id);
|
||||||
|
|
||||||
const botNumber = urlMin ? urlMin.core.getParam(urlMin.instance, 'Bot Number', null) : null;
|
const botNumber = urlMin ? urlMin.core.getParam(urlMin.instance, 'Bot Number', null) : null;
|
||||||
if (botNumber && GBServer.globals.minBoot.botId !== urlMin.botId) {
|
if (botNumber && GBServer.globals.minBoot.botId !== urlMin.botId) {
|
||||||
GBLog.info(`${id} fixed by bot number talked to: ${botId}.`);
|
GBLog.info(`${id} fixed by bot number talked to: ${botId}.`);
|
||||||
|
let locale;
|
||||||
user = await sec.ensureUser(urlMin, id, '', '', 'omnichannel', '','');
|
if (!user) {
|
||||||
|
|
||||||
|
// 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.updateUserInstance(id, urlMin.instance.instanceId);
|
||||||
|
user = await sec.updateUserLocale(user.userId, locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
let activeMin;
|
let activeMin;
|
||||||
|
|
||||||
|
@ -1116,11 +1139,12 @@ export class WhatsappDirectLine extends GBService {
|
||||||
// If bot has a fixed Find active bot instance.
|
// If bot has a fixed Find active bot instance.
|
||||||
|
|
||||||
activeMin = botNumber ? urlMin : toSwitchMin ? toSwitchMin : GBServer.globals.minBoot;
|
activeMin = botNumber ? urlMin : toSwitchMin ? toSwitchMin : GBServer.globals.minBoot;
|
||||||
|
const min = activeMin;
|
||||||
// If it is the first time for the user, tries to auto-execute
|
// If it is the first time for the user, tries to auto-execute
|
||||||
// start dialog if any is specified in Config.xlsx.
|
// start dialog if any is specified in Config.xlsx.
|
||||||
|
|
||||||
if (user === null || user.hearOnDialog) {
|
if (user === null || user.hearOnDialog) {
|
||||||
|
|
||||||
user = await sec.ensureUser(activeMin, id, senderName, '', 'whatsapp', senderName, null);
|
user = await sec.ensureUser(activeMin, id, senderName, '', 'whatsapp', senderName, null);
|
||||||
|
|
||||||
const startDialog = user.hearOnDialog
|
const startDialog = user.hearOnDialog
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
import tags from 'language-tags';
|
|
||||||
|
|
||||||
export class GBUtil {
|
export class GBUtil {
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue