fix(core.gbapp): Improvements on BASIC with built-in validators.
This commit is contained in:
parent
4fe67c8704
commit
af10172dd4
4 changed files with 116 additions and 32 deletions
|
@ -213,7 +213,7 @@ export class AdminDialog extends IGBDialog {
|
||||||
min.dialogs.add(
|
min.dialogs.add(
|
||||||
new WaterfallDialog('/publish', [
|
new WaterfallDialog('/publish', [
|
||||||
async step => {
|
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');
|
return await step.next('sim');
|
||||||
} else {
|
} else {
|
||||||
const locale = step.context.activity.locale;
|
const locale = step.context.activity.locale;
|
||||||
|
@ -232,7 +232,7 @@ export class AdminDialog extends IGBDialog {
|
||||||
if (step.activeDialog.state.options.firstTime) {
|
if (step.activeDialog.state.options.firstTime) {
|
||||||
canPublish = true;
|
canPublish = true;
|
||||||
} else {
|
} else {
|
||||||
canPublish = AdminDialog.canPublish(min, from);
|
canPublish = AdminDialog.canPublish(min, from) || process.env.ADMIN_OPEN_PUBLISH === "true";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!canPublish) {
|
if (!canPublish) {
|
||||||
|
|
|
@ -183,26 +183,26 @@ class SysClass {
|
||||||
|
|
||||||
await client
|
await client
|
||||||
.api(
|
.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({});
|
.post({});
|
||||||
|
|
||||||
if (!document || document.length === 0) {
|
if (!document || document.length === 0) {
|
||||||
throw `File '${file}' specified on save GBasic command SAVE not found. Check the .gbdata or the .gbdialog associated.`;
|
throw `File '${file}' specified on save GBasic command SAVE not found. Check the .gbdata or the .gbdialog associated.`;
|
||||||
}
|
}
|
||||||
if (args.length > 27) {
|
if (args.length > 128) {
|
||||||
throw `File '${file}' has a SAVE call with more than 27 arguments. Check the .gbdialog associated.`;
|
throw `File '${file}' has a SAVE call with more than 128 arguments. Check the .gbdialog associated.`;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = { values: [[]] };
|
let body = { values: [[]] };
|
||||||
|
|
||||||
for (let index = 0; index < 26; index++) {
|
for (let index = 0; index < 128; index++) {
|
||||||
body.values[0][index] = args[index];
|
body.values[0][index] = args[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
let res2 = await client
|
let res2 = await client
|
||||||
.api(
|
.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);
|
.patch(body);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -547,7 +547,7 @@ export class DialogClass {
|
||||||
return await step.beginDialog('/t');
|
return await step.beginDialog('/t');
|
||||||
}
|
}
|
||||||
|
|
||||||
public async hear(step, promise, previousResolve, kind) {
|
public async hear(step, promise, previousResolve, kind, ...args) {
|
||||||
function random(low, high) {
|
function random(low, high) {
|
||||||
return Math.random() * (high - low) + low;
|
return Math.random() * (high - low) + low;
|
||||||
}
|
}
|
||||||
|
@ -555,7 +555,7 @@ export class DialogClass {
|
||||||
this.min.cbMap[idPromise] = {};
|
this.min.cbMap[idPromise] = {};
|
||||||
this.min.cbMap[idPromise].promise = promise;
|
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) {
|
if (previousResolve !== undefined) {
|
||||||
previousResolve(opts);
|
previousResolve(opts);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -748,6 +748,11 @@ export class GBMinService {
|
||||||
// Adds message to the analytics layer.
|
// Adds message to the analytics layer.
|
||||||
|
|
||||||
if (user) {
|
if (user) {
|
||||||
|
|
||||||
|
if (!user.conversation){
|
||||||
|
user.conversation = await analytics.createConversation(user.systemUser);
|
||||||
|
}
|
||||||
|
|
||||||
message = await analytics.createMessage(
|
message = await analytics.createMessage(
|
||||||
min.instance.instanceId,
|
min.instance.instanceId,
|
||||||
user.conversation,
|
user.conversation,
|
||||||
|
|
|
@ -161,12 +161,47 @@ export class GBVMService extends GBService {
|
||||||
mobile = this.getUserMobile(step);
|
mobile = this.getUserMobile(step);
|
||||||
ubound = function(list){return list.length};
|
ubound = function(list){return list.length};
|
||||||
|
|
||||||
|
|
||||||
${code}
|
${code}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
// Keywords from General Bots BASIC.
|
// 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) => {
|
code = code.replace(/(hear on)(\s)(.*)/gi, ($0, $1, $2, $3) => {
|
||||||
return `sys().gotoDialog(${$3})\n`;
|
return `sys().gotoDialog(${$3})\n`;
|
||||||
|
@ -276,7 +311,7 @@ export class GBVMService extends GBService {
|
||||||
// Finds all hear calls.
|
// Finds all hear calls.
|
||||||
|
|
||||||
let parsedCode = code;
|
let parsedCode = code;
|
||||||
const hearExp = /(\w+).*hear.*\(\)/;
|
const hearExp = /(\w+).*hear.*\((.*)\)/;
|
||||||
|
|
||||||
let match1;
|
let match1;
|
||||||
|
|
||||||
|
@ -286,6 +321,7 @@ export class GBVMService extends GBService {
|
||||||
// Writes async body.
|
// Writes async body.
|
||||||
|
|
||||||
const variable = match1[1]; // Construct variable = hear ().
|
const variable = match1[1]; // Construct variable = hear ().
|
||||||
|
const args = match1[2]; // Construct variable = hear ("A", "B").
|
||||||
const promiseName = `promiseFor${variable}`;
|
const promiseName = `promiseFor${variable}`;
|
||||||
|
|
||||||
parsedCode = code.substring(pos, pos + match1.index);
|
parsedCode = code.substring(pos, pos + match1.index);
|
||||||
|
@ -326,13 +362,7 @@ export class GBVMService extends GBService {
|
||||||
parsedCode += '}\n';
|
parsedCode += '}\n';
|
||||||
|
|
||||||
|
|
||||||
let kind = 'general';
|
parsedCode += `hear (step, ${promiseName}, resolve, ${args});\n`;
|
||||||
if (variable === "YES OR NO") {
|
|
||||||
kind = 'yesOrNo';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
parsedCode += `hear (step, ${promiseName}, resolve, '${kind}');\n`;
|
|
||||||
parsedCode += code.substring(pos + match1[0].length);
|
parsedCode += code.substring(pos + match1[0].length);
|
||||||
|
|
||||||
// A interaction will be made for each hear.
|
// 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.id = (step.options as any).id;
|
||||||
step.activeDialog.state.options.previousResolve = (step.options as any).previousResolve;
|
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 {
|
else {
|
||||||
|
|
||||||
|
@ -425,7 +455,7 @@ export class GBVMService extends GBService {
|
||||||
}
|
}
|
||||||
|
|
||||||
let result = step.result;
|
let result = step.result;
|
||||||
if (step.activeDialog.state.options['boolean']) {
|
if (step.activeDialog.state.options['kind'] === "boolean") {
|
||||||
|
|
||||||
if (isIntentYes(step.context.locale, step.result)) {
|
if (isIntentYes(step.context.locale, step.result)) {
|
||||||
result = true;
|
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
|
// e@e.com
|
||||||
}
|
}
|
||||||
else if (step.activeDialog.state.options['number']) {
|
else if (step.activeDialog.state.options['kind'] === "name") {
|
||||||
// MAX and MIN.
|
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);
|
||||||
}
|
}
|
||||||
else if (step.activeDialog.state.options['date']) {
|
|
||||||
// 12/12/2020 OK
|
result = value;
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (step.activeDialog.state.options['hour']) {
|
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['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
|
// 12:12
|
||||||
}
|
}
|
||||||
else if (step.activeDialog.state.options['money']) {
|
else if (step.activeDialog.state.options['kind'] === "money") {
|
||||||
// 23,12
|
// 23,12
|
||||||
}
|
}
|
||||||
else if (step.activeDialog.state.options['phone']) {
|
else if (step.activeDialog.state.options['kind'] === "phone") {
|
||||||
// +55 21
|
// +55 21
|
||||||
}
|
}
|
||||||
else if (step.activeDialog.state.options['zipcode']) {
|
else if (step.activeDialog.state.options['kind'] === "zipcode") {
|
||||||
// 12333-222
|
// 12333-222
|
||||||
}
|
}
|
||||||
else if (step.activeDialog.state.options['menu']) {
|
else if (step.activeDialog.state.options['kind'] === "menu") {
|
||||||
// ['drums', 'guitar', 'bass']; kpmSearch
|
|
||||||
|
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;
|
const id = step.activeDialog.state.options.id;
|
||||||
|
|
Loading…
Add table
Reference in a new issue