new(basic.gblib): #300 FIND custom SET FILTER TYPE new keyword.
This commit is contained in:
parent
5534b416da
commit
e392759d45
3 changed files with 66 additions and 55 deletions
|
@ -556,7 +556,6 @@ export class DialogKeywords {
|
||||||
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.`);
|
||||||
}
|
}
|
||||||
const process = GBServer.globals.processes[pid];
|
|
||||||
let { min, user, params } = await DialogKeywords.getProcessInfo(pid);
|
let { min, user, params } = await DialogKeywords.getProcessInfo(pid);
|
||||||
const sec = new SecService();
|
const sec = new SecService();
|
||||||
await sec.setParam(user.userId, name, value);
|
await sec.setParam(user.userId, name, value);
|
||||||
|
@ -568,7 +567,6 @@ export class DialogKeywords {
|
||||||
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.`);
|
||||||
}
|
}
|
||||||
const process = GBServer.globals.processes[pid];
|
|
||||||
let { min, user, params } = await DialogKeywords.getProcessInfo(pid);
|
let { min, user, params } = await DialogKeywords.getProcessInfo(pid);
|
||||||
const sec = new SecService();
|
const sec = new SecService();
|
||||||
return await sec.getParam(user, name);
|
return await sec.getParam(user, name);
|
||||||
|
@ -625,6 +623,17 @@ export class DialogKeywords {
|
||||||
await this.setOption({ pid, name: 'wholeWord', value: value });
|
await this.setOption({ pid, name: 'wholeWord', value: value });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines the FIND behaviour to consider whole words while searching.
|
||||||
|
*
|
||||||
|
* @example SET FILTER TYPE date, string
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public async setFilterTypes({ pid, types }) {
|
||||||
|
const value = types;
|
||||||
|
await this.setOption({ pid, name: 'filterTypes', value: value });
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines the theme for assets generation.
|
* Defines the theme for assets generation.
|
||||||
*
|
*
|
||||||
|
|
|
@ -292,7 +292,7 @@ export class KeywordsExpressions {
|
||||||
keywords[i++] = [
|
keywords[i++] = [
|
||||||
/^\s*((?:[a-z]+.?)(?:(?:\w+).)(?:\w+)*)\s*=\s*find\s*(.*)\s*or talk\s*(.*)/gim,
|
/^\s*((?:[a-z]+.?)(?:(?:\w+).)(?:\w+)*)\s*=\s*find\s*(.*)\s*or talk\s*(.*)/gim,
|
||||||
($0, $1, $2, $3) => {
|
($0, $1, $2, $3) => {
|
||||||
return `${$1} = await sys.getFind({pid: pid, args:[${$2}])\n
|
return `${$1} = await sys.find({pid: pid, args:[${$2}])\n
|
||||||
if (!${$1}) {s
|
if (!${$1}) {s
|
||||||
await dk.talk ({pid: pid, ${$3}})\n;
|
await dk.talk ({pid: pid, ${$3}})\n;
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -312,7 +312,7 @@ export class KeywordsExpressions {
|
||||||
/^\s*((?:[a-z]+.?)(?:(?:\w+).)(?:\w+)*)\s*=\s*find\s*(.*)/gim,
|
/^\s*((?:[a-z]+.?)(?:(?:\w+).)(?:\w+)*)\s*=\s*find\s*(.*)/gim,
|
||||||
($0, $1, $2, $3) => {
|
($0, $1, $2, $3) => {
|
||||||
return `
|
return `
|
||||||
${$1} = await sys.getFind({pid: pid, args: [${$2}]})`;
|
${$1} = await sys.find({pid: pid, args: [${$2}]})`;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ import { DialogKeywords } from './DialogKeywords.js';
|
||||||
import { GBServer } from '../../../src/app.js';
|
import { GBServer } from '../../../src/app.js';
|
||||||
import { GBVMService } from './GBVMService.js';
|
import { GBVMService } from './GBVMService.js';
|
||||||
import Fs from 'fs';
|
import Fs from 'fs';
|
||||||
import { GBSSR }from '../../core.gbapp/services/GBSSR.js';
|
import { GBSSR } from '../../core.gbapp/services/GBSSR.js';
|
||||||
import urlJoin from 'url-join';
|
import urlJoin from 'url-join';
|
||||||
import Excel from 'exceljs';
|
import Excel from 'exceljs';
|
||||||
import { TwitterApi } from 'twitter-api-v2';
|
import { TwitterApi } from 'twitter-api-v2';
|
||||||
|
@ -59,7 +59,6 @@ import * as MSAL from '@azure/msal-node';
|
||||||
import { GBConversationalService } from '../../core.gbapp/services/GBConversationalService.js';
|
import { GBConversationalService } from '../../core.gbapp/services/GBConversationalService.js';
|
||||||
import { WebAutomationServices } from './WebAutomationServices.js';
|
import { WebAutomationServices } from './WebAutomationServices.js';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fileoverview General Bots server core.
|
* @fileoverview General Bots server core.
|
||||||
*/
|
*/
|
||||||
|
@ -68,7 +67,6 @@ import { WebAutomationServices } from './WebAutomationServices.js';
|
||||||
* BASIC system class for extra manipulation of bot behaviour.
|
* BASIC system class for extra manipulation of bot behaviour.
|
||||||
*/
|
*/
|
||||||
export class SystemKeywords {
|
export class SystemKeywords {
|
||||||
|
|
||||||
public async callVM({ pid, text }) {
|
public async callVM({ pid, text }) {
|
||||||
const { min, user } = await DialogKeywords.getProcessInfo(pid);
|
const { min, user } = await DialogKeywords.getProcessInfo(pid);
|
||||||
const step = null;
|
const step = null;
|
||||||
|
@ -323,7 +321,7 @@ export class SystemKeywords {
|
||||||
|
|
||||||
// Checks if it is a GBFILE.
|
// Checks if it is a GBFILE.
|
||||||
|
|
||||||
if (data.data) {
|
if (data.data) {
|
||||||
const gbfile = data.data;
|
const gbfile = data.data;
|
||||||
|
|
||||||
let { baseUrl, client } = await GBDeployer.internalGetDriveClient(min);
|
let { baseUrl, client } = await GBDeployer.internalGetDriveClient(min);
|
||||||
|
@ -478,10 +476,8 @@ export class SystemKeywords {
|
||||||
// Handles calls for HTML stuff
|
// Handles calls for HTML stuff
|
||||||
|
|
||||||
if (handle) {
|
if (handle) {
|
||||||
|
|
||||||
GBLog.info(`BASIC: Web automation SET ${file}' to '${address}' . `);
|
GBLog.info(`BASIC: Web automation SET ${file}' to '${address}' . `);
|
||||||
await new WebAutomationServices()
|
await new WebAutomationServices().setElementText({ pid, handle, selector: file, text: address });
|
||||||
.setElementText({ pid, handle, selector: file, text: address });
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -693,7 +689,7 @@ export class SystemKeywords {
|
||||||
* @see NPM package data-forge
|
* @see NPM package data-forge
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public async getFind({ pid, args }): Promise<any> {
|
public async find({ pid, 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();
|
||||||
|
@ -834,7 +830,12 @@ export class SystemKeywords {
|
||||||
// Increments columnIndex by looping until find a column match.
|
// Increments columnIndex by looping until find a column match.
|
||||||
|
|
||||||
const filters = [];
|
const filters = [];
|
||||||
|
let predefinedFilterTypes;
|
||||||
|
if (params.filterTypes) {
|
||||||
|
predefinedFilterTypes = params.filterTypes.split(',');
|
||||||
|
}
|
||||||
|
|
||||||
|
let filterIndex = 0;
|
||||||
await CollectionUtil.asyncForEach(args, async arg => {
|
await CollectionUtil.asyncForEach(args, async arg => {
|
||||||
const filter = await getFilter(arg);
|
const filter = await getFilter(arg);
|
||||||
if (!filter) {
|
if (!filter) {
|
||||||
|
@ -848,20 +849,22 @@ export class SystemKeywords {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
filter.columnIndex = columnIndex;
|
filter.columnIndex = columnIndex;
|
||||||
|
const fixed = predefinedFilterTypes ? predefinedFilterTypes[filterIndex] : null;
|
||||||
|
|
||||||
if (this.isValidHour(filter.value)) {
|
if (this.isValidHour(filter.value)) {
|
||||||
filter.dataType = 'hourInterval';
|
filter.dataType = fixed ? fixed : 'hourInterval';
|
||||||
} else if (this.isValidDate(filter.value)) {
|
} else if (this.isValidDate(filter.value)) {
|
||||||
filter.value = SystemKeywords.getDateFromLocaleString(pid, filter.value, contentLocale);
|
filter.value = SystemKeywords.getDateFromLocaleString(pid, filter.value, contentLocale);
|
||||||
filter.dataType = 'date';
|
filter.dataType = fixed ? fixed : 'date';
|
||||||
} else if (this.isValidNumber(filter.value)) {
|
} else if (this.isValidNumber(filter.value)) {
|
||||||
filter.value = Number.parseInt(filter.value);
|
filter.value = Number.parseInt(filter.value);
|
||||||
filter.dataType = 'number';
|
filter.dataType = fixed ? fixed : 'number';
|
||||||
} else {
|
} else {
|
||||||
filter.value = filter.value;
|
filter.value = filter.value;
|
||||||
filter.dataType = 'string';
|
filter.dataType = fixed ? fixed : 'string';
|
||||||
}
|
}
|
||||||
filters.push(filter);
|
filters.push(filter);
|
||||||
|
filterIndex++;
|
||||||
});
|
});
|
||||||
|
|
||||||
// As BASIC uses arrays starting with 1 (one) as index,
|
// As BASIC uses arrays starting with 1 (one) as index,
|
||||||
|
@ -885,7 +888,6 @@ export class SystemKeywords {
|
||||||
|
|
||||||
switch (filter.dataType) {
|
switch (filter.dataType) {
|
||||||
case 'string':
|
case 'string':
|
||||||
|
|
||||||
const v1 = GBConversationalService.removeDiacritics(result.toLowerCase().trim());
|
const v1 = GBConversationalService.removeDiacritics(result.toLowerCase().trim());
|
||||||
const v2 = GBConversationalService.removeDiacritics(filter.toLowerCase().trim());
|
const v2 = GBConversationalService.removeDiacritics(filter.toLowerCase().trim());
|
||||||
|
|
||||||
|
@ -1373,9 +1375,8 @@ export class SystemKeywords {
|
||||||
return text.replace(/\D/gi, '');
|
return text.replace(/\D/gi, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//Create a CREAT LEAD keyword
|
//Create a CREAT LEAD keyword
|
||||||
public async createLead({ pid, templateName, data }) {
|
public async createLead({ pid, templateName, data }) {
|
||||||
//OAuth Token Endpoint (from your Azure App Registration)
|
//OAuth Token Endpoint (from your Azure App Registration)
|
||||||
const authorityUrl = 'https://login.microsoftonline.com/<COPY A GUID HERE>';
|
const authorityUrl = 'https://login.microsoftonline.com/<COPY A GUID HERE>';
|
||||||
const msalConfig = {
|
const msalConfig = {
|
||||||
|
@ -1384,43 +1385,49 @@ export class SystemKeywords {
|
||||||
clientId: process.env.DYNAMICS_CLIENTID,
|
clientId: process.env.DYNAMICS_CLIENTID,
|
||||||
clientSecret: process.env.DYNAMICS_CLIENTSECRET,
|
clientSecret: process.env.DYNAMICS_CLIENTSECRET,
|
||||||
knownAuthorities: ['login.microsoftonline.com']
|
knownAuthorities: ['login.microsoftonline.com']
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
const cca = new MSAL.ConfidentialClientApplication(msalConfig);
|
const cca = new MSAL.ConfidentialClientApplication(msalConfig);
|
||||||
const serverUrl = ` `;
|
const serverUrl = ` `;
|
||||||
|
|
||||||
//function that acquires a token and passes it to DynamicsWebApi
|
//function that acquires a token and passes it to DynamicsWebApi
|
||||||
const acquireToken = (dynamicsWebApiCallback) => {
|
const acquireToken = dynamicsWebApiCallback => {
|
||||||
cca.acquireTokenByClientCredential({
|
cca
|
||||||
scopes: [`${serverUrl}/.default`],
|
.acquireTokenByClientCredential({
|
||||||
}).then(response => {
|
scopes: [`${serverUrl}/.default`]
|
||||||
|
})
|
||||||
|
.then(response => {
|
||||||
//call DynamicsWebApi callback only when a token has been retrieved successfully
|
//call DynamicsWebApi callback only when a token has been retrieved successfully
|
||||||
dynamicsWebApiCallback(response.accessToken);
|
dynamicsWebApiCallback(response.accessToken);
|
||||||
}).catch((error) => {
|
})
|
||||||
|
.catch(error => {
|
||||||
console.log(JSON.stringify(error));
|
console.log(JSON.stringify(error));
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
//create DynamicsWebApi
|
//create DynamicsWebApi
|
||||||
const dynamicsWebApi = new DynamicsWebApi({
|
const dynamicsWebApi = new DynamicsWebApi({
|
||||||
webApiUrl: `${serverUrl}/api/data/v9.2/`,
|
webApiUrl: `${serverUrl}/api/data/v9.2/`,
|
||||||
onTokenRefresh: acquireToken
|
onTokenRefresh: acquireToken
|
||||||
});
|
});
|
||||||
//initialize a CRM entity record object
|
//initialize a CRM entity record object
|
||||||
var lead = {
|
var lead = {
|
||||||
subject: "Test WebAPI",
|
subject: 'Test WebAPI',
|
||||||
firstname: "Test",
|
firstname: 'Test',
|
||||||
lastname: "WebAPI",
|
lastname: 'WebAPI',
|
||||||
jobtitle: "Title"
|
jobtitle: 'Title'
|
||||||
};
|
};
|
||||||
//call dynamicsWebApi.create function
|
//call dynamicsWebApi.create function
|
||||||
dynamicsWebApi.create(lead, "leads").then(function (id) {
|
dynamicsWebApi
|
||||||
//do something with id here
|
.create(lead, 'leads')
|
||||||
}).catch(function (error) {
|
.then(function (id) {
|
||||||
//catch error here
|
//do something with id here
|
||||||
})
|
})
|
||||||
}
|
.catch(function (error) {
|
||||||
|
//catch error here
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Fills a .docx or .pptx with template data.
|
* Fills a .docx or .pptx with template data.
|
||||||
|
@ -1460,14 +1467,13 @@ export class SystemKeywords {
|
||||||
for (var i in o) {
|
for (var i in o) {
|
||||||
let value = o[i];
|
let value = o[i];
|
||||||
|
|
||||||
if (value && value.gbarray){
|
if (value && value.gbarray) {
|
||||||
o.shift();
|
o.shift();
|
||||||
value = o[i];
|
value = o[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const kind of ['png', 'jpg', 'jpeg']) {
|
for (const kind of ['png', 'jpg', 'jpeg']) {
|
||||||
if (value.endsWith && value.endsWith(`.${kind}`)) {
|
if (value.endsWith && value.endsWith(`.${kind}`)) {
|
||||||
|
|
||||||
const { baseUrl, client } = await GBDeployer.internalGetDriveClient(min);
|
const { baseUrl, client } = await GBDeployer.internalGetDriveClient(min);
|
||||||
|
|
||||||
path = urlJoin(gbaiName, `${botId}.gbdrive`);
|
path = urlJoin(gbaiName, `${botId}.gbdrive`);
|
||||||
|
@ -1475,7 +1481,7 @@ export class SystemKeywords {
|
||||||
path = '/' + urlJoin(path, Path.dirname(value));
|
path = '/' + urlJoin(path, Path.dirname(value));
|
||||||
value = Path.basename(value);
|
value = Path.basename(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
const ref = await this.internalGetDocument(client, baseUrl, path, value);
|
const ref = await this.internalGetDocument(client, baseUrl, path, value);
|
||||||
let url = ref['@microsoft.graph.downloadUrl'];
|
let url = ref['@microsoft.graph.downloadUrl'];
|
||||||
const imageName = Path.join(
|
const imageName = Path.join(
|
||||||
|
@ -1487,15 +1493,14 @@ export class SystemKeywords {
|
||||||
const response = await fetch(url);
|
const response = await fetch(url);
|
||||||
const buf = Buffer.from(await response.arrayBuffer());
|
const buf = Buffer.from(await response.arrayBuffer());
|
||||||
Fs.writeFileSync(imageName, buf, { encoding: null });
|
Fs.writeFileSync(imageName, buf, { encoding: null });
|
||||||
|
|
||||||
const getNormalSize = ({ width, height, orientation }) => {
|
const getNormalSize = ({ width, height, orientation }) => {
|
||||||
return (orientation || 0) >= 5 ? [ height, width ] : [ width, height];
|
return (orientation || 0) >= 5 ? [height, width] : [width, height];
|
||||||
};
|
};
|
||||||
|
|
||||||
const size = getNormalSize(await sharp(buf).metadata());
|
const size = getNormalSize(await sharp(buf).metadata());
|
||||||
url = urlJoin(GBServer.globals.publicAddress, min.botId, 'cache', Path.basename(imageName));
|
url = urlJoin(GBServer.globals.publicAddress, min.botId, 'cache', Path.basename(imageName));
|
||||||
images[index++] = {url: url, size:size, buf: buf} ;
|
images[index++] = { url: url, size: size, buf: buf };
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (o[i] !== null && typeof o[i] == 'object') {
|
if (o[i] !== null && typeof o[i] == 'object') {
|
||||||
|
@ -1510,7 +1515,6 @@ export class SystemKeywords {
|
||||||
centered: false,
|
centered: false,
|
||||||
getImage: (tagValue, tagName) => {
|
getImage: (tagValue, tagName) => {
|
||||||
return images[indexImage].buf;
|
return images[indexImage].buf;
|
||||||
|
|
||||||
},
|
},
|
||||||
getSize: (img, tagValue, tagName) => {
|
getSize: (img, tagValue, tagName) => {
|
||||||
return images[indexImage++].size;
|
return images[indexImage++].size;
|
||||||
|
@ -1526,10 +1530,8 @@ export class SystemKeywords {
|
||||||
doc.attachModule(new ImageModule(opts));
|
doc.attachModule(new ImageModule(opts));
|
||||||
|
|
||||||
await traverseDataToInjectImageUrl(data);
|
await traverseDataToInjectImageUrl(data);
|
||||||
doc
|
doc.setData(data).render();
|
||||||
.setData(data)
|
|
||||||
.render();
|
|
||||||
|
|
||||||
buf = doc.getZip().generate({ type: 'nodebuffer', compression: 'DEFLATE' });
|
buf = doc.getZip().generate({ type: 'nodebuffer', compression: 'DEFLATE' });
|
||||||
Fs.writeFileSync(localName, buf, { encoding: null });
|
Fs.writeFileSync(localName, buf, { encoding: null });
|
||||||
|
|
||||||
|
@ -1689,7 +1691,7 @@ export class SystemKeywords {
|
||||||
const address = `${cell}:${cell}`;
|
const address = `${cell}:${cell}`;
|
||||||
|
|
||||||
if (value !== found[columnName]) {
|
if (value !== found[columnName]) {
|
||||||
await this.set({ pid, handle:null, file, address, value });
|
await this.set({ pid, handle: null, file, address, value });
|
||||||
merges++;
|
merges++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue