Skip to content

Commit

Permalink
fix(whatsapp.gblib): Transfer bug fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigorodriguez committed May 16, 2020
1 parent 230a9e3 commit ed15c85
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 31 deletions.
2 changes: 1 addition & 1 deletion packages/core.gbapp/services/GBMinService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ export class GBMinService {
const { min, adapter, conversationState } = await this.buildBotAdapter(instance, GBServer.globals.sysPackages);
GBServer.globals.minInstances.push(min);

await this.deployer.deployPackage(min, 'packages/default.gbdialog');
// TODO: await this.deployer.deployPackage(min, 'packages/default.gbdialog');
await this.deployer.deployPackage(min, 'packages/default.gbtheme');

// Install per bot deployed packages.
Expand Down
12 changes: 3 additions & 9 deletions packages/kb.gbapp/dialogs/AskDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,17 +183,11 @@ export class AskDialog extends IGBDialog {

private static async handleAnswer(service: KBService, min: GBMinInstance, step: any, answer: GuaribasAnswer) {

const dialogSufix = 'dialog:';
const urlSufix = 'url:';
const scriptSufix = 'script:';

if (answer.content.startsWith(dialogSufix)) {
let dialogName = answer.content.substring(dialogSufix.length);
return await step.replaceDialog(`/${dialogName}`, { isReturning: true });
} else if (answer.content.startsWith(scriptSufix)) {
let scriptName = answer.content.substring(scriptSufix.length);

return await GBMinService.callVM(scriptName, min, step);
if (answer.content.endsWith('.docx')) {
const mainName = answer.content.replace(/\s|\-/g, '').split('.')[0];
return await GBMinService.callVM(mainName, min, step);
} else {
await service.sendAnswer(min, AskDialog.getChannel(step), step, answer);

Expand Down
48 changes: 27 additions & 21 deletions packages/whatsapp.gblib/services/WhatsappDirectLine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ export class WhatsappDirectLine extends GBService {
GBLog.info(`GBWhatsapp: Checking server...`);

const options = {
url: urlJoin(this.whatsappServiceUrl, 'status') + `?token=${this.min.instance.whatsappServiceKey}` ,
url: urlJoin(this.whatsappServiceUrl, 'status') + `?token=${this.min.instance.whatsappServiceKey}`,
method: 'GET',

};

const res = await request(options);
Expand Down Expand Up @@ -195,42 +195,48 @@ export class WhatsappDirectLine extends GBService {

if (user.agentMode === "self") {
let manualUser = await sec.getUserFromAgentSystemId(id);
const cmd = '/reply ';
if (text.startsWith(cmd)) {
let filename = text.substr(cmd.length);
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.`);
} 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 sec.updateCurrentAgent(manualUser.userSystemId, this.min.instance.instanceId, null);
if (manualUser === null) {
await sec.updateCurrentAgent(id, this.min.instance.instanceId, null);
}
else {
GBLog.info(`HUMAN AGENT (${id}) TO USER ${manualUser.userSystemId}: ${text}`);
this.sendToDevice(manualUser.userSystemId, `${manualUser.userSystemId}: ${text}`);
const cmd = '/reply ';
if (text.startsWith(cmd)) {
let filename = text.substr(cmd.length);
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.`);
} 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 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}`);
}
}
}
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}.`);
}
else if (text === '/qt') {
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 sec.updateCurrentAgent(id, this.min.instance.instanceId, null);
}
else {
GBLog.info(`USER (${id}) TO AGENT ${agent.userSystemId}: ${text}`);
GBLog.info(`USER (${id}) TO AGENT ${user.userSystemId}: ${text}`);
this.sendToDevice(user.agentSystemId, `${id}: ${text}`);
}

Expand Down

0 comments on commit ed15c85

Please sign in to comment.