diff --git a/packages/admin.gbapp/dialogs/AdminDialog.ts b/packages/admin.gbapp/dialogs/AdminDialog.ts index 31ee9f15..697106b3 100644 --- a/packages/admin.gbapp/dialogs/AdminDialog.ts +++ b/packages/admin.gbapp/dialogs/AdminDialog.ts @@ -213,7 +213,7 @@ export class AdminDialog extends IGBDialog { min.dialogs.add( new WaterfallDialog('/publish', [ async step => { - if (step.activeDialog.state.options.confirm) { + if (step.activeDialog.state.options.confirm || process.env.ADMIN_OPEN_PUBLISH === "true") { return await step.next('sim'); } else { const locale = step.context.activity.locale; @@ -232,7 +232,7 @@ export class AdminDialog extends IGBDialog { if (step.activeDialog.state.options.firstTime) { canPublish = true; } else { - canPublish = AdminDialog.canPublish(min, from); + canPublish = AdminDialog.canPublish(min, from) || process.env.ADMIN_OPEN_PUBLISH === "true"; } if (!canPublish) { diff --git a/packages/core.gbapp/services/GBAPIService.ts b/packages/core.gbapp/services/GBAPIService.ts index 0af1fda2..46659111 100644 --- a/packages/core.gbapp/services/GBAPIService.ts +++ b/packages/core.gbapp/services/GBAPIService.ts @@ -183,26 +183,26 @@ class SysClass { await client .api( - `https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${libraryId}/drive/items/${document[0].id}/workbook/worksheets('Sheet1')/range(address='A1:Z1')/insert` + `https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${libraryId}/drive/items/${document[0].id}/workbook/worksheets('Sheet1')/range(address='A2:Z2')/insert` ) .post({}); if (!document || document.length === 0) { throw `File '${file}' specified on save GBasic command SAVE not found. Check the .gbdata or the .gbdialog associated.`; } - if (args.length > 27) { - throw `File '${file}' has a SAVE call with more than 27 arguments. Check the .gbdialog associated.`; + if (args.length > 128) { + throw `File '${file}' has a SAVE call with more than 128 arguments. Check the .gbdialog associated.`; } let body = { values: [[]] }; - for (let index = 0; index < 26; index++) { + for (let index = 0; index < 128; index++) { body.values[0][index] = args[index]; } let res2 = await client .api( - `https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${libraryId}/drive/items/${document[0].id}/workbook/worksheets('Sheet1')/range(address='A2:Z2')` + `https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${libraryId}/drive/items/${document[0].id}/workbook/worksheets('Sheet1')/range(address='A2:DX2')` ) .patch(body); } catch (error) { @@ -547,7 +547,7 @@ export class DialogClass { return await step.beginDialog('/t'); } - public async hear(step, promise, previousResolve, kind) { + public async hear(step, promise, previousResolve, kind, ...args) { function random(low, high) { return Math.random() * (high - low) + low; } @@ -555,7 +555,7 @@ export class DialogClass { this.min.cbMap[idPromise] = {}; this.min.cbMap[idPromise].promise = promise; - const opts = { id: idPromise, previousResolve: previousResolve, kind: kind }; + const opts = { id: idPromise, previousResolve: previousResolve, kind: kind, args }; if (previousResolve !== undefined) { previousResolve(opts); } else { diff --git a/packages/core.gbapp/services/GBMinService.ts b/packages/core.gbapp/services/GBMinService.ts index 1c90d9fe..70238536 100644 --- a/packages/core.gbapp/services/GBMinService.ts +++ b/packages/core.gbapp/services/GBMinService.ts @@ -748,6 +748,11 @@ export class GBMinService { // Adds message to the analytics layer. if (user) { + + if (!user.conversation){ + user.conversation = await analytics.createConversation(user.systemUser); + } + message = await analytics.createMessage( min.instance.instanceId, user.conversation, diff --git a/packages/core.gbapp/services/GBVMService.ts b/packages/core.gbapp/services/GBVMService.ts index 1b5fe7f1..335a0673 100644 --- a/packages/core.gbapp/services/GBVMService.ts +++ b/packages/core.gbapp/services/GBVMService.ts @@ -160,13 +160,48 @@ export class GBVMService extends GBService { username = this.getUserName(step); mobile = this.getUserMobile(step); ubound = function(list){return list.length}; + ${code} `; // Keywords from General Bots BASIC. - code = code.replace(/(hear email)/gi, `email = askEmail()`); + code = code.replace(/hear email/gi, ($0) => { + return `email = hear("email")`; + }); + + code = code.replace(/hear (.*) as (\w+)/gi, ($0, $1, $2) => { + return `${$2} = hear("menu", ${$1})`; + }); + + code = code.replace(/hear number as (\w+)/gi, ($0, $1, $2) => { + return `${$1} = hear("number")`; + }); + + code = code.replace(/hear name as (\w+)/gi, ($0, $1, $2) => { + return `${$1} = hear("name")`; + }); + + code = code.replace(/hear date as (\w+)/gi, ($0, $1, $2) => { + return `${$1} = hear("date")`; + }); + + code = code.replace(/hear date as (\w+)/gi, ($0, $1, $2) => { + return `${$1} = hear("hour")`; + }); + + code = code.replace(/hear date as (\w+)/gi, ($0, $1, $2) => { + return `${$1} = hear("phone")`; + }); + + code = code.replace(/hear date as (\w+)/gi, ($0, $1, $2) => { + return `${$1} = hear("money")`; + }); + + code = code.replace(/hear date as (\w+)/gi, ($0, $1, $2) => { + return `${$1} = hear("zip")`; + }); code = code.replace(/(hear on)(\s)(.*)/gi, ($0, $1, $2, $3) => { return `sys().gotoDialog(${$3})\n`; @@ -276,7 +311,7 @@ export class GBVMService extends GBService { // Finds all hear calls. let parsedCode = code; - const hearExp = /(\w+).*hear.*\(\)/; + const hearExp = /(\w+).*hear.*\((.*)\)/; let match1; @@ -286,6 +321,7 @@ export class GBVMService extends GBService { // Writes async body. const variable = match1[1]; // Construct variable = hear (). + const args = match1[2]; // Construct variable = hear ("A", "B"). const promiseName = `promiseFor${variable}`; parsedCode = code.substring(pos, pos + match1.index); @@ -326,13 +362,7 @@ export class GBVMService extends GBService { parsedCode += '}\n'; - let kind = 'general'; - if (variable === "YES OR NO") { - kind = 'yesOrNo'; - } - - - parsedCode += `hear (step, ${promiseName}, resolve, '${kind}');\n`; + parsedCode += `hear (step, ${promiseName}, resolve, ${args});\n`; parsedCode += code.substring(pos + match1[0].length); // A interaction will be made for each hear. @@ -407,9 +437,9 @@ export class GBVMService extends GBService { step.activeDialog.state.options.id = (step.options as any).id; step.activeDialog.state.options.previousResolve = (step.options as any).previousResolve; - if (step.options['kind'] === "yesOrNo") { + if (step.options['args']) { - GBLog.info('BASIC: Asking for input (HEAR YES OR NO).'); + GBLog.info(`BASIC: Asking for input (HEAR with ${step.options['args'][0]}).`); } else { @@ -425,7 +455,7 @@ export class GBVMService extends GBService { } let result = step.result; - if (step.activeDialog.state.options['boolean']) { + if (step.activeDialog.state.options['kind'] === "boolean") { if (isIntentYes(step.context.locale, step.result)) { result = true; @@ -435,29 +465,78 @@ export class GBVMService extends GBService { } } - else if (step.activeDialog.state.options['email']) { + else if (step.activeDialog.state.options['kind'] === "email") { // e@e.com } - else if (step.activeDialog.state.options['number']) { - // MAX and MIN. + else if (step.activeDialog.state.options['kind'] === "name") { + const extractEntity = text => { + return text.match(/[_a-zA-Z][_a-zA-Z0-9]{0,16}/gi); + }; + + const value = extractEntity(step.result); + + if (value === null || value.length != 1) { + await step.context.sendActivity("Por favor, digite um nome válido."); + return await step.replaceDialog('/hear', step.activeDialog.state.options); + } + + result = value; + } - else if (step.activeDialog.state.options['date']) { - // 12/12/2020 OK + else if (step.activeDialog.state.options['kind'] === "number") { + const extractEntity = text => { + return text.match(/\d+/gi); + }; + + const value = extractEntity(step.result); + + if (value === null || value.length != 1) { + await step.context.sendActivity("Por favor, digite um número válido."); + return await step.replaceDialog('/hear', step.activeDialog.state.options); + } + + result = value; } - else if (step.activeDialog.state.options['hour']) { + else if (step.activeDialog.state.options['kind'] === "date") { + const extractEntity = text => { + return text.match(/(^(((0[1-9]|1[0-9]|2[0-8])[\/](0[1-9]|1[012]))|((29|30|31)[\/](0[13578]|1[02]))|((29|30)[\/](0[4,6,9]|11)))[\/](19|[2-9][0-9])\d\d$)|(^29[\/]02[\/](19|[2-9][0-9])(00|04|08|12|16|20|24|28|32|36|40|44|48|52|56|60|64|68|72|76|80|84|88|92|96)$)/gi); + }; + + const value = extractEntity(step.result); + + if (value === null || value.length != 1) { + await step.context.sendActivity("Por favor, digite uma data no formato 12/12/2020."); + return await step.replaceDialog('/hear', step.activeDialog.state.options); + } + + result = value; + } + else if (step.activeDialog.state.options['kind'] === "hour") { // 12:12 } - else if (step.activeDialog.state.options['money']) { + else if (step.activeDialog.state.options['kind'] === "money") { // 23,12 } - else if (step.activeDialog.state.options['phone']) { + else if (step.activeDialog.state.options['kind'] === "phone") { // +55 21 } - else if (step.activeDialog.state.options['zipcode']) { + else if (step.activeDialog.state.options['kind'] === "zipcode") { // 12333-222 } - else if (step.activeDialog.state.options['menu']) { - // ['drums', 'guitar', 'bass']; kpmSearch + else if (step.activeDialog.state.options['kind'] === "menu") { + + const list = step.activeDialog.state.options['args']; + result = null; + await CollectionUtil.asyncForEach(list, async item => { + if (GBConversationalService.kmpSearch(step.result, item) != -1) { + result = item; + } + }); + + if (result === null) { + await step.context.sendActivity(`Escolha, por favor, um destes modelos listados.`); + return await step.replaceDialog('/hear', step.activeDialog.state.options); + } } const id = step.activeDialog.state.options.id;