fix(core.gbapp): #344 fix regarding SET FILTER keyword.
This commit is contained in:
parent
f2d6bbe47a
commit
db7ed36707
5 changed files with 66 additions and 39 deletions
|
@ -46,7 +46,7 @@ import { Messages } from '../strings.js';
|
||||||
import * as Fs from 'fs';
|
import * as Fs from 'fs';
|
||||||
import { CollectionUtil } from 'pragmatismo-io-framework';
|
import { CollectionUtil } from 'pragmatismo-io-framework';
|
||||||
import { GBConversationalService } from '../../core.gbapp/services/GBConversationalService.js';
|
import { GBConversationalService } from '../../core.gbapp/services/GBConversationalService.js';
|
||||||
import phoneUtil from 'google-libphonenumber';
|
import phoneUtil from 'google-libphonenumber';
|
||||||
import phone from 'phone';
|
import phone from 'phone';
|
||||||
import DateDiff from 'date-diff';
|
import DateDiff from 'date-diff';
|
||||||
import tesseract from 'node-tesseract-ocr';
|
import tesseract from 'node-tesseract-ocr';
|
||||||
|
@ -536,7 +536,7 @@ export class DialogKeywords {
|
||||||
this['id'] = new SystemKeywords().getRandomId();
|
this['id'] = new SystemKeywords().getRandomId();
|
||||||
}
|
}
|
||||||
|
|
||||||
private isUserSystemParam(name: string): Boolean {
|
public static isUserSystemParam(name: string): Boolean {
|
||||||
const names = [
|
const names = [
|
||||||
'welcomed',
|
'welcomed',
|
||||||
'loaded',
|
'loaded',
|
||||||
|
@ -553,7 +553,7 @@ export class DialogKeywords {
|
||||||
return names.indexOf(name) > -1;
|
return names.indexOf(name) > -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async setOption({ pid, name, value }) {
|
public static async setOption({ pid, name, value }) {
|
||||||
// if (this.isUserSystemParam(name)) {
|
// if (this.isUserSystemParam(name)) {
|
||||||
// throw new Error(`Not possible to define ${name} as it is a reserved system param name.`);
|
// throw new Error(`Not possible to define ${name} as it is a reserved system param name.`);
|
||||||
// }
|
// }
|
||||||
|
@ -564,7 +564,7 @@ export class DialogKeywords {
|
||||||
return { min, user, params };
|
return { min, user, params };
|
||||||
}
|
}
|
||||||
|
|
||||||
private async getOption({ pid, name }) {
|
public static async getOption({ pid, name }) {
|
||||||
if (this.isUserSystemParam(name)) {
|
if (this.isUserSystemParam(name)) {
|
||||||
throw new Error(`Not possible to retrieve ${name} system param.`);
|
throw new Error(`Not possible to retrieve ${name} system param.`);
|
||||||
}
|
}
|
||||||
|
@ -580,7 +580,7 @@ export class DialogKeywords {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public async setMaxLines({ pid, count }) {
|
public async setMaxLines({ pid, count }) {
|
||||||
await this.setOption({ pid, name: 'maxLines', value: count });
|
await DialogKeywords.setOption({ pid, name: 'maxLines', value: count });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -590,7 +590,7 @@ export class DialogKeywords {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public async setUserParam({ pid, name, value }) {
|
public async setUserParam({ pid, name, value }) {
|
||||||
await this.setOption({ pid, name, value });
|
await DialogKeywords.setOption({ pid, name, value });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -600,7 +600,7 @@ export class DialogKeywords {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public async getUserParam({ pid, name }) {
|
public async getUserParam({ pid, name }) {
|
||||||
await this.getOption({ pid, name });
|
await DialogKeywords.getOption({ pid, name });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -610,7 +610,18 @@ export class DialogKeywords {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public async setMaxColumns({ pid, count }) {
|
public async setMaxColumns({ pid, count }) {
|
||||||
await this.setOption({ pid, name: 'setMaxColumns', value: count });
|
await DialogKeywords.setOption({ pid, name: 'setMaxColumns', value: count });
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines a custom user filter for SET calls.
|
||||||
|
*
|
||||||
|
* @example SET FILTER "ColumnName=33"
|
||||||
|
* SET "file.xlsx", "C", "200000"
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public async setFilter({ pid, value }) {
|
||||||
|
await DialogKeywords.setOption({ pid, name: 'filter', value });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -621,7 +632,7 @@ export class DialogKeywords {
|
||||||
*/
|
*/
|
||||||
public async setWholeWord({ pid, on }) {
|
public async setWholeWord({ pid, on }) {
|
||||||
const value = on.trim() === 'on';
|
const value = on.trim() === 'on';
|
||||||
await this.setOption({ pid, name: 'wholeWord', value: value });
|
await DialogKeywords.setOption({ pid, name: 'wholeWord', value: value });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -632,7 +643,7 @@ export class DialogKeywords {
|
||||||
*/
|
*/
|
||||||
public async setFilterTypes({ pid, types }) {
|
public async setFilterTypes({ pid, types }) {
|
||||||
const value = types;
|
const value = types;
|
||||||
await this.setOption({ pid, name: 'filterTypes', value: value });
|
await DialogKeywords.setOption({ pid, name: 'filterTypes', value: value });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -643,7 +654,7 @@ export class DialogKeywords {
|
||||||
*/
|
*/
|
||||||
public async setTheme({ pid, theme }) {
|
public async setTheme({ pid, theme }) {
|
||||||
const value = theme.trim();
|
const value = theme.trim();
|
||||||
await this.setOption({ pid, name: 'theme', value: value });
|
await DialogKeywords.setOption({ pid, name: 'theme', value: value });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -654,7 +665,7 @@ export class DialogKeywords {
|
||||||
*/
|
*/
|
||||||
public async setTranslatorOn({ pid, on }) {
|
public async setTranslatorOn({ pid, on }) {
|
||||||
const value = on.trim() === 'on';
|
const value = on.trim() === 'on';
|
||||||
await this.setOption({ pid, name: 'translatorOn', value: value });
|
await DialogKeywords.setOption({ pid, name: 'translatorOn', value: value });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1130,13 +1141,9 @@ export class DialogKeywords {
|
||||||
url = urlJoin(GBServer.globals.publicAddress, min.botId, 'cache', Path.basename(localName));
|
url = urlJoin(GBServer.globals.publicAddress, min.botId, 'cache', Path.basename(localName));
|
||||||
|
|
||||||
GBLog.info(`BASIC: WebAutomation: Sending the file ${url} to mobile ${mobile}.`);
|
GBLog.info(`BASIC: WebAutomation: Sending the file ${url} to mobile ${mobile}.`);
|
||||||
|
} else if (filename.url) {
|
||||||
}
|
|
||||||
|
|
||||||
else if (filename.url)
|
|
||||||
{
|
|
||||||
url = filename.url;
|
url = filename.url;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handles Markdown.
|
// Handles Markdown.
|
||||||
else if (filename.indexOf('.md') > -1) {
|
else if (filename.indexOf('.md') > -1) {
|
||||||
|
@ -1159,7 +1166,7 @@ export class DialogKeywords {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (url){
|
if (url) {
|
||||||
const reply = { type: ActivityTypes.Message, text: caption };
|
const reply = { type: ActivityTypes.Message, text: caption };
|
||||||
|
|
||||||
const imageData = await (await fetch(url)).arrayBuffer();
|
const imageData = await (await fetch(url)).arrayBuffer();
|
||||||
|
@ -1178,7 +1185,6 @@ export class DialogKeywords {
|
||||||
await min.conversationalService['sendOnConversation'](min, user, reply);
|
await min.conversationalService['sendOnConversation'](min, user, reply);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Generates a new QRCode.
|
* Generates a new QRCode.
|
||||||
|
|
|
@ -268,6 +268,8 @@ export class GBVMService extends GBService {
|
||||||
let today = this.today;
|
let today = this.today;
|
||||||
let now = this.now;
|
let now = this.now;
|
||||||
|
|
||||||
|
// Transfers NLP auto variables into global object.
|
||||||
|
|
||||||
for(i in this.variables) {
|
for(i in this.variables) {
|
||||||
global[i] = this.variables[i];
|
global[i] = this.variables[i];
|
||||||
}
|
}
|
||||||
|
@ -286,10 +288,9 @@ export class GBVMService extends GBService {
|
||||||
|
|
||||||
${code}
|
${code}
|
||||||
|
|
||||||
await wa.getCloseHandles({pid: pid});
|
await wa.closeHandles({pid: pid});
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
|
||||||
`;
|
`;
|
||||||
Fs.writeFileSync(jsfile, code);
|
Fs.writeFileSync(jsfile, code);
|
||||||
GBLogEx.info(min, `[GBVMService] Finished loading of ${filename}, JavaScript from Word: \n ${code}`);
|
GBLogEx.info(min, `[GBVMService] Finished loading of ${filename}, JavaScript from Word: \n ${code}`);
|
||||||
|
|
|
@ -432,6 +432,13 @@ export class KeywordsExpressions {
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
keywords[i++] = [
|
||||||
|
/^\s*(set filter)(\s*)(.*)/gim,
|
||||||
|
($0, $1, $2, $3) => {
|
||||||
|
return `await dk.setFilter ({pid: pid, ${$3}})`;
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
keywords[i++] = [
|
keywords[i++] = [
|
||||||
/^\s*set param \s*(.*)\s*as\s*(.*)/gim,
|
/^\s*set param \s*(.*)\s*as\s*(.*)/gim,
|
||||||
($0, $1, $2) => {
|
($0, $1, $2) => {
|
||||||
|
|
|
@ -483,6 +483,16 @@ export class SystemKeywords {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Add a semaphore between FILTER and SET.
|
||||||
|
|
||||||
|
// Processes FILTER option to ensure parallel SET calls.
|
||||||
|
|
||||||
|
const filter = await DialogKeywords.getOption({ pid, name });
|
||||||
|
if (filter) {
|
||||||
|
const row = this.find({ pid, handle: null, args: [filter] });
|
||||||
|
address += row['line'];
|
||||||
|
}
|
||||||
|
|
||||||
// Handles calls for BASIC persistence on sheet files.
|
// Handles calls for BASIC persistence on sheet files.
|
||||||
|
|
||||||
GBLog.info(`BASIC: Defining '${address}' in '${file}' to '${value}' (SET). `);
|
GBLog.info(`BASIC: Defining '${address}' in '${file}' to '${value}' (SET). `);
|
||||||
|
@ -536,7 +546,7 @@ export class SystemKeywords {
|
||||||
GBLog.info(`BASIC: Saving '${file}' (SAVE file).`);
|
GBLog.info(`BASIC: Saving '${file}' (SAVE file).`);
|
||||||
let { baseUrl, client } = await GBDeployer.internalGetDriveClient(min);
|
let { baseUrl, client } = await GBDeployer.internalGetDriveClient(min);
|
||||||
const botId = min.instance.botId;
|
const botId = min.instance.botId;
|
||||||
const path = DialogKeywords.getGBAIPath(min.botId,`gbdrive`);
|
const path = DialogKeywords.getGBAIPath(min.botId, `gbdrive`);
|
||||||
|
|
||||||
// Checks if it is a GB FILE object.
|
// Checks if it is a GB FILE object.
|
||||||
|
|
||||||
|
@ -563,7 +573,7 @@ export class SystemKeywords {
|
||||||
* @exaple SAVE "customers.xlsx", name, email, phone, address, city, state, country
|
* @exaple SAVE "customers.xlsx", name, email, phone, address, city, state, country
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public async save({ pid,file, args }): Promise<any> {
|
public async save({ pid, file, args }): Promise<any> {
|
||||||
const { min, user } = await DialogKeywords.getProcessInfo(pid);
|
const { min, user } = await DialogKeywords.getProcessInfo(pid);
|
||||||
args.shift();
|
args.shift();
|
||||||
GBLog.info(`BASIC: Saving '${file}' (SAVE). Args: ${args.join(',')}.`);
|
GBLog.info(`BASIC: Saving '${file}' (SAVE). Args: ${args.join(',')}.`);
|
||||||
|
@ -589,7 +599,7 @@ export class SystemKeywords {
|
||||||
const address = `A2:${this.numberToLetters(args.length - 1)}2`;
|
const address = `A2:${this.numberToLetters(args.length - 1)}2`;
|
||||||
for (let index = 0; index < args.length; index++) {
|
for (let index = 0; index < args.length; index++) {
|
||||||
let value = args[index];
|
let value = args[index];
|
||||||
if (value && await this.isValidDate({pid, dt:value})) {
|
if (value && (await this.isValidDate({ pid, dt: value }))) {
|
||||||
value = `'${value}`;
|
value = `'${value}`;
|
||||||
}
|
}
|
||||||
body.values[0][index] = value;
|
body.values[0][index] = value;
|
||||||
|
@ -622,7 +632,8 @@ export class SystemKeywords {
|
||||||
} else {
|
} else {
|
||||||
GBLog.info(`BASIC: GET '${addressOrHeaders}' in '${file}'.`);
|
GBLog.info(`BASIC: GET '${addressOrHeaders}' in '${file}'.`);
|
||||||
let { baseUrl, client } = await GBDeployer.internalGetDriveClient(min);
|
let { baseUrl, client } = await GBDeployer.internalGetDriveClient(min);
|
||||||
const botId = min.instance.botId;''
|
const botId = min.instance.botId;
|
||||||
|
('');
|
||||||
const path = DialogKeywords.getGBAIPath(botId, 'gbdata');
|
const path = DialogKeywords.getGBAIPath(botId, 'gbdata');
|
||||||
|
|
||||||
let document = await this.internalGetDocument(client, baseUrl, path, file);
|
let document = await this.internalGetDocument(client, baseUrl, path, file);
|
||||||
|
@ -689,7 +700,7 @@ export class SystemKeywords {
|
||||||
* @see NPM package data-forge
|
* @see NPM package data-forge
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public async find({ pid, handle, args }): Promise<any> {
|
public async find({ pid, handle, args }): Promise<any> {
|
||||||
const { min, user, params } = await DialogKeywords.getProcessInfo(pid);
|
const { min, user, params } = await DialogKeywords.getProcessInfo(pid);
|
||||||
const file = args[0];
|
const file = args[0];
|
||||||
args.shift();
|
args.shift();
|
||||||
|
@ -714,11 +725,11 @@ export class SystemKeywords {
|
||||||
let results;
|
let results;
|
||||||
let header, rows;
|
let header, rows;
|
||||||
let page;
|
let page;
|
||||||
if (handle){
|
if (handle) {
|
||||||
page = WebAutomationServices.getPageByHandle(handle);
|
page = WebAutomationServices.getPageByHandle(handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (handle &&page['$eval'] && WebAutomationServices.isSelector(file)) {
|
if (handle && page['$eval'] && WebAutomationServices.isSelector(file)) {
|
||||||
const container = page['frame'] ? page['frame'] : page;
|
const container = page['frame'] ? page['frame'] : page;
|
||||||
const originalSelector = file;
|
const originalSelector = file;
|
||||||
|
|
||||||
|
@ -857,10 +868,10 @@ export class SystemKeywords {
|
||||||
|
|
||||||
if (this.isValidHour(filter.value)) {
|
if (this.isValidHour(filter.value)) {
|
||||||
filter.dataType = fixed ? fixed : 'hourInterval';
|
filter.dataType = fixed ? fixed : 'hourInterval';
|
||||||
} else if (await this.isValidDate({pid, dt: filter.value})) {
|
} else if (await this.isValidDate({ pid, dt: filter.value })) {
|
||||||
filter.value = SystemKeywords.getDateFromLocaleString(pid, filter.value, contentLocale);
|
filter.value = SystemKeywords.getDateFromLocaleString(pid, filter.value, contentLocale);
|
||||||
filter.dataType = fixed ? fixed : 'date';
|
filter.dataType = fixed ? fixed : 'date';
|
||||||
} else if (await this.isValidNumber({pid, number: filter.value})) {
|
} else if (await this.isValidNumber({ pid, number: filter.value })) {
|
||||||
filter.value = Number.parseInt(filter.value);
|
filter.value = Number.parseInt(filter.value);
|
||||||
filter.dataType = fixed ? fixed : 'number';
|
filter.dataType = fixed ? fixed : 'number';
|
||||||
} else {
|
} else {
|
||||||
|
@ -1003,7 +1014,7 @@ export class SystemKeywords {
|
||||||
const propertyName = header[colIndex];
|
const propertyName = header[colIndex];
|
||||||
let value = xlRow[colIndex];
|
let value = xlRow[colIndex];
|
||||||
if (value && value.charAt(0) === "'") {
|
if (value && value.charAt(0) === "'") {
|
||||||
if (await this.isValidDate({pid, dt:value.substr(1)})) {
|
if (await this.isValidDate({ pid, dt: value.substr(1) })) {
|
||||||
value = value.substr(1);
|
value = value.substr(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1103,7 +1114,6 @@ export class SystemKeywords {
|
||||||
const botId = min.instance.botId;
|
const botId = min.instance.botId;
|
||||||
let path = DialogKeywords.getGBAIPath(min.botId, `gbdrive`);
|
let path = DialogKeywords.getGBAIPath(min.botId, `gbdrive`);
|
||||||
|
|
||||||
|
|
||||||
// Extracts each part of path to call create folder to each
|
// Extracts each part of path to call create folder to each
|
||||||
// one of them.
|
// one of them.
|
||||||
|
|
||||||
|
@ -1151,7 +1161,7 @@ export class SystemKeywords {
|
||||||
public async shareFolder({ pid, folder, email, message }) {
|
public async shareFolder({ pid, folder, email, message }) {
|
||||||
const { min, user, params } = await DialogKeywords.getProcessInfo(pid);
|
const { min, user, params } = await DialogKeywords.getProcessInfo(pid);
|
||||||
let { baseUrl, client } = await GBDeployer.internalGetDriveClient(min);
|
let { baseUrl, client } = await GBDeployer.internalGetDriveClient(min);
|
||||||
const path = DialogKeywords.getGBAIPath(min.botId,`gbdrive`);
|
const path = DialogKeywords.getGBAIPath(min.botId, `gbdrive`);
|
||||||
const root = urlJoin(path, folder);
|
const root = urlJoin(path, folder);
|
||||||
|
|
||||||
const src = await client.api(`${baseUrl}/drive/root:/${root}`).get();
|
const src = await client.api(`${baseUrl}/drive/root:/${root}`).get();
|
||||||
|
@ -1250,7 +1260,7 @@ export class SystemKeywords {
|
||||||
dest = dest.replace(/\\/gi, '/');
|
dest = dest.replace(/\\/gi, '/');
|
||||||
|
|
||||||
// Determines full path at source and destination.
|
// Determines full path at source and destination.
|
||||||
const path = DialogKeywords.getGBAIPath(min.botId,`gbdrive`);
|
const path = DialogKeywords.getGBAIPath(min.botId, `gbdrive`);
|
||||||
const root = path;
|
const root = path;
|
||||||
const srcPath = urlJoin(root, src);
|
const srcPath = urlJoin(root, src);
|
||||||
const dstPath = urlJoin(path, dest);
|
const dstPath = urlJoin(path, dest);
|
||||||
|
@ -1650,7 +1660,7 @@ export class SystemKeywords {
|
||||||
const propertyName = header[colIndex];
|
const propertyName = header[colIndex];
|
||||||
let value = xlRow[colIndex];
|
let value = xlRow[colIndex];
|
||||||
if (value && value.charAt(0) === "'") {
|
if (value && value.charAt(0) === "'") {
|
||||||
if (await this.isValidDate({pid, dt:value.substr(1)})) {
|
if (await this.isValidDate({ pid, dt: value.substr(1) })) {
|
||||||
value = value.substr(1);
|
value = value.substr(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1708,7 +1718,7 @@ export class SystemKeywords {
|
||||||
args.push(row[keys[j]]);
|
args.push(row[keys[j]]);
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.save({ pid,file, args });
|
await this.save({ pid, file, args });
|
||||||
adds++;
|
adds++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,9 +72,12 @@ export class WebAutomationServices {
|
||||||
|
|
||||||
return 4294967296 * (2097151 & h2) + (h1 >>> 0);
|
return 4294967296 * (2097151 & h2) + (h1 >>> 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
public async getCloseHandles({ pid }) {
|
public async closeHandles({ pid }) {
|
||||||
const { min, user } = await DialogKeywords.getProcessInfo(pid);
|
const { min, user } = await DialogKeywords.getProcessInfo(pid);
|
||||||
|
|
||||||
|
await DialogKeywords.setOption({ pid, name: "filter", value: null });
|
||||||
|
|
||||||
// Releases previous allocated OPEN semaphores.
|
// Releases previous allocated OPEN semaphores.
|
||||||
|
|
||||||
let keys = Object.keys(GBServer.globals.webSessions);
|
let keys = Object.keys(GBServer.globals.webSessions);
|
||||||
|
|
Loading…
Add table
Reference in a new issue