feat(systemkeywords.ts): introducing executionid feature in api

This commit is contained in:
Alan Perdomo 2023-01-10 12:06:14 -03:00
parent cfee19edda
commit a65a82dd8a
7 changed files with 91 additions and 85 deletions

View file

@ -101,7 +101,7 @@ export class GBAdminService implements IGBAdminService {
return password; return password;
} }
public static getRndReadableIdentifier() { public static getRndReadableIdentifier(): string {
return lowercase_PW(14); return lowercase_PW(14);
} }

View file

@ -1028,7 +1028,10 @@ export class DialogKeywords {
} }
public async getSingleton({}) { public async getSingleton({}) {
const executionId = this.sys().getRandomId();
GBServer.globals.executions[executionId]={};
return { return {
executionId: executionId,
id: this.sys().getRandomId(), id: this.sys().getRandomId(),
username: this.userName(), username: this.userName(),
mobile: this.userMobile(), mobile: this.userMobile(),

View file

@ -237,6 +237,7 @@ export class GBVMService extends GBService {
// Local variables. // Local variables.
const gb = await dk.getSingleton(); const gb = await dk.getSingleton();
const executionId = gb.executionId;
const id = gb.id; const id = gb.id;
const username = gb.username; const username = gb.username;
const mobile = gb.mobile; const mobile = gb.mobile;
@ -387,7 +388,7 @@ export class GBVMService extends GBService {
($0, $1, $2) => { ($0, $1, $2) => {
let tableName = /\s*FROM\s*(\w+)/.exec($2)[1]; let tableName = /\s*FROM\s*(\w+)/.exec($2)[1];
let sql = `SELECT ${$2}`.replace(tableName, '?'); let sql = `SELECT ${$2}`.replace(tableName, '?');
return `${$1} = await sys.executeSQL({data:${$1}, sql:"${sql}", tableName:"${tableName}"})\n`; return `${$1} = await sys.executeSQL({executionId:executionId, data:${$1}, sql:"${sql}", tableName:"${tableName}"})\n`;
} }
]; ];
@ -397,9 +398,9 @@ export class GBVMService extends GBService {
if (!$1.startsWith('"') && !$1.startsWith("'")) { if (!$1.startsWith('"') && !$1.startsWith("'")) {
$1 = `"${$1}"`; $1 = `"${$1}"`;
} }
const params = this.getParams($1, ['url', 'username', 'password']); const params = this.getParams($1, ['executionId', 'url', 'username', 'password']);
return `page = await wa.getPage(${params})\n`; return `page = await wa.getPage({executionId:executionId,${params}})\n`;
} }
]; ];
@ -413,114 +414,114 @@ export class GBVMService extends GBService {
keywords[i++] = [ keywords[i++] = [
/^\s*hear (\w+) as login/gim, /^\s*hear (\w+) as login/gim,
($0, $1) => { ($0, $1) => {
return `${$1} = await dk.getHear({kind:"login"})`; return `${$1} = await dk.getHear({executionId:executionId, kind:"login"})`;
} }
]; ];
keywords[i++] = [ keywords[i++] = [
/^\s*hear (\w+) as email/gim, /^\s*hear (\w+) as email/gim,
($0, $1) => { ($0, $1) => {
return `${$1} = await dk.getHear({kind:"email"})`; return `${$1} = await dk.getHear({executionId:executionId, kind:"email"})`;
} }
]; ];
keywords[i++] = [ keywords[i++] = [
/^\s*hear (\w+) as integer/gim, /^\s*hear (\w+) as integer/gim,
($0, $1) => { ($0, $1) => {
return `${$1} = await dk.getHear({kind:"integer"})`; return `${$1} = await dk.getHear({executionId:executionId, kind:"integer"})`;
} }
]; ];
keywords[i++] = [ keywords[i++] = [
/^\s*hear (\w+) as file/gim, /^\s*hear (\w+) as file/gim,
($0, $1) => { ($0, $1) => {
return `${$1} = await dk.getHear({kind:"file"})`; return `${$1} = await dk.getHear({executionId:executionId, kind:"file"})`;
} }
]; ];
keywords[i++] = [ keywords[i++] = [
/^\s*hear (\w+) as boolean/gim, /^\s*hear (\w+) as boolean/gim,
($0, $1) => { ($0, $1) => {
return `${$1} = await dk.getHear({kind:"boolean"})`; return `${$1} = await dk.getHear({executionId:executionId, kind:"boolean"})`;
} }
]; ];
keywords[i++] = [ keywords[i++] = [
/^\s*hear (\w+) as name/gim, /^\s*hear (\w+) as name/gim,
($0, $1) => { ($0, $1) => {
return `${$1} = await dk.getHear({kind:"name"})`; return `${$1} = await dk.getHear({executionId:executionId, kind:"name"})`;
} }
]; ];
keywords[i++] = [ keywords[i++] = [
/^\s*hear (\w+) as date/gim, /^\s*hear (\w+) as date/gim,
($0, $1) => { ($0, $1) => {
return `${$1} = await dk.getHear({kind:"date"})`; return `${$1} = await dk.getHear({executionId:executionId, kind:"date"})`;
} }
]; ];
keywords[i++] = [ keywords[i++] = [
/^\s*hear (\w+) as hour/gim, /^\s*hear (\w+) as hour/gim,
($0, $1) => { ($0, $1) => {
return `${$1} = await dk.getHear({kind:"hour"})`; return `${$1} = await dk.getHear({executionId:executionId, kind:"hour"})`;
} }
]; ];
keywords[i++] = [ keywords[i++] = [
/^\s*hear (\w+) as phone/gim, /^\s*hear (\w+) as phone/gim,
($0, $1) => { ($0, $1) => {
return `${$1} = await dk.getHear({kind:"phone"})`; return `${$1} = await dk.getHear({executionId:executionId, kind:"phone"})`;
} }
]; ];
keywords[i++] = [ keywords[i++] = [
/^\s*hear (\w+) as money/gim, /^\s*hear (\w+) as money/gim,
($0, $1) => { ($0, $1) => {
return `${$1} = await dk.getHear({kind:"money")}`; return `${$1} = await dk.getHear({executionId:executionId, kind:"money")}`;
} }
]; ];
keywords[i++] = [ keywords[i++] = [
/^\s*hear (\w+) as language/gim, /^\s*hear (\w+) as language/gim,
($0, $1) => { ($0, $1) => {
return `${$1} = await dk.getHear({kind:"language")}`; return `${$1} = await dk.getHear({executionId:executionId, kind:"language")}`;
} }
]; ];
keywords[i++] = [ keywords[i++] = [
/^\s*hear (\w+) as zipcode/gim, /^\s*hear (\w+) as zipcode/gim,
($0, $1) => { ($0, $1) => {
return `${$1} = await dk.getHear({kind:"zipcode")}`; return `${$1} = await dk.getHear({executionId:executionId, kind:"zipcode")}`;
} }
]; ];
keywords[i++] = [ keywords[i++] = [
/^\s*hear (\w+) as (.*)/gim, /^\s*hear (\w+) as (.*)/gim,
($0, $1, $2) => { ($0, $1, $2) => {
return `${$1} = await dk.getHear({kind:"menu", args: [${$2}])}`; return `${$1} = await dk.getHear({executionId:executionId, kind:"menu", args: [${$2}])}`;
} }
]; ];
keywords[i++] = [ keywords[i++] = [
/^\s*(hear)\s*(\w+)/gim, /^\s*(hear)\s*(\w+)/gim,
($0, $1, $2) => { ($0, $1, $2) => {
return `${$2} = await dk.getHear({})`; return `${$2} = await dk.getHear({executionId:executionId})`;
} }
]; ];
keywords[i++] = [ keywords[i++] = [
/^\s*(\w+)\s*\=\s*find contact\s*(.*)/gim, /^\s*(\w+)\s*\=\s*find contact\s*(.*)/gim,
($0, $1, $2, $3) => { ($0, $1, $2, $3) => {
return `${$1} = await dk.fndContact({${$2})\n`; return `${$1} = await dk.fndContact({executionId:executionId, ${$2}})\n`;
} }
]; ];
keywords[i++] = [ keywords[i++] = [
/^\s*(\w+)\s*=\s*find\s*(.*)\s*or talk\s*(.*)/gim, /^\s*(\w+)\s*=\s*find\s*(.*)\s*or talk\s*(.*)/gim,
($0, $1, $2, $3) => { ($0, $1, $2, $3) => {
return `${$1} = await sys.find({args:[${$2}])\n return `${$1} = await sys.find({executionId:executionId, args:[${$2}])\n
if (!${$1}) { if (!${$1}) {
await dk.talk ({${$3}})\n; await dk.talk ({executionId:executionId, ${$3}})\n;
return -1; return -1;
} }
`; `;
@ -538,7 +539,7 @@ export class GBVMService extends GBService {
/^\s*(\w+)\s*\=\s*find\s*(.*)/gim, /^\s*(\w+)\s*\=\s*find\s*(.*)/gim,
($0, $1, $2, $3) => { ($0, $1, $2, $3) => {
return ` return `
${$1} = await sys.find({args: [${$2}]})\n`; ${$1} = await sys.find({executionId:executionId, args: [${$2}]})\n`;
} }
]; ];
@ -547,56 +548,56 @@ export class GBVMService extends GBService {
($0, $1, $2, $3) => { ($0, $1, $2, $3) => {
const params = this.getParams($3, ['dealName', 'contact', 'company', 'amount']); const params = this.getParams($3, ['dealName', 'contact', 'company', 'amount']);
return `${$1} = await dk.createDeal(${params})\n`; return `${$1} = await dk.createDeal({executionId:executionId, ${params}})\n`;
} }
]; ];
keywords[i++] = [ keywords[i++] = [
/^\s*(\w+)\s*\=\s*active tasks/gim, /^\s*(\w+)\s*\=\s*active tasks/gim,
($0, $1) => { ($0, $1) => {
return `${$1} = await dk.getActiveTasks({})\n`; return `${$1} = await dk.getActiveTasks({executionId:executionId})\n`;
} }
]; ];
keywords[i++] = [ keywords[i++] = [
/^\s*(\w+)\s*\=\s*append\s*(.*)/gim, /^\s*(\w+)\s*\=\s*append\s*(.*)/gim,
($0, $1, $2, $3) => { ($0, $1, $2, $3) => {
return `${$1} = await sys.append({args:[${$2}]})\n`; return `${$1} = await sys.append({executionId:executionId, args:[${$2}]})\n`;
} }
]; ];
keywords[i++] = [ keywords[i++] = [
/^\s*(\w+)\s*\=\s*sort\s*(\w+)\s*by(.*)/gim, /^\s*(\w+)\s*\=\s*sort\s*(\w+)\s*by(.*)/gim,
($0, $1, $2, $3) => { ($0, $1, $2, $3) => {
return `${$1} = await sys.sortBy({array: ${$2}, memberName: "${$3}"})\n`; return `${$1} = await sys.sortBy({executionId:executionId, array: ${$2}, memberName: "${$3}"})\n`;
} }
]; ];
keywords[i++] = [ keywords[i++] = [
/^\s*see\s*text\s*of\s*(\w+)\s*as\s*(\w+)\s*/gim, /^\s*see\s*text\s*of\s*(\w+)\s*as\s*(\w+)\s*/gim,
($0, $1, $2, $3) => { ($0, $1, $2, $3) => {
return `${$2} = await sys.seeText({url: ${$1})\n`; return `${$2} = await sys.seeText({executionId:executionId, url: ${$1})\n`;
} }
]; ];
keywords[i++] = [ keywords[i++] = [
/^\s*see\s*caption\s*of\s*(\w+)\s*as(.*)/gim, /^\s*see\s*caption\s*of\s*(\w+)\s*as(.*)/gim,
($0, $1, $2, $3) => { ($0, $1, $2, $3) => {
return `${$2} = await sys.seeCaption({url: ${$1})\n`; return `${$2} = await sys.seeCaption({executionId:executionId, url: ${$1})\n`;
} }
]; ];
keywords[i++] = [ keywords[i++] = [
/^\s*(wait)\s*(\d+)/gim, /^\s*(wait)\s*(\d+)/gim,
($0, $1, $2) => { ($0, $1, $2) => {
return `await sys.wait({seconds:${$2}})`; return `await sys.wait({executionId:executionId, seconds:${$2}})`;
} }
]; ];
keywords[i++] = [ keywords[i++] = [
/^\s*(get stock for )(.*)/gim, /^\s*(get stock for )(.*)/gim,
($0, $1, $2) => { ($0, $1, $2) => {
return `stock = await sys.getStock({symbol: ${$2})`; return `stock = await sys.getStock({executionId:executionId, symbol: ${$2})`;
} }
]; ];
@ -609,19 +610,19 @@ export class GBVMService extends GBService {
// Handles GET "selector". // Handles GET "selector".
if (count == 1) { if (count == 1) {
return `${$1} = await wa.getBySelector({handle:page, selector: ${values[0]}})`; return `${$1} = await wa.getBySelector({executionId:executionId, handle:page, selector: ${values[0]}})`;
} }
// Handles GET "frameSelector", "selector" // Handles GET "frameSelector", "selector"
else if (count == 2) { else if (count == 2) {
return `${$1} = await wa.getByFrame({handle: page, ${values[0]}, frameOrSelector: ${values[1]}, selector: ${ return `${$1} = await wa.getByFrame({executionId:executionId, handle: page, ${values[0]}, frameOrSelector: ${values[1]}, selector: ${
values[2] values[2]
}})`; }})`;
} }
// Handles the GET http version. // Handles the GET http version.
else { else {
return `${$1} = await sys.get ({file: ${$2}, addressOrHeaders: headers, httpUsername, httpPs})`; return `${$1} = await sys.get ({executionId:executionId, file: ${$2}, addressOrHeaders: headers, httpUsername, httpPs})`;
} }
} }
]; ];
@ -629,7 +630,7 @@ export class GBVMService extends GBService {
keywords[i++] = [ keywords[i++] = [
/\= NEW OBJECT/gi, /\= NEW OBJECT/gi,
($0, $1, $2, $3) => { ($0, $1, $2, $3) => {
return ` = {}`; return ` = {executionId:executionId}`;
} }
]; ];
@ -644,14 +645,14 @@ export class GBVMService extends GBService {
/^\s*(go to)(\s*)(.*)/gim, /^\s*(go to)(\s*)(.*)/gim,
($0, $1, $2, $3) => { ($0, $1, $2, $3) => {
const params = this.getParams($3, ['fromOrDialogName', 'dialogName']); const params = this.getParams($3, ['fromOrDialogName', 'dialogName']);
return `await dk.gotoDialog(${params})\n`; return `await dk.gotoDialog({executionId:executionId, ${params}})\n`;
} }
]; ];
keywords[i++] = [ keywords[i++] = [
/^\s*(set language)(\s*)(.*)/gim, /^\s*(set language)(\s*)(.*)/gim,
($0, $1, $2, $3) => { ($0, $1, $2, $3) => {
return `await dk.setLanguage ({${$3}})\n`; return `await dk.setLanguage ({executionId:executionId, ${$3}})\n`;
} }
]; ];
@ -680,7 +681,7 @@ export class GBVMService extends GBService {
/^\s*(datediff)(\s*)(.*)/gim, /^\s*(datediff)(\s*)(.*)/gim,
($0, $1, $2, $3) => { ($0, $1, $2, $3) => {
const params = this.getParams($3, ['date1', 'date2', 'mode']); const params = this.getParams($3, ['date1', 'date2', 'mode']);
return `await dk.dateDiff (${params}})\n`; return `await dk.dateDiff (executionId:executionId, ${params}})\n`;
} }
]; ];
@ -688,98 +689,98 @@ export class GBVMService extends GBService {
/^\s*(dateadd)(\s*)(.*)/gim, /^\s*(dateadd)(\s*)(.*)/gim,
($0, $1, $2, $3) => { ($0, $1, $2, $3) => {
const params = this.getParams($3, ['date', 'mode', 'units']); const params = this.getParams($3, ['date', 'mode', 'units']);
return `await dk.dateAdd (${$3})\n`; return `await dk.dateAdd (executionId:executionId, ${$3})\n`;
} }
]; ];
keywords[i++] = [ keywords[i++] = [
/^\s*(set max lines)(\s*)(.*)/gim, /^\s*(set max lines)(\s*)(.*)/gim,
($0, $1, $2, $3) => { ($0, $1, $2, $3) => {
return `await dk.setMaxLines ({count: ${$3}})\n`; return `await dk.setMaxLines ({executionId:executionId, count: ${$3}})\n`;
} }
]; ];
keywords[i++] = [ keywords[i++] = [
/^\s*(set max columns)(\s*)(.*)/gim, /^\s*(set max columns)(\s*)(.*)/gim,
($0, $1, $2, $3) => { ($0, $1, $2, $3) => {
return `await dk.setMaxColumns ({count: ${$3}})\n`; return `await dk.setMaxColumns ({executionId:executionId, count: ${$3}})\n`;
} }
]; ];
keywords[i++] = [ keywords[i++] = [
/^\s*(set translator)(\s*)(.*)/gim, /^\s*(set translator)(\s*)(.*)/gim,
($0, $1, $2, $3) => { ($0, $1, $2, $3) => {
return `await dk.setTranslatorOn ({on: "${$3.toLowerCase()}"})\n`; return `await dk.setTranslatorOn ({executionId:executionId, on: "${$3.toLowerCase()}"})\n`;
} }
]; ];
keywords[i++] = [ keywords[i++] = [
/^\s*(set theme)(\s*)(.*)/gim, /^\s*(set theme)(\s*)(.*)/gim,
($0, $1, $2, $3) => { ($0, $1, $2, $3) => {
return `await dk.setTheme ({theme: "${$3.toLowerCase()}"})\n`; return `await dk.setTheme ({executionId:executionId, theme: "${$3.toLowerCase()}"})\n`;
} }
]; ];
keywords[i++] = [ keywords[i++] = [
/^\s*(set whole word)(\s*)(.*)/gim, /^\s*(set whole word)(\s*)(.*)/gim,
($0, $1, $2, $3) => { ($0, $1, $2, $3) => {
return `await dk.setWholeWord ({on: "${$3.toLowerCase()}"})\n`; return `await dk.setWholeWord ({executionId:executionId, on: "${$3.toLowerCase()}"})\n`;
} }
]; ];
keywords[i++] = [ keywords[i++] = [
/^\s*(\w+)\s*\=\s*post\s*(.*),\s*(.*)/gim, /^\s*(\w+)\s*\=\s*post\s*(.*),\s*(.*)/gim,
($0, $1, $2, $3) => { ($0, $1, $2, $3) => {
return `${$1} = await sys.postByHttp ({url:${$2}, data:${$3}, headers})`; return `${$1} = await sys.postByHttp ({executionId:executionId, url:${$2}, data:${$3}, headers})`;
} }
]; ];
keywords[i++] = [ keywords[i++] = [
/^\s*(\w+)\s*\=\s*put\s*(.*),\s*(.*)/gim, /^\s*(\w+)\s*\=\s*put\s*(.*),\s*(.*)/gim,
($0, $1, $2, $3) => { ($0, $1, $2, $3) => {
return `${$1} = await sys.putByHttp ({url:${$2}, data:${$3}, headers})`; return `${$1} = await sys.putByHttp ({executionId:executionId, url:${$2}, data:${$3}, headers})`;
} }
]; ];
keywords[i++] = [ keywords[i++] = [
/^\s*(\w+)\s*\=\s*download\s*(.*),\s*(.*)/gim, /^\s*(\w+)\s*\=\s*download\s*(.*),\s*(.*)/gim,
($0, $1, $2, $3) => { ($0, $1, $2, $3) => {
return `${$1} = await sys.download ({handle:page, selector: ${$2}, folder:${$3}})`; return `${$1} = await sys.download ({executionId:executionId, handle:page, selector: ${$2}, folder:${$3}})`;
} }
]; ];
keywords[i++] = [ keywords[i++] = [
/^\s*(\w+)\s*\=\s*CREATE FOLDER\s*(.*)/gim, /^\s*(\w+)\s*\=\s*CREATE FOLDER\s*(.*)/gim,
($0, $1, $2) => { ($0, $1, $2) => {
return `${$1} = await sys.createFolder ({name:${$2}})`; return `${$1} = await sys.createFolder ({executionId:executionId, name:${$2}})`;
} }
]; ];
keywords[i++] = [ keywords[i++] = [
/^\s*SHARE FOLDER\s*(.*)/gim, /^\s*SHARE FOLDER\s*(.*)/gim,
($0, $1) => { ($0, $1) => {
return `await sys.shareFolder ({name: ${$1}})`; return `await sys.shareFolder ({executionId:executionId, name: ${$1}})`;
} }
]; ];
keywords[i++] = [ keywords[i++] = [
/^\s*(create a bot farm using)(\s*)(.*)/gim, /^\s*(create a bot farm using)(\s*)(.*)/gim,
($0, $1, $2, $3) => { ($0, $1, $2, $3) => {
return `await sys.createABotFarmUsing ({${$3}})`; return `await sys.createABotFarmUsing ({executionId:executionId, ${$3}})`;
} }
]; ];
keywords[i++] = [ keywords[i++] = [
/^\s*(transfer to)(\s*)(.*)/gim, /^\s*(transfer to)(\s*)(.*)/gim,
($0, $1, $2, $3) => { ($0, $1, $2, $3) => {
return `await dk.transferTo ({to:${$3}})\n`; return `await dk.transferTo ({executionId:executionId, to:${$3}})\n`;
} }
]; ];
keywords[i++] = [ keywords[i++] = [
/^\s*(\btransfer\b)(?=(?:[^"]|"[^"]*")*$)/gim, /^\s*(\btransfer\b)(?=(?:[^"]|"[^"]*")*$)/gim,
() => { () => {
return `await dk.transferTo ({})\n`; return `await dk.transferTo ({executionId:executionId, })\n`;
} }
]; ];
@ -793,7 +794,7 @@ export class GBVMService extends GBService {
keywords[i++] = [ keywords[i++] = [
/^\s*(show menu)/gim, /^\s*(show menu)/gim,
() => { () => {
return `await dk.showMenu ({})\n`; return `await dk.showMenu ({executionId:executionId, })\n`;
} }
]; ];
@ -801,7 +802,7 @@ export class GBVMService extends GBService {
/^\s*(talk to)(\s*)(.*)/gim, /^\s*(talk to)(\s*)(.*)/gim,
($0, $1, $2, $3) => { ($0, $1, $2, $3) => {
const params = this.getParams($3, ['mobile', 'message']); const params = this.getParams($3, ['mobile', 'message']);
return `await sys.talkTo(${params})\n`; return `await sys.talkTo({executionId:executionId, ${params}})\n`;
} }
]; ];
@ -811,7 +812,7 @@ export class GBVMService extends GBService {
if ($3.substr(0, 1) !== '"') { if ($3.substr(0, 1) !== '"') {
$3 = `"${$3}"`; $3 = `"${$3}"`;
} }
return `await dk.talk ({text: ${$3}})\n`; return `await dk.talk ({executionId:executionId, text: ${$3}})\n`;
} }
]; ];
@ -819,7 +820,7 @@ export class GBVMService extends GBService {
/^\s*(send sms to)(\s*)(.*)/gim, /^\s*(send sms to)(\s*)(.*)/gim,
($0, $1, $2, $3) => { ($0, $1, $2, $3) => {
const params = this.getParams($3, ['mobile', 'message']); const params = this.getParams($3, ['mobile', 'message']);
return `await sys.sendSmsTo(${params})\n`; return `await sys.sendSmsTo({executionId:executionId, ${params}})\n`;
} }
]; ];
@ -827,7 +828,7 @@ export class GBVMService extends GBService {
/^\s*(send email)(\s*)(.*)/gim, /^\s*(send email)(\s*)(.*)/gim,
($0, $1, $2, $3) => { ($0, $1, $2, $3) => {
const params = this.getParams($3, ['to', 'subject', 'body']); const params = this.getParams($3, ['to', 'subject', 'body']);
return `await dk.sendEmail(${params})\n`; return `await dk.sendEmail({executionId:executionId, ${params}})\n`;
} }
]; ];
@ -835,7 +836,7 @@ export class GBVMService extends GBService {
/^\s*(send mail)(\s*)(.*)/gim, /^\s*(send mail)(\s*)(.*)/gim,
($0, $1, $2, $3) => { ($0, $1, $2, $3) => {
const params = this.getParams($3, ['to', 'subject', 'body']); const params = this.getParams($3, ['to', 'subject', 'body']);
return `await dk.sendEmail(${params})\n`; return `await dk.sendEmail({executionId:executionId, ${params}})\n`;
} }
]; ];
@ -843,7 +844,7 @@ export class GBVMService extends GBService {
/^\s*(send file to)(\s*)(.*)/gim, /^\s*(send file to)(\s*)(.*)/gim,
($0, $1, $2, $3) => { ($0, $1, $2, $3) => {
const params = this.getParams($3, ['mobile', 'filename', 'caption']); const params = this.getParams($3, ['mobile', 'filename', 'caption']);
return `await dk.sendFileTo(${params})\n`; return `await dk.sendFileTo({executionId:executionId, ${params}})\n`;
} }
]; ];
@ -851,7 +852,7 @@ export class GBVMService extends GBService {
/^\s*(hover)(\s*)(.*)/gim, /^\s*(hover)(\s*)(.*)/gim,
($0, $1, $2, $3) => { ($0, $1, $2, $3) => {
const params = this.getParams($3, ['handle', 'selector']); const params = this.getParams($3, ['handle', 'selector']);
return `await wa.hover (${params})\n`; return `await wa.hover ({executionId:executionId, ${params}})\n`;
} }
]; ];
@ -859,7 +860,7 @@ export class GBVMService extends GBService {
/^\s*(click link text)(\s*)(.*)/gim, /^\s*(click link text)(\s*)(.*)/gim,
($0, $1, $2, $3) => { ($0, $1, $2, $3) => {
const params = this.getParams('page,' + $3, ['handle', 'text', 'index']); const params = this.getParams('page,' + $3, ['handle', 'text', 'index']);
return `await wa.linkByText (${params})\n`; return `await wa.linkByText ({executionId:executionId, ${params}})\n`;
} }
]; ];
@ -869,7 +870,7 @@ export class GBVMService extends GBService {
// page is not string. // page is not string.
// https://github.com/GeneralBots/BotServer/issues/310 // https://github.com/GeneralBots/BotServer/issues/310
const params = this.getParams('page,' + $3, ['handle', 'frameOrSelector', 'selector']); const params = this.getParams('page,' + $3, ['handle', 'frameOrSelector', 'selector']);
return `await wa.click (${params})\n`; return `await wa.click ({executionId:executionId, ${params}})\n`;
} }
]; ];
@ -877,7 +878,7 @@ export class GBVMService extends GBService {
/^\s*(send file)(\s*)(.*)/gim, /^\s*(send file)(\s*)(.*)/gim,
($0, $1, $2, $3) => { ($0, $1, $2, $3) => {
const params = this.getParams($3, ['filename', 'caption']); const params = this.getParams($3, ['filename', 'caption']);
return `await dk.sendFile(${params})\n`; return `await dk.sendFile({executionId:executionId, ${params}})\n`;
} }
]; ];
@ -885,7 +886,7 @@ export class GBVMService extends GBService {
/^\s*(copy)(\s*)(.*)/gim, /^\s*(copy)(\s*)(.*)/gim,
($0, $1, $2, $3) => { ($0, $1, $2, $3) => {
const params = this.getParams($3, ['src', 'dst']); const params = this.getParams($3, ['src', 'dst']);
return `await sys.copyFile (${params})\n`; return `await sys.copyFile ({executionId:executionId, ${params}})\n`;
} }
]; ];
@ -893,14 +894,14 @@ export class GBVMService extends GBService {
/^\s*(convert)(\s*)(.*)/gim, /^\s*(convert)(\s*)(.*)/gim,
($0, $1, $2, $3) => { ($0, $1, $2, $3) => {
const params = this.getParams($3, ['src', 'dst']); const params = this.getParams($3, ['src', 'dst']);
return `await sys.convert (${params})\n`; return `await sys.convert ({executionId:executionId, ${params}})\n`;
} }
]; ];
keywords[i++] = [ keywords[i++] = [
/^\s*(\w+)\s*\=\s*(.*)\s*as chart/gim, /^\s*(\w+)\s*\=\s*(.*)\s*as chart/gim,
($0, $1, $2) => { ($0, $1, $2) => {
return `await dk.chart ({type:'bar', data: ${2}, legends:null, transpose: false})\n`; return `await dk.chart ({executionId:executionId, type:'bar', data: ${2}, legends:null, transpose: false})\n`;
} }
]; ];
@ -908,69 +909,69 @@ export class GBVMService extends GBService {
/^\s*(chart)(\s*)(.*)/gim, /^\s*(chart)(\s*)(.*)/gim,
($0, $1, $2, $3) => { ($0, $1, $2, $3) => {
const params = this.getParams($3, ['type', 'data', 'legends', 'transpose']); const params = this.getParams($3, ['type', 'data', 'legends', 'transpose']);
return `await dk.chart (${params})\n`; return `await dk.chart ({executionId:executionId, ${params}})\n`;
} }
]; ];
keywords[i++] = [ keywords[i++] = [
/^\s*MERGE\s*(.*)\s*WITH\s*(.*)BY\s*(.*)/gim, /^\s*MERGE\s*(.*)\s*WITH\s*(.*)BY\s*(.*)/gim,
($0, $1, $2, $3) => { ($0, $1, $2, $3) => {
return `await sys.merge({file: ${$1}, data: ${$2}, key1: ${$3}})\n`; return `await sys.merge({executionId:executionId, file: ${$1}, data: ${$2}, key1: ${$3}})\n`;
} }
]; ];
keywords[i++] = [ keywords[i++] = [
/^\s*PRESS\s*(.*)/gim, /^\s*PRESS\s*(.*)/gim,
($0, $1, $2) => { ($0, $1, $2) => {
return `await wa.pressKey({handle: page, char: ${$1})\n`; return `await wa.pressKey({executionId:executionId, handle: page, char: ${$1})\n`;
} }
]; ];
keywords[i++] = [ keywords[i++] = [
/^\s*SCREENSHOT\s*(.*)/gim, /^\s*SCREENSHOT\s*(.*)/gim,
($0, $1, $2) => { ($0, $1, $2) => {
return `await wa.screenshot({handle: page, selector: ${$1}})\n`; return `await wa.screenshot({executionId:executionId, handle: page, selector: ${$1}})\n`;
} }
]; ];
keywords[i++] = [ keywords[i++] = [
/^\s*TWEET\s*(.*)/gim, /^\s*TWEET\s*(.*)/gim,
($0, $1, $2) => { ($0, $1, $2) => {
return `await sys.tweet({text: ${$1})\n`; return `await sys.tweet({executionId:executionId, text: ${$1})\n`;
} }
]; ];
keywords[i++] = [ keywords[i++] = [
/^\s*(\w+)\s*\=\s*(.*)\s*as image/gim, /^\s*(\w+)\s*\=\s*(.*)\s*as image/gim,
($0, $1, $2) => { ($0, $1, $2) => {
return `${$1} = await sys.asImage({data: ${$2}})\n`; return `${$1} = await sys.asImage({executionId:executionId, data: ${$2}})\n`;
} }
]; ];
keywords[i++] = [ keywords[i++] = [
/^\s*(\w+)\s*\=\s*(.*)\s*as pdf/gim, /^\s*(\w+)\s*\=\s*(.*)\s*as pdf/gim,
($0, $1, $2) => { ($0, $1, $2) => {
return `${$1} = await sys.asPdf({data: ${$2})\n`; return `${$1} = await sys.asPdf({executionId:executionId, data: ${$2})\n`;
} }
]; ];
keywords[i++] = [ keywords[i++] = [
/^\s*(\w+)\s*\=\s*FILL\s*(.*)\s*WITH\s*(.*)/gim, /^\s*(\w+)\s*\=\s*FILL\s*(.*)\s*WITH\s*(.*)/gim,
($0, $1, $2, $3) => { ($0, $1, $2, $3) => {
return `${$1} = await sys.fill({templateName: ${$2}, data: ${$3}})\n`; return `${$1} = await sys.fill({executionId:executionId, templateName: ${$2}, data: ${$3}})\n`;
} }
]; ];
keywords[i++] = [ keywords[i++] = [
/^\s*save\s*(.*)\s*as\s*(.*)/gim, /^\s*save\s*(.*)\s*as\s*(.*)/gim,
($0, $1, $2, $3) => { ($0, $1, $2, $3) => {
return `await sys.saveFile({file: ${$2}, data: ${$1})\n`; return `await sys.saveFile({executionId:executionId, file: ${$2}, data: ${$1})\n`;
} }
]; ];
keywords[i++] = [ keywords[i++] = [
/^\s*(save)(\s*)(.*)/gim, /^\s*(save)(\s*)(.*)/gim,
($0, $1, $2, $3) => { ($0, $1, $2, $3) => {
return `await sys.save({args: [${$3}]})\n`; return `await sys.save({executionId:executionId, args: [${$3}]})\n`;
} }
]; ];
@ -978,7 +979,7 @@ export class GBVMService extends GBService {
/^\s*set\s*(.*)/gim, /^\s*set\s*(.*)/gim,
($0, $1, $2) => { ($0, $1, $2) => {
const params = this.getParams($1, ['file', 'address', 'value']); const params = this.getParams($1, ['file', 'address', 'value']);
return `await sys.set (${params})`; return `await sys.set ({executionId:executionId, ${params}})`;
} }
]; ];
return keywords; return keywords;

