new(Whatsapp.gblib): Now agents will be translated into user language before send text.

This commit is contained in:
Rodrigo Rodriguez 2020-05-17 22:36:00 +00:00
parent f67eb02d24
commit 57f9965132
3 changed files with 33 additions and 22 deletions

6
package-lock.json generated
View file

@ -3273,9 +3273,9 @@
}
},
"botlib": {
"version": "1.5.1",
"resolved": "https://registry.npmjs.org/botlib/-/botlib-1.5.1.tgz",
"integrity": "sha512-oT+cPxEpjQ4bKdeQfrVVzFnJRCmcH76GR5XL5Zez9npjfsYXttgLAM5DSMJzRo2VxO0X1OwN8UxvkUkTjCsCUA==",
"version": "1.5.2",
"resolved": "https://registry.npmjs.org/botlib/-/botlib-1.5.2.tgz",
"integrity": "sha512-drDSpfwN8dQe9X0+YkOFEP0wOfzvbumga3UlR0kB/4Zkt22jPlDXdCmS6e83hV9/93XMibwCgdKpF6WnKeZ8Zg==",
"requires": {
"async": "3.1.0",
"botbuilder": "4.7.0",

View file

@ -164,6 +164,14 @@ export class WhatsappDirectLine extends GBService {
}
GBLog.info(`GBWhatsapp: RCV ${from}(${fromName}): ${text})`);
const id = req.body.messages[0].chatId.split('@')[0];
const senderName = req.body.messages[0].senderName;
let sec = new SecService();
const user = await sec.ensureUser(this.min.instance.instanceId, id,
senderName, "", "whatsapp", senderName);
const locale = user.locale ? user.locale : 'pt';
if (message.type === "ptt") {
const options = {
@ -177,7 +185,7 @@ export class WhatsappDirectLine extends GBService {
text = await GBConversationalService.getTextFromAudioBuffer(
this.min.instance.speechKey,
this.min.instance.cloudLocation,
buf, this.locale
buf, locale
);
}
@ -185,14 +193,6 @@ export class WhatsappDirectLine extends GBService {
const conversationId = this.conversationIds[from];
let client = await this.directLineClient;
const id = req.body.messages[0].chatId.split('@')[0];
const senderName = req.body.messages[0].senderName;
let sec = new SecService();
const user = await sec.ensureUser(this.min.instance.instanceId, id,
senderName, "", "whatsapp", senderName);
if (user.agentMode === "self") {
let manualUser = await sec.getUserFromAgentSystemId(id);
@ -206,38 +206,39 @@ export class WhatsappDirectLine extends GBService {
let message = await this.min.kbService.getAnswerTextByMediaName(this.min.instance.instanceId, filename);
if (message === null) {
await this.sendToDevice(user.userSystemId, `File ${filename} not found in any .gbkb published. Check the name or publish again the associated .gbkb.`);
await this.sendToDeviceEx(user.userSystemId, `File ${filename} not found in any .gbkb published. Check the name or publish again the associated .gbkb.`,
locale);
} else {
await this.min.conversationalService.sendMarkdownToMobile(this.min, null, user.userSystemId, message);
}
} else if (text === '/qt') {
// TODO: Transfers only in pt-br for now.
await this.sendToDevice(manualUser.userSystemId, Messages[this.locale].notify_end_transfer(this.min.instance.botId));
await this.sendToDevice(user.agentSystemId, Messages[this.locale].notify_end_transfer(this.min.instance.botId));
await this.sendToDeviceEx(manualUser.userSystemId, Messages[this.locale].notify_end_transfer(this.min.instance.botId), locale);
await this.sendToDeviceEx(user.agentSystemId, Messages[this.locale].notify_end_transfer(this.min.instance.botId), locale);
await sec.updateCurrentAgent(manualUser.userSystemId, this.min.instance.instanceId, null);
}
else {
GBLog.info(`HUMAN AGENT (${id}) TO USER ${manualUser.userSystemId}: ${text}`);
this.sendToDevice(manualUser.userSystemId, `${manualUser.agentSystemId}: ${text}`);
this.sendToDeviceEx(manualUser.userSystemId, `${manualUser.agentSystemId}: ${text}`, locale);
}
}
}
else if (user.agentMode === "human") {
let agent = await sec.getUserFromSystemId(user.agentSystemId);
if (text === '/t') {
await this.sendToDevice(user.userSystemId, `Você já está sendo atendido por ${agent.userSystemId}.`);
await this.sendToDeviceEx(user.userSystemId, `Você já está sendo atendido por ${agent.userSystemId}.`, locale);
}
else if (text === '/qt' || text === "Sair" || text === "Fechar" ) {
else if (text === '/qt' || text === "Sair" || text === "Fechar") {
// TODO: Transfers only in pt-br for now.
await this.sendToDevice(id, Messages[this.locale].notify_end_transfer(this.min.instance.botId));
await this.sendToDevice(user.agentSystemId, Messages[this.locale].notify_end_transfer(this.min.instance.botId));
await this.sendToDeviceEx(id, Messages[this.locale].notify_end_transfer(this.min.instance.botId), locale);
await this.sendToDeviceEx(user.agentSystemId, Messages[this.locale].notify_end_transfer(this.min.instance.botId), locale);
await sec.updateCurrentAgent(id, this.min.instance.instanceId, null);
}
else {
GBLog.info(`USER (${id}) TO AGENT ${user.userSystemId}: ${text}`);
this.sendToDevice(user.agentSystemId, `${id}: ${text}`);
this.sendToDeviceEx(user.agentSystemId, `${id}: ${text}`, locale);
}
}
@ -408,6 +409,16 @@ export class WhatsappDirectLine extends GBService {
await this.sendFileToDevice(to, url, 'Audio', msg);
}
public async sendToDeviceEx(to, msg, locale) {
const text = await this.min.conversationalService.translate(
this.min.instance.translatorKey,
this.min.instance.translatorEndpoint,
msg,
locale
);
await this.sendToDevice(to, text);
}
public async sendToDevice(to, msg) {
const cmd = '/audio ';

View file

@ -158,7 +158,7 @@ export class GBServer {
GBLog.info(`Publishing instances...`);
const packageInstance = await importer.importIfNotExistsBotPackage(
GBConfigService.get('CLOUD_GROUP'),
GBConfigService.get('BOT_ID'),
'boot.gbot',
'packages/boot.gbot'
);