diff --git a/packages/core.gbapp/services/GBMinService.ts b/packages/core.gbapp/services/GBMinService.ts index 88611202..3179e391 100644 --- a/packages/core.gbapp/services/GBMinService.ts +++ b/packages/core.gbapp/services/GBMinService.ts @@ -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. diff --git a/packages/kb.gbapp/dialogs/AskDialog.ts b/packages/kb.gbapp/dialogs/AskDialog.ts index e6fa00d6..0671afda 100644 --- a/packages/kb.gbapp/dialogs/AskDialog.ts +++ b/packages/kb.gbapp/dialogs/AskDialog.ts @@ -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); diff --git a/packages/whatsapp.gblib/services/WhatsappDirectLine.ts b/packages/whatsapp.gblib/services/WhatsappDirectLine.ts index c729507d..40ee2553 100644 --- a/packages/whatsapp.gblib/services/WhatsappDirectLine.ts +++ b/packages/whatsapp.gblib/services/WhatsappDirectLine.ts @@ -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); @@ -195,26 +195,32 @@ 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") { @@ -222,7 +228,7 @@ export class WhatsappDirectLine extends GBService { 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)); @@ -230,7 +236,7 @@ export class WhatsappDirectLine extends GBService { 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}`); }