fix(systemkeywords.ts): executionid, and changed to pid

This commit is contained in:
Alan Perdomo 2023-01-13 16:09:45 -03:00
parent b2cae7f21f
commit 274db0d389
9 changed files with 192 additions and 176 deletions

View file

@ -1,7 +1,7 @@
dist: focal dist: focal
language: node_js language: node_js
node_js: node_js:
- 19.3.0 - 19.4.0
notifications: notifications:

View file

@ -14,7 +14,7 @@
"Dário Vieira <dario.junior3@gmail.com>" "Dário Vieira <dario.junior3@gmail.com>"
], ],
"engines": { "engines": {
"node": "=19.3.0" "node": "=19.4.0"
}, },
"license": "AGPL-3.0", "license": "AGPL-3.0",
"preferGlobal": true, "preferGlobal": true,

View file

@ -265,21 +265,21 @@ export class DialogKeywords {
* *
* @example list = ACTIVE TASKS * @example list = ACTIVE TASKS
*/ */
public async getActiveTasks({ executionId }) {} public async getActiveTasks({ pid }) {}
/** /**
* Creates a new deal. * Creates a new deal.
* *
* @example CREATE DEAL dealname,contato,empresa,amount * @example CREATE DEAL dealname,contato,empresa,amount
*/ */
public async createDeal({ executionId, dealName, contact, company, amount }) {} public async createDeal({ pid, dealName, contact, company, amount }) {}
/** /**
* Finds contacts in XRM. * Finds contacts in XRM.
* *
* @example list = FIND CONTACT "Sandra" * @example list = FIND CONTACT "Sandra"
*/ */
public async fndContact({ executionId, name }) {} public async fndContact({ pid, name }) {}
public getContentLocaleWithCulture(contentLocale) { public getContentLocaleWithCulture(contentLocale) {
switch (contentLocale) { switch (contentLocale) {
@ -294,7 +294,7 @@ export class DialogKeywords {
} }
} }
public async getCoded({ executionId, value }) { public async getCoded({ pid, value }) {
// Checks if it is a GB FILE object. // Checks if it is a GB FILE object.
if (value.data && value.filename) { if (value.data && value.filename) {
@ -310,14 +310,14 @@ export class DialogKeywords {
* @example day = WEEKDAY (date) * @example day = WEEKDAY (date)
* *
*/ */
public getWeekFromDate(executionId, date) { public getWeekFromDate(pid, date) {
const contentLocale = this.min.core.getParam<string>( const contentLocale = this.min.core.getParam<string>(
this.min.instance, this.min.instance,
'Default Content Language', 'Default Content Language',
GBConfigService.get('DEFAULT_CONTENT_LANGUAGE') GBConfigService.get('DEFAULT_CONTENT_LANGUAGE')
); );
let dt = SystemKeywords.getDateFromLocaleString(executionId, date, contentLocale); let dt = SystemKeywords.getDateFromLocaleString(pid, date, contentLocale);
GBLog.info(`BASIC WEEKDAY contentLocale: ${this.getContentLocaleWithCulture(contentLocale)}`); GBLog.info(`BASIC WEEKDAY contentLocale: ${this.getContentLocaleWithCulture(contentLocale)}`);
GBLog.info(`BASIC WEEKDAY date: ${dt}`); GBLog.info(`BASIC WEEKDAY date: ${dt}`);
GBLog.info(dt.toLocaleString(this.getContentLocaleWithCulture(contentLocale), { weekday: 'short' })); GBLog.info(dt.toLocaleString(this.getContentLocaleWithCulture(contentLocale), { weekday: 'short' }));
@ -447,7 +447,7 @@ export class DialogKeywords {
* @example hour = HOUR (date) * @example hour = HOUR (date)
* *
*/ */
public getHourFromDate(executionId, date) { public getHourFromDate(pid, date) {
function addZero(i) { function addZero(i) {
if (i < 10) { if (i < 10) {
i = '0' + i; i = '0' + i;
@ -461,7 +461,7 @@ export class DialogKeywords {
GBConfigService.get('DEFAULT_CONTENT_LANGUAGE') GBConfigService.get('DEFAULT_CONTENT_LANGUAGE')
); );
let dt = SystemKeywords.getDateFromLocaleString(executionId, date, contentLocale); let dt = SystemKeywords.getDateFromLocaleString(pid, date, contentLocale);
if (dt) { if (dt) {
if (!(dt instanceof Date)) { if (!(dt instanceof Date)) {
@ -503,7 +503,7 @@ export class DialogKeywords {
* SEND MAIL "email@domain.com","Subject", "Message text." * SEND MAIL "email@domain.com","Subject", "Message text."
* *
*/ */
public async sendEmail({ executionId, to, subject, body }) { public async sendEmail({ pid, to, subject, body }) {
// tslint:disable-next-line:no-console // tslint:disable-next-line:no-console
GBLog.info(`[E-mail]: to:${to},subject: ${subject},body: ${body}.`); GBLog.info(`[E-mail]: to:${to},subject: ${subject},body: ${body}.`);
@ -541,9 +541,9 @@ export class DialogKeywords {
* @example SEND FILE TO "+199988887777","image.jpg",caption * @example SEND FILE TO "+199988887777","image.jpg",caption
* *
*/ */
public async sendFileTo({ executionId, mobile, filename, caption }) { public async sendFileTo({ pid, mobile, filename, caption }) {
GBLog.info(`BASIC: SEND FILE TO '${mobile}',filename '${filename}'.`); GBLog.info(`BASIC: SEND FILE TO '${mobile}',filename '${filename}'.`);
return await this.internalSendFile({ executionId, mobile, filename, caption }); return await this.internalSendFile({ pid, mobile, filename, caption });
} }
/** /**
@ -552,10 +552,10 @@ export class DialogKeywords {
* @example SEND FILE "image.jpg" * @example SEND FILE "image.jpg"
* *
*/ */
public async sendFile({ executionId, filename, caption }) { public async sendFile({ pid, filename, caption }) {
const mobile = await this.userMobile(); const mobile = await this.userMobile();
GBLog.info(`BASIC: SEND FILE (current: ${mobile},filename '${filename}'.`); GBLog.info(`BASIC: SEND FILE (current: ${mobile},filename '${filename}'.`);
return await this.internalSendFile({ executionId, mobile, filename, caption }); return await this.internalSendFile({ pid, mobile, filename, caption });
} }
/** /**
@ -717,7 +717,13 @@ export class DialogKeywords {
* @example HEAR name * @example HEAR name
* *
*/ */
public async getHear({ executionId, kind, arg }) { public async getHear({ pid, kind, arg }) {
const process = GBServer.globals.processes[pid];
const min = GBServer.globals.minInstances.filter(p =>
p.instance.instanceId == process.instanceId)[0];
// Handles first arg as an array of args. // Handles first arg as an array of args.
let args = []; let args = [];
@ -730,12 +736,13 @@ export class DialogKeywords {
const isIntentYes = (locale, utterance) => { const isIntentYes = (locale, utterance) => {
return utterance.toLowerCase().match(Messages[locale].affirmative_sentences); return utterance.toLowerCase().match(Messages[locale].affirmative_sentences);
}; };
const sec = new SecService();
if (this.hrOn) { if (this.hrOn) {
const sec = new SecService();
user = await sec.getUserFromAgentSystemId(this.hrOn); user = await sec.getUserFromAgentSystemId(this.hrOn);
} else { } else {
user = this.user.systemUser; user = await sec.getUserFromId (process.instanceId, process.userId);
} }
const userId = user.userId; const userId = user.userId;
let result; let result;
@ -830,8 +837,8 @@ export class DialogKeywords {
const value = extractEntity(text); const value = extractEntity(text);
if (value === null) { if (value === null) {
await this.talk({ executionId, text: 'Por favor,digite um e-mail válido.' }); await this.talk({ pid, text: 'Por favor,digite um e-mail válido.' });
return await this.getHear({ executionId, kind, arg }); return await this.getHear({ pid, kind, arg });
} }
result = value; result = value;
@ -843,8 +850,8 @@ export class DialogKeywords {
const value = extractEntity(text); const value = extractEntity(text);
if (value === null || value.length != 1) { if (value === null || value.length != 1) {
await this.talk({ executionId, text: 'Por favor,digite um nome válido.' }); await this.talk({ pid, text: 'Por favor,digite um nome válido.' });
return await this.getHear({ executionId, kind, arg }); return await this.getHear({ pid, kind, arg });
} }
result = value; result = value;
@ -856,8 +863,8 @@ export class DialogKeywords {
const value = extractEntity(text); const value = extractEntity(text);
if (value === null || value.length != 1) { if (value === null || value.length != 1) {
await this.talk({ executionId, text: 'Por favor,digite um número válido.' }); await this.talk({ pid, text: 'Por favor,digite um número válido.' });
return await this.getHear({ executionId, kind, arg }); return await this.getHear({ pid, kind, arg });
} }
result = value; result = value;
@ -871,8 +878,8 @@ export class DialogKeywords {
const value = extractEntity(text); const value = extractEntity(text);
if (value === null || value.length != 1) { if (value === null || value.length != 1) {
await this.talk({ executionId, text: 'Por favor,digite uma data no formato 12/12/2020.' }); await this.talk({ pid, text: 'Por favor,digite uma data no formato 12/12/2020.' });
return await this.getHear({ executionId, kind, arg }); return await this.getHear({ pid, kind, arg });
} }
result = value; result = value;
@ -884,8 +891,8 @@ export class DialogKeywords {
const value = extractEntity(text); const value = extractEntity(text);
if (value === null || value.length != 1) { if (value === null || value.length != 1) {
await this.talk({ executionId, text: 'Por favor,digite um horário no formato hh:ss.' }); await this.talk({ pid, text: 'Por favor,digite um horário no formato hh:ss.' });
return await this.getHear({ executionId, kind, arg }); return await this.getHear({ pid, kind, arg });
} }
result = value; result = value;
@ -904,8 +911,8 @@ export class DialogKeywords {
const value = extractEntity(text); const value = extractEntity(text);
if (value === null || value.length != 1) { if (value === null || value.length != 1) {
await this.talk({ executionId, text: 'Por favor,digite um valor monetário.' }); await this.talk({ pid, text: 'Por favor,digite um valor monetário.' });
return await this.getHear({ executionId, kind, arg }); return await this.getHear({ pid, kind, arg });
} }
result = value; result = value;
@ -918,11 +925,11 @@ export class DialogKeywords {
} catch (error) { } catch (error) {
await this.talk(Messages[locale].validation_enter_valid_mobile); await this.talk(Messages[locale].validation_enter_valid_mobile);
return await this.getHear({ executionId, kind, arg }); return await this.getHear({ pid, kind, arg });
} }
if (!phoneUtil.isPossibleNumber(phoneNumber)) { if (!phoneUtil.isPossibleNumber(phoneNumber)) {
await this.talk({ executionId, text: 'Por favor,digite um número de telefone válido.' }); await this.talk({ pid, text: 'Por favor,digite um número de telefone válido.' });
return await this.getHear({ executionId, kind, arg }); return await this.getHear({ pid, kind, arg });
} }
result = phoneNumber; result = phoneNumber;
@ -941,8 +948,8 @@ export class DialogKeywords {
const value = extractEntity(text); const value = extractEntity(text);
if (value === null || value.length != 1) { if (value === null || value.length != 1) {
await this.talk({ executionId, text: 'Por favor, digite um CEP válido.' }); await this.talk({ pid, text: 'Por favor, digite um CEP válido.' });
return await this.getHear({ executionId, kind, arg }); return await this.getHear({ pid, kind, arg });
} }
result = value[0]; result = value[0];
@ -956,8 +963,8 @@ export class DialogKeywords {
}); });
if (result === null) { if (result === null) {
await this.talk({ executionId, text: `Escolha por favor um dos itens sugeridos.` }); await this.talk({ pid, text: `Escolha por favor um dos itens sugeridos.` });
return await this.getHear({ executionId, kind, arg }); return await this.getHear({ pid, kind, arg });
} }
} else if (kind === 'language') { } else if (kind === 'language') {
result = null; result = null;
@ -988,8 +995,8 @@ export class DialogKeywords {
}); });
if (result === null) { if (result === null) {
await this.talk({ executionId, text: `Escolha por favor um dos itens sugeridos.` }); await this.talk({ pid, text: `Escolha por favor um dos itens sugeridos.` });
return await this.getHear({ executionId, kind, arg }); return await this.getHear({ pid, kind, arg });
} }
} }
return result; return result;
@ -1028,25 +1035,10 @@ export class DialogKeywords {
} }
} }
public async getSingleton({}) {
return {
id: this.sys().getRandomId(),
username: this.userName(),
mobile: this.userMobile(),
from: this.userMobile(),
ENTER: String.fromCharCode(13),
headers: {},
data: {},
list: [],
httpUsername: '',
httpPs: ''
};
}
/** /**
* Talks to the user by using the specified text. * Talks to the user by using the specified text.
*/ */
public async talk({ executionId, text }) { public async talk({ pid, text }) {
GBLog.info(`BASIC: TALK '${text}'.`); GBLog.info(`BASIC: TALK '${text}'.`);
if (this.user) { if (this.user) {
const translate = this.user ? this.user.basicOptions.translatorOn : false; const translate = this.user ? this.user.basicOptions.translatorOn : false;
@ -1063,7 +1055,7 @@ export class DialogKeywords {
/** /**
* Processes the sending of the file. * Processes the sending of the file.
*/ */
private async internalSendFile({ executionId, mobile, filename, caption }) { private async internalSendFile({ pid, mobile, filename, caption }) {
// Handles SEND FILE TO mobile,element in Web Automation. // Handles SEND FILE TO mobile,element in Web Automation.
const element = filename._page ? filename._page : filename.screenshot ? filename : null; const element = filename._page ? filename._page : filename.screenshot ? filename : null;
@ -1108,7 +1100,7 @@ export class DialogKeywords {
} }
} }
public async getQRCode({ executionId, text }) { public async getQRCode({ pid, text }) {
const img = await qrcode.toDataURL(text); const img = await qrcode.toDataURL(text);
const data = img.replace(/^data:image\/\w+;base64,/, ''); const data = img.replace(/^data:image\/\w+;base64,/, '');
const buf = Buffer.from(data, 'base64'); const buf = Buffer.from(data, 'base64');

View file

@ -51,7 +51,8 @@ import Path from 'path';
import indent from 'indent.js'; import indent from 'indent.js';
import { GBAdminService } from '../../admin.gbapp/services/GBAdminService.js'; import { GBAdminService } from '../../admin.gbapp/services/GBAdminService.js';
import pkg from 'swagger-client'; import pkg from 'swagger-client';
const {Swagger} = pkg; import { DialogKeywords } from './DialogKeywords.js';
const { Swagger } = pkg;
/** /**
* @fileoverview Decision was to priorize security(isolation) and debugging, * @fileoverview Decision was to priorize security(isolation) and debugging,
@ -62,7 +63,7 @@ const {Swagger} = pkg;
* Basic services for BASIC manipulation. * Basic services for BASIC manipulation.
*/ */
export class GBVMService extends GBService { export class GBVMService extends GBService {
public async loadDialogPackage (folder: string, min: GBMinInstance, core: IGBCoreService, deployer: GBDeployer) { public async loadDialogPackage(folder: string, min: GBMinInstance, core: IGBCoreService, deployer: GBDeployer) {
const files = await walkPromise(folder); const files = await walkPromise(folder);
await CollectionUtil.asyncForEach(files, async file => { await CollectionUtil.asyncForEach(files, async file => {
@ -158,7 +159,7 @@ export class GBVMService extends GBService {
}); });
} }
public async translateBASIC (filename: any, min: GBMinInstance, deployer: GBDeployer, mainName: string) { public async translateBASIC(filename: any, min: GBMinInstance, deployer: GBDeployer, mainName: string) {
// Converts General Bots BASIC into regular VBS // Converts General Bots BASIC into regular VBS
let basicCode: string = Fs.readFileSync(filename, 'utf8'); let basicCode: string = Fs.readFileSync(filename, 'utf8');
@ -241,18 +242,17 @@ export class GBVMService extends GBService {
// Local variables. // Local variables.
const gb = await dk.getSingleton(); const pid = this.pid;
const executionId = gb.executionId; const id = this.id;
const id = gb.id; const username = this.username;
const username = gb.username; const mobile = this.mobile;
const mobile = gb.mobile; const from = this.from;
const from = gb.from; const ENTER = this.ENTER;
const ENTER = gb.ENTER; const headers = this.headers;
const headers = gb.headers; const data = this.data;
const data = gb.data; const list = this.list;
const list = gb.list; const httpUsername = this.httpUsername;
const httpUsername = gb.httpUsername; const httpPs = this.httpPs;
const httpPs = gb.httpPs;
let page = null; let page = null;
@ -282,19 +282,19 @@ export class GBVMService extends GBService {
} }
} }
public static getMethodNameFromVBSFilename (filename: string) { public static getMethodNameFromVBSFilename(filename: string) {
let mainName = filename.replace(/\s*|\-/gim, '').split('.')[0]; let mainName = filename.replace(/\s*|\-/gim, '').split('.')[0];
return mainName.toLowerCase(); return mainName.toLowerCase();
} }
public static getSetScheduleKeywordArgs (code: string) { public static getSetScheduleKeywordArgs(code: string) {
if (!code) return null; if (!code) return null;
const keyword = /^\s*SET SCHEDULE (.*)/gim; const keyword = /^\s*SET SCHEDULE (.*)/gim;
const result = keyword.exec(code); const result = keyword.exec(code);
return result ? result[1] : null; return result ? result[1] : null;
} }
private async getTextFromWord (folder: string, filename: string) { private async getTextFromWord(folder: string, filename: string) {
return new Promise<string>(async (resolve, reject) => { return new Promise<string>(async (resolve, reject) => {
textract.fromFileWithPath(urlJoin(folder, filename), { preserveLineBreaks: true }, (error, text) => { textract.fromFileWithPath(urlJoin(folder, filename), { preserveLineBreaks: true }, (error, text) => {
if (error) { if (error) {
@ -351,7 +351,7 @@ export class GBVMService extends GBService {
* *
* @param code General Bots BASIC * @param code General Bots BASIC
*/ */
public async convertGBASICToVBS (min: GBMinInstance, code: string) { public async convertGBASICToVBS(min: GBMinInstance, code: string) {
// Start and End of VB2TS tags of processing. // Start and End of VB2TS tags of processing.
code = `<%\n code = `<%\n
@ -382,7 +382,7 @@ export class GBVMService extends GBService {
return { code, jsonMap }; return { code, jsonMap };
} }
private getKeywords () { private getKeywords() {
// Keywords from General Bots BASIC. // Keywords from General Bots BASIC.
let keywords = []; let keywords = [];
@ -393,7 +393,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({executionId:executionId, data:${$1}, sql:"${sql}", tableName:"${tableName}"})\n`; return `${$1} = await sys.executeSQL({pid: pid, data:${$1}, sql:"${sql}", tableName:"${tableName}"})\n`;
} }
]; ];
@ -403,9 +403,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, ['executionId', 'url', 'username', 'password']); const params = this.getParams($1, ['pid', 'url', 'username', 'password']);
return `page = await wa.getPage({executionId:executionId,${params}})\n`; return `page = await wa.getPage({pid: pid,${params}})\n`;
} }
]; ];
@ -419,114 +419,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({executionId:executionId, kind:"login"})`; return `${$1} = await dk.getHear({pid: pid, 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({executionId:executionId, kind:"email"})`; return `${$1} = await dk.getHear({pid: pid, 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({executionId:executionId, kind:"integer"})`; return `${$1} = await dk.getHear({pid: pid, 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({executionId:executionId, kind:"file"})`; return `${$1} = await dk.getHear({pid: pid, 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({executionId:executionId, kind:"boolean"})`; return `${$1} = await dk.getHear({pid: pid, 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({executionId:executionId, kind:"name"})`; return `${$1} = await dk.getHear({pid: pid, 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({executionId:executionId, kind:"date"})`; return `${$1} = await dk.getHear({pid: pid, 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({executionId:executionId, kind:"hour"})`; return `${$1} = await dk.getHear({pid: pid, 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({executionId:executionId, kind:"phone"})`; return `${$1} = await dk.getHear({pid: pid, 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({executionId:executionId, kind:"money")}`; return `${$1} = await dk.getHear({pid: pid, 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({executionId:executionId, kind:"language")}`; return `${$1} = await dk.getHear({pid: pid, 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({executionId:executionId, kind:"zipcode")}`; return `${$1} = await dk.getHear({pid: pid, 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({executionId:executionId, kind:"menu", args: [${$2}])}`; return `${$1} = await dk.getHear({pid: pid, 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({executionId:executionId})`; return `${$2} = await dk.getHear({pid: pid})`;
} }
]; ];
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({executionId:executionId, ${$2}})\n`; return `${$1} = await dk.fndContact({pid: pid, ${$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({executionId:executionId, args:[${$2}])\n return `${$1} = await sys.find({pid: pid, args:[${$2}])\n
if (!${$1}) { if (!${$1}) {
await dk.talk ({executionId:executionId, ${$3}})\n; await dk.talk ({pid: pid, ${$3}})\n;
return -1; return -1;
} }
`; `;
@ -544,7 +544,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({executionId:executionId, args: [${$2}]})\n`; ${$1} = await sys.find({pid: pid, args: [${$2}]})\n`;
} }
]; ];
@ -553,56 +553,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({executionId:executionId, ${params}})\n`; return `${$1} = await dk.createDeal({pid: pid, ${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({executionId:executionId})\n`; return `${$1} = await dk.getActiveTasks({pid: pid})\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({executionId:executionId, args:[${$2}]})\n`; return `${$1} = await sys.append({pid: pid, 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({executionId:executionId, array: ${$2}, memberName: "${$3}"})\n`; return `${$1} = await sys.sortBy({pid: pid, 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({executionId:executionId, url: ${$1})\n`; return `${$2} = await sys.seeText({pid: pid, 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({executionId:executionId, url: ${$1})\n`; return `${$2} = await sys.seeCaption({pid: pid, 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({executionId:executionId, seconds:${$2}})`; return `await sys.wait({pid: pid, 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({executionId:executionId, symbol: ${$2})`; return `stock = await sys.getStock({pid: pid, symbol: ${$2})`;
} }
]; ];
@ -615,19 +615,17 @@ export class GBVMService extends GBService {
// Handles GET "selector". // Handles GET "selector".
if (count == 1) { if (count == 1) {
return `${$1} = await wa.getBySelector({executionId:executionId, handle:page, selector: ${values[0]}})`; return `${$1} = await wa.getBySelector({pid: pid, 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({executionId:executionId, handle: page, ${values[0]}, frameOrSelector: ${values[1]}, selector: ${ return `${$1} = await wa.getByFrame({pid: pid, 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 ({executionId:executionId, file: ${$2}, addressOrHeaders: headers, httpUsername, httpPs})`; return `${$1} = await sys.get ({pid: pid, file: ${$2}, addressOrHeaders: headers, httpUsername, httpPs})`;
} }
} }
]; ];
@ -635,7 +633,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 ` = {executionId:executionId}`; return ` = {pid: pid}`;
} }
]; ];
@ -650,14 +648,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({executionId:executionId, ${params}})\n`; return `await dk.gotoDialog({pid: pid, ${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 ({executionId:executionId, ${$3}})\n`; return `await dk.setLanguage ({pid: pid, ${$3}})\n`;
} }
]; ];
@ -686,7 +684,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 (executionId:executionId, ${params}})\n`; return `await dk.dateDiff (pid: pid, ${params}})\n`;
} }
]; ];
@ -694,98 +692,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 (executionId:executionId, ${$3})\n`; return `await dk.dateAdd (pid: pid, ${$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 ({executionId:executionId, count: ${$3}})\n`; return `await dk.setMaxLines ({pid: pid, 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 ({executionId:executionId, count: ${$3}})\n`; return `await dk.setMaxColumns ({pid: pid, 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 ({executionId:executionId, on: "${$3.toLowerCase()}"})\n`; return `await dk.setTranslatorOn ({pid: pid, 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 ({executionId:executionId, theme: "${$3.toLowerCase()}"})\n`; return `await dk.setTheme ({pid: pid, 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 ({executionId:executionId, on: "${$3.toLowerCase()}"})\n`; return `await dk.setWholeWord ({pid: pid, 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 ({executionId:executionId, url:${$2}, data:${$3}, headers})`; return `${$1} = await sys.postByHttp ({pid: pid, 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 ({executionId:executionId, url:${$2}, data:${$3}, headers})`; return `${$1} = await sys.putByHttp ({pid: pid, 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 ({executionId:executionId, handle:page, selector: ${$2}, folder:${$3}})`; return `${$1} = await sys.download ({pid: pid, 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 ({executionId:executionId, name:${$2}})`; return `${$1} = await sys.createFolder ({pid: pid, name:${$2}})`;
} }
]; ];
keywords[i++] = [ keywords[i++] = [
/^\s*SHARE FOLDER\s*(.*)/gim, /^\s*SHARE FOLDER\s*(.*)/gim,
($0, $1) => { ($0, $1) => {
return `await sys.shareFolder ({executionId:executionId, name: ${$1}})`; return `await sys.shareFolder ({pid: pid, 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 ({executionId:executionId, ${$3}})`; return `await sys.createABotFarmUsing ({pid: pid, ${$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 ({executionId:executionId, to:${$3}})\n`; return `await dk.transferTo ({pid: pid, to:${$3}})\n`;
} }
]; ];
keywords[i++] = [ keywords[i++] = [
/^\s*(\btransfer\b)(?=(?:[^"]|"[^"]*")*$)/gim, /^\s*(\btransfer\b)(?=(?:[^"]|"[^"]*")*$)/gim,
() => { () => {
return `await dk.transferTo ({executionId:executionId, })\n`; return `await dk.transferTo ({pid: pid, })\n`;
} }
]; ];
@ -799,7 +797,7 @@ export class GBVMService extends GBService {
keywords[i++] = [ keywords[i++] = [
/^\s*(show menu)/gim, /^\s*(show menu)/gim,
() => { () => {
return `await dk.showMenu ({executionId:executionId, })\n`; return `await dk.showMenu ({pid: pid, })\n`;
} }
]; ];
@ -807,7 +805,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({executionId:executionId, ${params}})\n`; return `await sys.talkTo({pid: pid, ${params}})\n`;
} }
]; ];
@ -817,7 +815,7 @@ export class GBVMService extends GBService {
if ($3.substr(0, 1) !== '"') { if ($3.substr(0, 1) !== '"') {
$3 = `"${$3}"`; $3 = `"${$3}"`;
} }
return `await dk.talk ({executionId:executionId, text: ${$3}})\n`; return `await dk.talk ({pid: pid, text: ${$3}})\n`;
} }
]; ];
@ -825,7 +823,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({executionId:executionId, ${params}})\n`; return `await sys.sendSmsTo({pid: pid, ${params}})\n`;
} }
]; ];
@ -833,7 +831,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({executionId:executionId, ${params}})\n`; return `await dk.sendEmail({pid: pid, ${params}})\n`;
} }
]; ];
@ -841,7 +839,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({executionId:executionId, ${params}})\n`; return `await dk.sendEmail({pid: pid, ${params}})\n`;
} }
]; ];
@ -849,7 +847,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({executionId:executionId, ${params}})\n`; return `await dk.sendFileTo({pid: pid, ${params}})\n`;
} }
]; ];
@ -857,7 +855,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 ({executionId:executionId, ${params}})\n`; return `await wa.hover ({pid: pid, ${params}})\n`;
} }
]; ];
@ -865,7 +863,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 ({executionId:executionId, ${params}})\n`; return `await wa.linkByText ({pid: pid, ${params}})\n`;
} }
]; ];
@ -875,7 +873,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 ({executionId:executionId, ${params}})\n`; return `await wa.click ({pid: pid, ${params}})\n`;
} }
]; ];
@ -883,7 +881,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({executionId:executionId, ${params}})\n`; return `await dk.sendFile({pid: pid, ${params}})\n`;
} }
]; ];
@ -891,7 +889,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 ({executionId:executionId, ${params}})\n`; return `await sys.copyFile ({pid: pid, ${params}})\n`;
} }
]; ];
@ -899,14 +897,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 ({executionId:executionId, ${params}})\n`; return `await sys.convert ({pid: pid, ${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 ({executionId:executionId, type:'bar', data: ${2}, legends:null, transpose: false})\n`; return `await dk.chart ({pid: pid, type:'bar', data: ${2}, legends:null, transpose: false})\n`;
} }
]; ];
@ -914,69 +912,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 ({executionId:executionId, ${params}})\n`; return `await dk.chart ({pid: pid, ${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({executionId:executionId, file: ${$1}, data: ${$2}, key1: ${$3}})\n`; return `await sys.merge({pid: pid, 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({executionId:executionId, handle: page, char: ${$1})\n`; return `await wa.pressKey({pid: pid, 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({executionId:executionId, handle: page, selector: ${$1}})\n`; return `await wa.screenshot({pid: pid, 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({executionId:executionId, text: ${$1})\n`; return `await sys.tweet({pid: pid, 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({executionId:executionId, data: ${$2}})\n`; return `${$1} = await sys.asImage({pid: pid, 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({executionId:executionId, data: ${$2})\n`; return `${$1} = await sys.asPdf({pid: pid, 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({executionId:executionId, templateName: ${$2}, data: ${$3}})\n`; return `${$1} = await sys.fill({pid: pid, 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({executionId:executionId, file: ${$2}, data: ${$1})\n`; return `await sys.saveFile({pid: pid, 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({executionId:executionId, args: [${$3}]})\n`; return `await sys.save({pid: pid, args: [${$3}]})\n`;
} }
]; ];
@ -984,7 +982,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 ({executionId:executionId, ${params}})`; return `await sys.set ({pid: pid, ${params}})`;
} }
]; ];
return keywords; return keywords;
@ -993,7 +991,7 @@ export class GBVMService extends GBService {
/** /**
* Executes the converted JavaScript from BASIC code inside execution context. * Executes the converted JavaScript from BASIC code inside execution context.
*/ */
public static async callVM (text: string, min: GBMinInstance, step, GBDialogdeployer: GBDeployer, debug: boolean) { public static async callVM(text: string, min: GBMinInstance, step, deployer: GBDeployer, debug: boolean) {
const debuggerPort = 9222; const debuggerPort = 9222;
// Creates a class DialogKeywords which is the *this* pointer // Creates a class DialogKeywords which is the *this* pointer
@ -1001,7 +999,9 @@ export class GBVMService extends GBService {
const user = step ? await min.userProfile.get(step.context, {}) : null; const user = step ? await min.userProfile.get(step.context, {}) : null;
const sandbox = { user: user.systemUser }; const dk = new DialogKeywords(min, deployer, user);
const sandbox = {};
const contentLocale = min.core.getParam<string>( const contentLocale = min.core.getParam<string>(
min.instance, min.instance,
@ -1026,16 +1026,30 @@ export class GBVMService extends GBService {
const scriptPath = urlJoin(gbdialogPath, `${text}.js`); const scriptPath = urlJoin(gbdialogPath, `${text}.js`);
let code = min.sandBoxMap[text]; let code = min.sandBoxMap[text];
const executionId = GBAdminService.getNumberIdentifier(); const pid = GBAdminService.getNumberIdentifier();
GBServer.globals.executions[executionId]={ GBServer.globals.processes[pid] = {
executionId: executionId, userId: user.systemUser.userId,
instanceId: min.instance.instanceId
}; };
sandbox['id'] = dk.sys().getRandomId();
sandbox['username'] = await dk.userName();
sandbox['mobile'] = await dk.userMobile();
sandbox['from'] = await dk.userMobile();
sandbox['ENTER'] = String.fromCharCode(13);
sandbox['headers'] = {};
sandbox['data'] = {};
sandbox['list'] = [];
sandbox['httpUsername'] = '';
sandbox['httpPs'] = '';
sandbox['pid'] = pid;
if (GBConfigService.get('VM3') === 'true') { if (GBConfigService.get('VM3') === 'true') {
try { try {
const vm1 = new NodeVM({ const vm1 = new NodeVM({
allowAsync: true, allowAsync: true,
sandbox: {}, sandbox: sandbox,
console: 'inherit', console: 'inherit',
wrapper: 'commonjs', wrapper: 'commonjs',
require: { require: {

View file

@ -44,6 +44,7 @@ import urlJoin from 'url-join';
import Fs from 'fs'; import Fs from 'fs';
import Path from 'path'; import Path from 'path';
import url from 'url'; import url from 'url';
import { pid } from 'process';
/** /**
* Web Automation services of conversation to be called by BASIC. * Web Automation services of conversation to be called by BASIC.
@ -119,14 +120,14 @@ export class WebAutomationKeywords {
* *
* @example OPEN "https://wikipedia.org" * @example OPEN "https://wikipedia.org"
*/ */
public async getPage ({ executionId, url, username, password }) { public async getPage ({ pid, 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({executionId, username: username, password: password }); await page.authenticate({pid, username: username, password: password });
} }
await page.goto(url); await page.goto(url);
@ -189,12 +190,12 @@ export class WebAutomationKeywords {
/** /**
* Simulates a mouse hover an web page element. * Simulates a mouse hover an web page element.
*/ */
public async hover ({ executionId, handle, selector }) { public async hover ({ pid, handle, selector }) {
const page = this.getPageByHandle(handle); const page = this.getPageByHandle(handle);
GBLog.info(`BASIC: Web Automation HOVER element: ${selector}.`); GBLog.info(`BASIC: Web Automation HOVER element: ${selector}.`);
await this.getBySelector({ handle, selector: selector }); await this.getBySelector({ handle, selector: selector });
await page.hover(selector); await page.hover(selector);
await this.debugStepWeb(executionId, page); await this.debugStepWeb(pid, page);
} }
/** /**
@ -202,7 +203,7 @@ export class WebAutomationKeywords {
* *
* @example CLICK page,"#idElement" * @example CLICK page,"#idElement"
*/ */
public async click ({ executionId, handle, frameOrSelector, selector }) { public async click ({ pid, handle, frameOrSelector, selector }) {
const page = this.getPageByHandle(handle); const page = this.getPageByHandle(handle);
GBLog.info(`BASIC: Web Automation CLICK element: ${frameOrSelector}.`); GBLog.info(`BASIC: Web Automation CLICK element: ${frameOrSelector}.`);
if (selector) { if (selector) {
@ -215,10 +216,10 @@ export class WebAutomationKeywords {
await page.waitForSelector(frameOrSelector); await page.waitForSelector(frameOrSelector);
await page.click(frameOrSelector); await page.click(frameOrSelector);
} }
await this.debugStepWeb(executionId, page); await this.debugStepWeb(pid, page);
} }
private async debugStepWeb (executionId, page) { private async debugStepWeb (pid, page) {
let refresh = true; let refresh = true;
if (this.lastDebugWeb) { if (this.lastDebugWeb) {
refresh = new Date().getTime() - this.lastDebugWeb.getTime() > 5000; refresh = new Date().getTime() - this.lastDebugWeb.getTime() > 5000;
@ -228,7 +229,7 @@ export class WebAutomationKeywords {
const mobile = this.min.core.getParam(this.min.instance, 'Bot Admin Number', null); const mobile = this.min.core.getParam(this.min.instance, 'Bot Admin Number', null);
const filename = page; const filename = page;
if (mobile) { if (mobile) {
await this.dk.sendFileTo({executionId, mobile, filename, caption: 'General Bots Debugger' }); await this.dk.sendFileTo({pid: pid, mobile, filename, caption: 'General Bots Debugger' });
} }
this.lastDebugWeb = new Date(); this.lastDebugWeb = new Date();
} }
@ -255,7 +256,7 @@ export class WebAutomationKeywords {
} }
} }
public async linkByText ({ executionId, handle, text, index }) { public async linkByText ({ pid, handle, text, index }) {
const page = this.getPageByHandle(handle); const page = this.getPageByHandle(handle);
GBLog.info(`BASIC: Web Automation CLICK LINK TEXT: ${text} ${index}.`); GBLog.info(`BASIC: Web Automation CLICK LINK TEXT: ${text} ${index}.`);
if (!index) { if (!index) {
@ -263,7 +264,7 @@ export class WebAutomationKeywords {
} }
const els = await page.$x(`//a[contains(.,'${text}')]`); const els = await page.$x(`//a[contains(.,'${text}')]`);
await els[index - 1].click(); await els[index - 1].click();
await this.debugStepWeb(executionId, page); await this.debugStepWeb(pid, page);
} }
/** /**
@ -291,14 +292,14 @@ export class WebAutomationKeywords {
* *
* @example SET page,"selector","text" * @example SET page,"selector","text"
*/ */
public async setElementText ({ executionId, handle, selector, text }) { public async setElementText ({ pid, handle, selector, text }) {
const page = this.getPageByHandle(handle); const page = this.getPageByHandle(handle);
GBLog.info(`BASIC: Web Automation TYPE on ${selector}: ${text}.`); GBLog.info(`BASIC: Web Automation TYPE on ${selector}: ${text}.`);
const e = await this.getBySelector({ handle, selector }); const e = await this.getBySelector({ handle, selector });
await e.click({ clickCount: 3 }); await e.click({ clickCount: 3 });
await page.keyboard.press('Backspace'); await page.keyboard.press('Backspace');
await e.type(text, { delay: 200 }); await e.type(text, { delay: 200 });
await this.debugStepWeb(executionId, page); await this.debugStepWeb(pid, page);
} }
/** /**

View file

@ -196,6 +196,15 @@ export class SecService extends GBService {
return agentSystemId; return agentSystemId;
} }
public async getUserFromId (instanceId: number, userId: string): Promise<GuaribasUser> {
return await GuaribasUser.findOne({
where: {
instanceId: instanceId,
userId: userId
}
});
}
public async getUserFromSystemId (systemId: string): Promise<GuaribasUser> { public async getUserFromSystemId (systemId: string): Promise<GuaribasUser> {
return await GuaribasUser.findOne({ return await GuaribasUser.findOne({
where: { where: {

View file

@ -203,7 +203,7 @@ export class WhatsappDirectLine extends GBService {
msg msg
); );
s.sendEmail({executionId: 0, to: adminEmail, subject: `Check your WhatsApp for bot ${this.botId}`, body: msg }); s.sendEmail({pid: 0, to: adminEmail, subject: `Check your WhatsApp for bot ${this.botId}`, body: msg });
}).bind(this) }).bind(this)
); );

View file

@ -41,7 +41,7 @@ import { GBMinService } from '../packages/core.gbapp/services/GBMinService.js';
*/ */
export class RootData { export class RootData {
public executions: {}; // List of .gbdialog active executions. public processes: {}; // List of .gbdialog active executions.
public publicAddress: string; // URI for BotServer. public publicAddress: string; // URI for BotServer.
public server: any; // Express reference. public server: any; // Express reference.
public sysPackages: any[]; // Loaded system package list. public sysPackages: any[]; // Loaded system package list.

View file

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