View file

@ -370,7 +370,7 @@ export class SystemKeywords {
/** /**
* Retrives a random id with a length of five, every time it is called. * Retrives a random id with a length of five, every time it is called.
*/ */
public async getRandomId () { public getRandomId () {
const idGeneration = this.dk['idGeneration']; const idGeneration = this.dk['idGeneration'];
if (idGeneration && idGeneration.trim().toLowerCase() === 'number') { if (idGeneration && idGeneration.trim().toLowerCase() === 'number') {
return GBAdminService.getNumberIdentifier(); return GBAdminService.getNumberIdentifier();

View file

@ -119,14 +119,14 @@ export class WebAutomationKeywords {
* *
* @example OPEN "https://wikipedia.org" * @example OPEN "https://wikipedia.org"
*/ */
public async getPage ({ url, username, password }) { public async getPage ({ executionId, url, username, password }) {
GBLog.info(`BASIC: Web Automation GET PAGE ${url}.`); GBLog.info(`BASIC: Web Automation GET PAGE ${url}.`);
if (!this.browser) { if (!this.browser) {
this.browser = await createBrowser(null); this.browser = await createBrowser(null);
} }
const page = (await this.browser.pages())[0]; const page = (await this.browser.pages())[0];
if (username || password) { if (username || password) {
await page.authenticate({ username: username, password: password }); await page.authenticate({executionId, username: username, password: password });
} }
await page.goto(url); await page.goto(url);

View file

@ -41,12 +41,13 @@ import { GBMinService } from '../packages/core.gbapp/services/GBMinService.js';
*/ */
export class RootData { export class RootData {
public publicAddress: string; // URI for BotServer public executions: {}; // List of .gbdialog active executions.
public server: any; // Express reference public publicAddress: string; // URI for BotServer.
public sysPackages: any[]; // Loaded system package list public server: any; // Express reference.
public appPackages: any[]; // Loaded .gbapp package list public sysPackages: any[]; // Loaded system package list.
public minService: GBMinService; // Minimalist service core public appPackages: any[]; // Loaded .gbapp package list.
public bootInstance: IGBInstance; // General Bot Interface Instance public minService: GBMinService; // Minimalist service core.
public bootInstance: IGBInstance; // General Bot Interface Instance.
public minInstances: any[]; // List of bot instances. public minInstances: any[]; // List of bot instances.
public minBoot: GBMinInstance; // Reference to boot bot. public minBoot: GBMinInstance; // Reference to boot bot.
public wwwroot: string; // .gbui or a static webapp. public wwwroot: string; // .gbui or a static webapp.

View file

@ -84,6 +84,7 @@ export class GBServer {
const server = express(); const server = express();
GBServer.globals.server = server; GBServer.globals.server = server;
GBServer.globals.executions = {};
GBServer.globals.appPackages = []; GBServer.globals.appPackages = [];
GBServer.globals.sysPackages = []; GBServer.globals.sysPackages = [];
GBServer.globals.minInstances = []; GBServer.globals.minInstances = [];