From 80229804380624e62b384e334840494a8da0d8fc Mon Sep 17 00:00:00 2001 From: Rodrigo Rodriguez Date: Mon, 21 Aug 2023 13:21:49 -0300 Subject: [PATCH] new (basic.gbapp): NOTE keyword. --- packages/basic.gblib/services/GBVMService.ts | 19 +++++---- .../basic.gblib/services/SystemKeywords.ts | 18 +------- packages/core.gbapp/services/GBMinService.ts | 11 +++-- packages/kb.gbapp/dialogs/AskDialog.ts | 41 +++++++++---------- 4 files changed, 40 insertions(+), 49 deletions(-) diff --git a/packages/basic.gblib/services/GBVMService.ts b/packages/basic.gblib/services/GBVMService.ts index 1057b1b7..94f48695 100644 --- a/packages/basic.gblib/services/GBVMService.ts +++ b/packages/basic.gblib/services/GBVMService.ts @@ -418,13 +418,7 @@ export class GBVMService extends GBService { let code = min.sandBoxMap[text]; const channel = step? step.context.activity.channelId : 'web'; - const pid = GBAdminService.getNumberIdentifier(); - GBServer.globals.processes[pid] = { - pid: pid, - userId: user? user.userId:0, - instanceId: min.instance.instanceId, - channel: channel - }; + const pid = GBVMService.createProcessInfo(user, min, channel); const dk = new DialogKeywords(); const sys = new SystemKeywords(); await dk.setFilter ({pid: pid, value: null }); @@ -497,4 +491,15 @@ export class GBVMService extends GBService { return result; } + + public static createProcessInfo(user: GuaribasUser, min: GBMinInstance, channel: any) { + const pid = GBAdminService.getNumberIdentifier(); + GBServer.globals.processes[pid] = { + pid: pid, + userId: user ? user.userId : 0, + instanceId: min.instance.instanceId, + channel: channel + }; + return pid; + } } diff --git a/packages/basic.gblib/services/SystemKeywords.ts b/packages/basic.gblib/services/SystemKeywords.ts index bf7bf485..fe3fae95 100644 --- a/packages/basic.gblib/services/SystemKeywords.ts +++ b/packages/basic.gblib/services/SystemKeywords.ts @@ -644,12 +644,7 @@ export class SystemKeywords { * */ public async note({ pid, text }): Promise { - const { min } = await DialogKeywords.getProcessInfo(pid); - await this.internalNote(min,text ); - } - - private async internalNote(min, text): Promise { - await this.internalSave(min, 'Notes.xlsx', [text]); + await this.save({pid, file:"Notes.xlsx", args:[text]} ); } /** @@ -660,17 +655,6 @@ export class SystemKeywords { */ public async save({ pid, file, args }): Promise { const { min } = await DialogKeywords.getProcessInfo(pid); - await this.internalSave(min, file, args); - } - - /** - * Saves the content of several variables to a new row in a tabular file. - * - * @exaple SAVE "customers.xlsx", name, email, phone, address, city, state, country - * - */ - - private async internalSave(min, file, args): Promise { GBLog.info(`BASIC: Saving '${file}' (SAVE). Args: ${args.join(',')}.`); let { baseUrl, client } = await GBDeployer.internalGetDriveClient(min); const botId = min.instance.botId; diff --git a/packages/core.gbapp/services/GBMinService.ts b/packages/core.gbapp/services/GBMinService.ts index 84e03fbb..acaaddeb 100644 --- a/packages/core.gbapp/services/GBMinService.ts +++ b/packages/core.gbapp/services/GBMinService.ts @@ -950,6 +950,7 @@ export class GBMinService { const analytics = new AnalyticsService(); const conversation = await analytics.createConversation(user); + } await sec.updateConversationReferenceById(userId, conversationReference); @@ -1058,8 +1059,10 @@ export class GBMinService { } } else if (context.activity.type === 'message') { // Processes messages activities. + const pid = GBVMService.createProcessInfo(user, min, step.context.activity.channelId); + step.context.activity['pid'] = pid; - await this.processMessageActivity(context, min, step); + await this.processMessageActivity(context, min, step, pid); } else if (context.activity.type === 'event') { // Processes events activities. @@ -1249,7 +1252,7 @@ export class GBMinService { /** * Called to handle all text messages sent and received by the bot. */ - private async processMessageActivity(context, min: GBMinInstance, step: GBDialogStep) { + private async processMessageActivity(context, min: GBMinInstance, step: GBDialogStep, pid) { const sec = new SecService(); if (!context.activity.text) { @@ -1406,9 +1409,9 @@ export class GBMinService { step.context.activity['text'] = text; const notes = min.core.getParam(min.instance, 'Notes', null); - if (notes) { + if (notes) { const sys = new SystemKeywords(); - await sys['internalNote'](min, text); + await sys.note({pid, text}); return; } diff --git a/packages/kb.gbapp/dialogs/AskDialog.ts b/packages/kb.gbapp/dialogs/AskDialog.ts index 13407e03..2aca29d3 100644 --- a/packages/kb.gbapp/dialogs/AskDialog.ts +++ b/packages/kb.gbapp/dialogs/AskDialog.ts @@ -106,14 +106,12 @@ export class AskDialog extends IGBDialog { if (step.options && step.options.firstTime) { text = Messages[locale].ask_first_time; - } - else if (step.options && step.options.isReturning && !step.context.activity.group) { + } else if (step.options && step.options.isReturning && !step.context.activity.group) { const askForMore = min.core.getParam(min.instance, 'Ask For More', null); - text = askForMore?Messages[locale].anything_else: ''; - } - else if (step.context.activity.group || (step.options && step.options.emptyPrompt)) { - text = ''; + text = askForMore ? Messages[locale].anything_else : ''; + } else if (step.context.activity.group || (step.options && step.options.emptyPrompt)) { + return await step.next(); } else if (user.subjects.length > 0) { text = Messages[locale].which_question; } else { @@ -153,14 +151,18 @@ export class AskDialog extends IGBDialog { handled = true; } }); - data.step = null; - GBLog.info(`/answer being called from getAskDialog.`); - await step.beginDialog(nextDialog ? nextDialog : '/answer', { - data: data, - query: text, - user: user ? user['dataValues'] : null, - message: text - }); + if (!handled) { + data.step = null; + GBLog.info(`/answer being called from getAskDialog.`); + await step.beginDialog(nextDialog ? nextDialog : '/answer', { + data: data, + query: text, + user: user ? user['dataValues'] : null, + message: text + }); + } else { + return await step.next(); + } } else { return await step.next(); } @@ -339,8 +341,7 @@ export class AskDialog extends IGBDialog { const mainName = GBVMService.getMethodNameFromVBSFilename(text); await step.endDialog(); return await GBVMService.callVM(mainName, min, step, user, this.deployer, false); - } - else if (text.startsWith('/')) { + } else if (text.startsWith('/')) { return await step.replaceDialog(text, { answer: answer }); } else { await service.sendAnswer(min, AskDialog.getChannel(step), step, answer); @@ -408,8 +409,8 @@ export class AskDialog extends IGBDialog { // Removes instructions, just code. response = response.replace(/Copy code/gim, '\n'); - let lines = response.split('\n') - let filteredLines = lines.filter(line => /\s*\d+\s*.*/.test(line)) + let lines = response.split('\n'); + let filteredLines = lines.filter(line => /\s*\d+\s*.*/.test(line)); response = filteredLines.join('\n'); // Gets dialog name and file handling @@ -428,7 +429,6 @@ export class AskDialog extends IGBDialog { message = `Dialog is ready! Let's run:`; await min.conversationalService.sendText(min, step, message); - let sec = new SecService(); const member = step.context.activity.from; const user = await sec.ensureUser( @@ -443,8 +443,7 @@ export class AskDialog extends IGBDialog { await step.endDialog(); - await GBVMService.callVM(dialogName.toLowerCase(), - min, step, user, this.deployer, false); + await GBVMService.callVM(dialogName.toLowerCase(), min, step, user, this.deployer, false); } } ];