fix(all): New templates.
This commit is contained in:
parent
26f5fcec7c
commit
03cc74ade6
12 changed files with 118 additions and 102 deletions
|
@ -45,7 +45,7 @@ import { GBUtil } from '../../../src/util.js';
|
||||||
export class DebuggerService {
|
export class DebuggerService {
|
||||||
|
|
||||||
public async setBreakpoint({ botId, line }) {
|
public async setBreakpoint({ botId, line }) {
|
||||||
GBLogEx.info(botId, `BASIC: Enabled breakpoint for ${botId} on ${line}.`);
|
GBLogEx.info(botId, `Enabled breakpoint for ${botId} on ${line}.`);
|
||||||
GBServer.globals.debuggers[botId].breaks.push(Number.parseInt(line));
|
GBServer.globals.debuggers[botId].breaks.push(Number.parseInt(line));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,11 +145,11 @@ export class DebuggerService {
|
||||||
error = `Cannot DEBUG an already running process. ${botId}`;
|
error = `Cannot DEBUG an already running process. ${botId}`;
|
||||||
return { error: error };
|
return { error: error };
|
||||||
} else if (GBServer.globals.debuggers[botId].state === 2) {
|
} else if (GBServer.globals.debuggers[botId].state === 2) {
|
||||||
GBLogEx.info(botId, `BASIC: Releasing execution ${botId} in DEBUG mode.`);
|
GBLogEx.info(botId, `Releasing execution ${botId} in DEBUG mode.`);
|
||||||
await this.resume({ botId });
|
await this.resume({ botId });
|
||||||
return { status: 'OK' };
|
return { status: 'OK' };
|
||||||
} else {
|
} else {
|
||||||
GBLogEx.info(botId, `BASIC: Running ${botId} in DEBUG mode.`);
|
GBLogEx.info(botId, `Running ${botId} in DEBUG mode.`);
|
||||||
GBServer.globals.debuggers[botId].state = 1;
|
GBServer.globals.debuggers[botId].state = 1;
|
||||||
GBServer.globals.debuggers[botId].stateInfo = 'Running (Debug)';
|
GBServer.globals.debuggers[botId].stateInfo = 'Running (Debug)';
|
||||||
|
|
||||||
|
|
|
@ -144,7 +144,7 @@ export class DialogKeywords {
|
||||||
|
|
||||||
const url = urlJoin(GBServer.globals.publicAddress, min.botId, 'cache', Path.basename(localName));
|
const url = urlJoin(GBServer.globals.publicAddress, min.botId, 'cache', Path.basename(localName));
|
||||||
|
|
||||||
GBLogEx.info(min, `BASIC: Visualization: Chart generated at ${url}.`);
|
GBLogEx.info(min, `Visualization: Chart generated at ${url}.`);
|
||||||
|
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
@ -155,7 +155,7 @@ export class DialogKeywords {
|
||||||
*/
|
*/
|
||||||
public async getOCR({ pid, localFile }) {
|
public async getOCR({ pid, localFile }) {
|
||||||
const { min, user } = await DialogKeywords.getProcessInfo(pid);
|
const { min, user } = await DialogKeywords.getProcessInfo(pid);
|
||||||
GBLogEx.info(min, `BASIC: OCR processing on ${localFile}.`);
|
GBLogEx.info(min, `OCR processing on ${localFile}.`);
|
||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
lang: 'eng',
|
lang: 'eng',
|
||||||
|
@ -593,7 +593,7 @@ export class DialogKeywords {
|
||||||
*/
|
*/
|
||||||
public async sendFileTo({ pid, mobile, filename, caption }) {
|
public async sendFileTo({ pid, mobile, filename, caption }) {
|
||||||
const { min, user, proc } = await DialogKeywords.getProcessInfo(pid);
|
const { min, user, proc } = await DialogKeywords.getProcessInfo(pid);
|
||||||
GBLogEx.info(min, `BASIC: SEND FILE TO '${mobile}',filename '${filename}'.`);
|
GBLogEx.info(min, `SEND FILE TO '${mobile}',filename '${filename}'.`);
|
||||||
return await this.internalSendFile({ pid, mobile, channel: proc.channel, filename, caption });
|
return await this.internalSendFile({ pid, mobile, channel: proc.channel, filename, caption });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -605,7 +605,7 @@ export class DialogKeywords {
|
||||||
*/
|
*/
|
||||||
public async sendTemplateTo({ pid, mobile, filename }) {
|
public async sendTemplateTo({ pid, mobile, filename }) {
|
||||||
const { min, user, proc } = await DialogKeywords.getProcessInfo(pid);
|
const { min, user, proc } = await DialogKeywords.getProcessInfo(pid);
|
||||||
GBLogEx.info(min, `BASIC: SEND TEMPLATE TO '${mobile}',filename '${filename}'.`);
|
GBLogEx.info(min, `SEND TEMPLATE TO '${mobile}',filename '${filename}'.`);
|
||||||
const service = new GBConversationalService(min.core);
|
const service = new GBConversationalService(min.core);
|
||||||
|
|
||||||
let text;
|
let text;
|
||||||
|
@ -626,7 +626,7 @@ export class DialogKeywords {
|
||||||
*/
|
*/
|
||||||
public async sendFile({ pid, filename, caption }) {
|
public async sendFile({ pid, filename, caption }) {
|
||||||
const { min, user, proc } = await DialogKeywords.getProcessInfo(pid);
|
const { min, user, proc } = await DialogKeywords.getProcessInfo(pid);
|
||||||
GBLogEx.info(min, `BASIC: SEND FILE (to: ${user.userSystemId},filename '${filename}'.`);
|
GBLogEx.info(min, `SEND FILE (to: ${user.userSystemId},filename '${filename}'.`);
|
||||||
const mobile = await this.userMobile({ pid });
|
const mobile = await this.userMobile({ pid });
|
||||||
return await this.internalSendFile({ pid, channel: proc.channel, mobile, filename, caption });
|
return await this.internalSendFile({ pid, channel: proc.channel, mobile, filename, caption });
|
||||||
}
|
}
|
||||||
|
@ -708,7 +708,7 @@ export class DialogKeywords {
|
||||||
// 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.`);
|
||||||
// }
|
// }
|
||||||
let { min, user, params } = await DialogKeywords.getProcessInfo(pid);
|
let { min, user, params } = await DialogKeywords.getProcessInfo(pid);
|
||||||
GBLogEx.info(min, `BASIC: ${name} = ${value} (botId: ${min.botId})`);
|
GBLogEx.info(min, `${name} = ${value} (botId: ${min.botId})`);
|
||||||
const sec = new SecService();
|
const sec = new SecService();
|
||||||
if (user) {
|
if (user) {
|
||||||
await sec.setParam(user.userId, name, value);
|
await sec.setParam(user.userId, name, value);
|
||||||
|
@ -969,9 +969,9 @@ export class DialogKeywords {
|
||||||
await this.talk({ pid: pid, text: button });
|
await this.talk({ pid: pid, text: button });
|
||||||
}
|
}
|
||||||
|
|
||||||
GBLogEx.info(min, `BASIC: HEAR with [${args.toString()}] (Asking for input).`);
|
GBLogEx.info(min, `HEAR with [${args.toString()}] (Asking for input).`);
|
||||||
} else {
|
} else {
|
||||||
GBLogEx.info(min, 'BASIC: HEAR (Asking for input).');
|
GBLogEx.info(min, 'HEAR (Asking for input).');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait for the user to answer.
|
// Wait for the user to answer.
|
||||||
|
@ -1377,7 +1377,7 @@ export class DialogKeywords {
|
||||||
*/
|
*/
|
||||||
public async talk({ pid, text }) {
|
public async talk({ pid, text }) {
|
||||||
const { min, user, step } = await DialogKeywords.getProcessInfo(pid);
|
const { min, user, step } = await DialogKeywords.getProcessInfo(pid);
|
||||||
GBLogEx.info(min, `BASIC: TALK '${text} step:${step}'.`);
|
GBLogEx.info(min, `TALK '${text} step:${step}'.`);
|
||||||
|
|
||||||
if (user) {
|
if (user) {
|
||||||
// TODO: const translate = user ? user.basicOptions.translatorOn : false;
|
// TODO: const translate = user ? user.basicOptions.translatorOn : false;
|
||||||
|
@ -1423,7 +1423,7 @@ export class DialogKeywords {
|
||||||
|
|
||||||
url = urlJoin(GBServer.globals.publicAddress, min.botId, 'cache', Path.basename(localName));
|
url = urlJoin(GBServer.globals.publicAddress, min.botId, 'cache', Path.basename(localName));
|
||||||
|
|
||||||
GBLogEx.info(min, `BASIC: WebAutomation: Sending ${url} to ${mobile} (${channel}).`);
|
GBLogEx.info(min, `WebAutomation: Sending ${url} to ${mobile} (${channel}).`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// GBFILE object.
|
// GBFILE object.
|
||||||
|
@ -1431,15 +1431,15 @@ export class DialogKeywords {
|
||||||
url = filename.url;
|
url = filename.url;
|
||||||
nameOnly = Path.basename(filename.localName);
|
nameOnly = Path.basename(filename.localName);
|
||||||
|
|
||||||
GBLogEx.info(min, `BASIC: Sending the GBFILE ${url} to ${mobile} (${channel}).`);
|
GBLogEx.info(min, `Sending the GBFILE ${url} to ${mobile} (${channel}).`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handles Markdown.
|
// Handles Markdown.
|
||||||
else if (filename.indexOf('.md') !== -1) {
|
else if (filename.indexOf('.md') !== -1) {
|
||||||
GBLogEx.info(min, `BASIC: Sending the contents of ${filename} markdown to mobile ${mobile}.`);
|
GBLogEx.info(min, `Sending the contents of ${filename} markdown to mobile ${mobile}.`);
|
||||||
const md = await min.kbService.getAnswerTextByMediaName(min.instance.instanceId, filename);
|
const md = await min.kbService.getAnswerTextByMediaName(min.instance.instanceId, filename);
|
||||||
if (!md) {
|
if (!md) {
|
||||||
GBLogEx.info(min, `BASIC: Markdown file ${filename} not found on database for ${min.instance.botId}.`);
|
GBLogEx.info(min, `Markdown file ${filename} not found on database for ${min.instance.botId}.`);
|
||||||
}
|
}
|
||||||
await min.conversationalService['playMarkdown'](min, md, DialogKeywords.getChannel(), null, mobile);
|
await min.conversationalService['playMarkdown'](min, md, DialogKeywords.getChannel(), null, mobile);
|
||||||
|
|
||||||
|
@ -1453,7 +1453,7 @@ export class DialogKeywords {
|
||||||
|
|
||||||
let { baseUrl, client } = await GBDeployer.internalGetDriveClient(min);
|
let { baseUrl, client } = await GBDeployer.internalGetDriveClient(min);
|
||||||
const fileUrl = urlJoin('/', gbaiName, `${min.botId}.gbdrive`, filename);
|
const fileUrl = urlJoin('/', gbaiName, `${min.botId}.gbdrive`, filename);
|
||||||
GBLogEx.info(min, `BASIC: Direct send from .gbdrive: ${fileUrl} to ${mobile}.`);
|
GBLogEx.info(min, `Direct send from .gbdrive: ${fileUrl} to ${mobile}.`);
|
||||||
|
|
||||||
const sys = new SystemKeywords();
|
const sys = new SystemKeywords();
|
||||||
|
|
||||||
|
|
|
@ -215,7 +215,7 @@ export class GBVMService extends GBService {
|
||||||
}`;
|
}`;
|
||||||
Fs.writeFileSync(urlJoin(folder, 'package.json'), packageJson);
|
Fs.writeFileSync(urlJoin(folder, 'package.json'), packageJson);
|
||||||
|
|
||||||
GBLogEx.info(min, `BASIC: Installing .gbdialog node_modules for ${min.botId}...`);
|
GBLogEx.info(min, `Installing .gbdialog node_modules for ${min.botId}...`);
|
||||||
const npmPath = urlJoin(process.env.PWD, 'node_modules', '.bin', 'npm');
|
const npmPath = urlJoin(process.env.PWD, 'node_modules', '.bin', 'npm');
|
||||||
child_process.execSync(`${npmPath} install`, { cwd: folder });
|
child_process.execSync(`${npmPath} install`, { cwd: folder });
|
||||||
}
|
}
|
||||||
|
@ -431,7 +431,7 @@ export class GBVMService extends GBService {
|
||||||
to.hasMany(from);
|
to.hasMany(from);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`BASIC: Invalid relationship in ${mainName}: from ${e.from} to ${e.to} (${min.botId})... ${error.message}`
|
`Invalid relationship in ${mainName}: from ${e.from} to ${e.to} (${min.botId})... ${error.message}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -439,14 +439,14 @@ export class GBVMService extends GBService {
|
||||||
if (sync && shouldSync) {
|
if (sync && shouldSync) {
|
||||||
GBLogEx.info(
|
GBLogEx.info(
|
||||||
min,
|
min,
|
||||||
`BASIC: Syncing changes for TABLE ${connectionName} ${tableName} keyword (${min.botId})...`
|
`Syncing changes for TABLE ${connectionName} ${tableName} keyword (${min.botId})...`
|
||||||
);
|
);
|
||||||
|
|
||||||
await seq.sync({
|
await seq.sync({
|
||||||
alter: true,
|
alter: true,
|
||||||
force: false // Keep it false due to data loss danger.
|
force: false // Keep it false due to data loss danger.
|
||||||
});
|
});
|
||||||
GBLogEx.info(min, `BASIC: Done sync for ${min.botId} ${connectionName} ${tableName} storage table...`);
|
GBLogEx.info(min, `Done sync for ${min.botId} ${connectionName} ${tableName} storage table...`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -51,7 +51,7 @@ export class ImageProcessingServices {
|
||||||
*/
|
*/
|
||||||
public async sharpen({ pid, file: file }) {
|
public async sharpen({ pid, file: file }) {
|
||||||
const { min, user } = await DialogKeywords.getProcessInfo(pid);
|
const { min, user } = await DialogKeywords.getProcessInfo(pid);
|
||||||
GBLogEx.info(min, `BASIC: Image Processing SHARPEN ${file}.`);
|
GBLogEx.info(min, `Image Processing SHARPEN ${file}.`);
|
||||||
|
|
||||||
const gbfile = DialogKeywords.getFileByHandle(file);
|
const gbfile = DialogKeywords.getFileByHandle(file);
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@ export class ImageProcessingServices {
|
||||||
*/
|
*/
|
||||||
public async blur({ pid, file: file }) {
|
public async blur({ pid, file: file }) {
|
||||||
const { min, user } = await DialogKeywords.getProcessInfo(pid);
|
const { min, user } = await DialogKeywords.getProcessInfo(pid);
|
||||||
GBLogEx.info(min, `BASIC: Image Processing SHARPEN ${file}.`);
|
GBLogEx.info(min, `Image Processing SHARPEN ${file}.`);
|
||||||
|
|
||||||
const gbfile = DialogKeywords.getFileByHandle(file);
|
const gbfile = DialogKeywords.getFileByHandle(file);
|
||||||
const data = await sharp(gbfile.data)
|
const data = await sharp(gbfile.data)
|
||||||
|
|
|
@ -66,7 +66,7 @@ export class ScheduleServices extends GBService {
|
||||||
});
|
});
|
||||||
|
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
GBLogEx.info(min, `BASIC: Removed ${name} SET SCHEDULE and ${count} rows from storage on: ${min.botId}...`);
|
GBLogEx.info(min, `Removed ${name} SET SCHEDULE and ${count} rows from storage on: ${min.botId}...`);
|
||||||
}
|
}
|
||||||
|
|
||||||
i++;
|
i++;
|
||||||
|
|
|
@ -322,7 +322,7 @@ export class SystemKeywords {
|
||||||
localName = Path.join('work', gbaiName, 'cache', `img${GBAdminService.getRndReadableIdentifier()}.png`);
|
localName = Path.join('work', gbaiName, 'cache', `img${GBAdminService.getRndReadableIdentifier()}.png`);
|
||||||
await page.screenshot({ path: localName, fullPage: true });
|
await page.screenshot({ path: localName, fullPage: true });
|
||||||
url = urlJoin(GBServer.globals.publicAddress, min.botId, 'cache', Path.basename(localName));
|
url = urlJoin(GBServer.globals.publicAddress, min.botId, 'cache', Path.basename(localName));
|
||||||
GBLogEx.info(min, `BASIC: Table image generated at ${url} .`);
|
GBLogEx.info(min, `Table image generated at ${url} .`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handles PDF generation.
|
// Handles PDF generation.
|
||||||
|
@ -331,7 +331,7 @@ export class SystemKeywords {
|
||||||
localName = Path.join('work', gbaiName, 'cache', `img${GBAdminService.getRndReadableIdentifier()}.pdf`);
|
localName = Path.join('work', gbaiName, 'cache', `img${GBAdminService.getRndReadableIdentifier()}.pdf`);
|
||||||
url = urlJoin(GBServer.globals.publicAddress, min.botId, 'cache', Path.basename(localName));
|
url = urlJoin(GBServer.globals.publicAddress, min.botId, 'cache', Path.basename(localName));
|
||||||
let pdf = await page.pdf({ format: 'A4' });
|
let pdf = await page.pdf({ format: 'A4' });
|
||||||
GBLogEx.info(min, `BASIC: Table PDF generated at ${url} .`);
|
GBLogEx.info(min, `Table PDF generated at ${url} .`);
|
||||||
}
|
}
|
||||||
|
|
||||||
await browser.close();
|
await browser.close();
|
||||||
|
@ -469,7 +469,7 @@ export class SystemKeywords {
|
||||||
public async wait({ pid, seconds }) {
|
public async wait({ pid, seconds }) {
|
||||||
const { min, user } = await DialogKeywords.getProcessInfo(pid);
|
const { min, user } = await DialogKeywords.getProcessInfo(pid);
|
||||||
// tslint:disable-next-line no-string-based-set-timeout
|
// tslint:disable-next-line no-string-based-set-timeout
|
||||||
GBLogEx.info(min, `BASIC: WAIT for ${seconds} second(s).`);
|
GBLogEx.info(min, `WAIT for ${seconds} second(s).`);
|
||||||
const timeout = async (ms: number) => new Promise(resolve => setTimeout(resolve, ms));
|
const timeout = async (ms: number) => new Promise(resolve => setTimeout(resolve, ms));
|
||||||
await timeout(seconds * 1000);
|
await timeout(seconds * 1000);
|
||||||
}
|
}
|
||||||
|
@ -482,7 +482,7 @@ export class SystemKeywords {
|
||||||
*/
|
*/
|
||||||
public async talkTo({ pid, mobile, message }) {
|
public async talkTo({ pid, mobile, message }) {
|
||||||
const { min, user } = await DialogKeywords.getProcessInfo(pid);
|
const { min, user } = await DialogKeywords.getProcessInfo(pid);
|
||||||
GBLogEx.info(min, `BASIC: Talking '${message}' to a specific user (${mobile}) (TALK TO). `);
|
GBLogEx.info(min, `Talking '${message}' to a specific user (${mobile}) (TALK TO). `);
|
||||||
await min.conversationalService.sendMarkdownToMobile(min, null, mobile, message);
|
await min.conversationalService.sendMarkdownToMobile(min, null, mobile, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -508,7 +508,7 @@ export class SystemKeywords {
|
||||||
*/
|
*/
|
||||||
public async sendSmsTo({ pid, mobile, message }) {
|
public async sendSmsTo({ pid, mobile, message }) {
|
||||||
const { min, user } = await DialogKeywords.getProcessInfo(pid);
|
const { min, user } = await DialogKeywords.getProcessInfo(pid);
|
||||||
GBLogEx.info(min, `BASIC: SEND SMS TO '${mobile}', message '${message}'.`);
|
GBLogEx.info(min, `SEND SMS TO '${mobile}', message '${message}'.`);
|
||||||
await min.conversationalService.sendSms(min, mobile, message);
|
await min.conversationalService.sendSms(min, mobile, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -527,7 +527,7 @@ export class SystemKeywords {
|
||||||
// Handles calls for HTML stuff
|
// Handles calls for HTML stuff
|
||||||
|
|
||||||
if (handle && WebAutomationServices.isSelector(file)) {
|
if (handle && WebAutomationServices.isSelector(file)) {
|
||||||
GBLogEx.info(min, `BASIC: Web automation SET ${file}' to '${address}' . `);
|
GBLogEx.info(min, `Web automation SET ${file}' to '${address}' . `);
|
||||||
await new WebAutomationServices().setElementText({ pid, handle, selector: file, text: address });
|
await new WebAutomationServices().setElementText({ pid, handle, selector: file, text: address });
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
@ -545,7 +545,7 @@ export class SystemKeywords {
|
||||||
|
|
||||||
// Handles calls for BASIC persistence on sheet files.
|
// Handles calls for BASIC persistence on sheet files.
|
||||||
|
|
||||||
GBLogEx.info(min, `BASIC: Defining '${address}' in '${file}' to '${value}' (SET). `);
|
GBLogEx.info(min, `Defining '${address}' in '${file}' to '${value}' (SET). `);
|
||||||
|
|
||||||
let { baseUrl, client } = await GBDeployer.internalGetDriveClient(min);
|
let { baseUrl, client } = await GBDeployer.internalGetDriveClient(min);
|
||||||
|
|
||||||
|
@ -632,7 +632,7 @@ export class SystemKeywords {
|
||||||
*/
|
*/
|
||||||
public async saveFile({ pid, file, data }): Promise<any> {
|
public async saveFile({ pid, file, data }): Promise<any> {
|
||||||
const { min, user } = await DialogKeywords.getProcessInfo(pid);
|
const { min, user } = await DialogKeywords.getProcessInfo(pid);
|
||||||
GBLogEx.info(min, `BASIC: Saving '${file}' (SAVE file).`);
|
GBLogEx.info(min, `Saving '${file}' (SAVE file).`);
|
||||||
let { baseUrl, client } = await GBDeployer.internalGetDriveClient(min);
|
let { baseUrl, client } = await GBDeployer.internalGetDriveClient(min);
|
||||||
const botId = min.instance.botId;
|
const botId = min.instance.botId;
|
||||||
const path = DialogKeywords.getGBAIPath(min.botId, `gbdrive`);
|
const path = DialogKeywords.getGBAIPath(min.botId, `gbdrive`);
|
||||||
|
@ -648,9 +648,9 @@ export class SystemKeywords {
|
||||||
await client.api(`${baseUrl}/drive/root:/${path}/${file}:/content`).put(data);
|
await client.api(`${baseUrl}/drive/root:/${path}/${file}:/content`).put(data);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error.code === 'itemNotFound') {
|
if (error.code === 'itemNotFound') {
|
||||||
GBLogEx.info(min, `BASIC: BASIC source file not found: ${file}.`);
|
GBLogEx.info(min, `BASIC source file not found: ${file}.`);
|
||||||
} else if (error.code === 'nameAlreadyExists') {
|
} else if (error.code === 'nameAlreadyExists') {
|
||||||
GBLogEx.info(min, `BASIC: BASIC destination file already exists: ${file}.`);
|
GBLogEx.info(min, `BASIC destination file already exists: ${file}.`);
|
||||||
}
|
}
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
@ -666,7 +666,7 @@ export class SystemKeywords {
|
||||||
*/
|
*/
|
||||||
public async uploadFile({ pid, file }): Promise<any> {
|
public async uploadFile({ pid, file }): Promise<any> {
|
||||||
const { min, user } = await DialogKeywords.getProcessInfo(pid);
|
const { min, user } = await DialogKeywords.getProcessInfo(pid);
|
||||||
GBLogEx.info(min, `BASIC: UPLOAD '${file.name}' ${file.size} bytes.`);
|
GBLogEx.info(min, `UPLOAD '${file.name}' ${file.size} bytes.`);
|
||||||
|
|
||||||
// Checks if it is a GB FILE object.
|
// Checks if it is a GB FILE object.
|
||||||
|
|
||||||
|
@ -710,7 +710,7 @@ export class SystemKeywords {
|
||||||
|
|
||||||
return file;
|
return file;
|
||||||
} else {
|
} else {
|
||||||
GBLog.error(`BASIC: BLOB HTTP ${res.errorCode} ${res._response.status} .`);
|
GBLog.error(`BLOB HTTP ${res.errorCode} ${res._response.status} .`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -730,17 +730,17 @@ export class SystemKeywords {
|
||||||
*/
|
*/
|
||||||
public async saveToStorageBatch({ pid, table, rows }): Promise<void> {
|
public async saveToStorageBatch({ pid, table, rows }): Promise<void> {
|
||||||
const { min } = await DialogKeywords.getProcessInfo(pid);
|
const { min } = await DialogKeywords.getProcessInfo(pid);
|
||||||
GBLogEx.info(min, `BASIC: Saving batch to storage '${table}' (SAVE).`);
|
GBLogEx.info(min, `SAVE '${table}' ${rows.length} row(s).`);
|
||||||
|
|
||||||
if (rows.length === 0) {
|
if (rows.length === 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const definition = this.getTableFromName(table, min);
|
const definition = this.getTableFromName(table, min);
|
||||||
const rowsDest = [];
|
let rowsDest = [];
|
||||||
|
|
||||||
rows.forEach(row => {
|
rows.forEach(row => {
|
||||||
const dst = {};
|
let dst = {};
|
||||||
let i = 0;
|
let i = 0;
|
||||||
Object.keys(row).forEach(column => {
|
Object.keys(row).forEach(column => {
|
||||||
const field = column.charAt(0).toUpperCase() + column.slice(1);
|
const field = column.charAt(0).toUpperCase() + column.slice(1);
|
||||||
|
@ -748,16 +748,18 @@ export class SystemKeywords {
|
||||||
i++;
|
i++;
|
||||||
});
|
});
|
||||||
rowsDest.push(dst);
|
rowsDest.push(dst);
|
||||||
|
dst = null;
|
||||||
});
|
});
|
||||||
|
|
||||||
await retry(
|
await retry(
|
||||||
async bail => {
|
async bail => {
|
||||||
await definition.bulkCreate(GBUtil.caseInsensitive(rowsDest));
|
await definition.bulkCreate(GBUtil.caseInsensitive(rowsDest));
|
||||||
|
rowsDest = [];
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
retries: 5,
|
retries: 5,
|
||||||
onRetry: err => {
|
onRetry: err => {
|
||||||
GBLog.error(`Retrying SaveToStorageBatch due to: ${JSON.stringify(err)}.`);
|
GBLog.error(`SAVE (retry): ${GBUtil.toYAML(err)}.`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -775,7 +777,7 @@ export class SystemKeywords {
|
||||||
}
|
}
|
||||||
|
|
||||||
const { min } = await DialogKeywords.getProcessInfo(pid);
|
const { min } = await DialogKeywords.getProcessInfo(pid);
|
||||||
GBLogEx.info(min, `BASIC: Saving to storage '${table}' (SAVE).`);
|
GBLogEx.info(min, `Saving to storage '${table}' (SAVE).`);
|
||||||
|
|
||||||
const definition = this.getTableFromName(table, min);
|
const definition = this.getTableFromName(table, min);
|
||||||
|
|
||||||
|
@ -807,7 +809,7 @@ export class SystemKeywords {
|
||||||
|
|
||||||
public async saveToStorageWithJSON({ pid, table, fieldsValues, fieldsNames }): Promise<any> {
|
public async saveToStorageWithJSON({ pid, table, fieldsValues, fieldsNames }): Promise<any> {
|
||||||
const { min, user } = await DialogKeywords.getProcessInfo(pid);
|
const { min, user } = await DialogKeywords.getProcessInfo(pid);
|
||||||
GBLogEx.info(min, `BASIC: Saving to storage '${table}' (SAVE).`);
|
GBLogEx.info(min, `Saving to storage '${table}' (SAVE).`);
|
||||||
const minBoot = GBServer.globals.minBoot as any;
|
const minBoot = GBServer.globals.minBoot as any;
|
||||||
const definition = minBoot.core.sequelize.models[table];
|
const definition = minBoot.core.sequelize.models[table];
|
||||||
|
|
||||||
|
@ -841,7 +843,7 @@ export class SystemKeywords {
|
||||||
}
|
}
|
||||||
|
|
||||||
const { min } = await DialogKeywords.getProcessInfo(pid);
|
const { min } = await DialogKeywords.getProcessInfo(pid);
|
||||||
GBLogEx.info(min, `BASIC: Saving '${file}' (SAVE). Args: ${args.join(',')}.`);
|
GBLogEx.info(min, `Saving '${file}' (SAVE). Args: ${args.join(',')}.`);
|
||||||
let { baseUrl, client } = await GBDeployer.internalGetDriveClient(min);
|
let { baseUrl, client } = await GBDeployer.internalGetDriveClient(min);
|
||||||
const botId = min.instance.botId;
|
const botId = min.instance.botId;
|
||||||
const path = DialogKeywords.getGBAIPath(botId, 'gbdata');
|
const path = DialogKeywords.getGBAIPath(botId, 'gbdata');
|
||||||
|
@ -929,7 +931,7 @@ export class SystemKeywords {
|
||||||
if (result.status != 200) {
|
if (result.status != 200) {
|
||||||
GBLogEx.info(min, `Waiting 5 secs. before retrying HTTP ${result.status} GET: ${result.url}`);
|
GBLogEx.info(min, `Waiting 5 secs. before retrying HTTP ${result.status} GET: ${result.url}`);
|
||||||
await GBUtil.sleep(5 * 1000);
|
await GBUtil.sleep(5 * 1000);
|
||||||
throw new Error(`BASIC: HTTP:${result.status} retry: ${result.statusText}.`);
|
throw new Error(`HTTP:${result.status} retry: ${result.statusText}.`);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -959,7 +961,7 @@ export class SystemKeywords {
|
||||||
qs
|
qs
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
GBLogEx.info(min, `BASIC: GET '${addressOrHeaders}' in '${file}'.`);
|
GBLogEx.info(min, `GET '${addressOrHeaders}' in '${file}'.`);
|
||||||
let { baseUrl, client } = await GBDeployer.internalGetDriveClient(min);
|
let { baseUrl, client } = await GBDeployer.internalGetDriveClient(min);
|
||||||
const botId = min.instance.botId;
|
const botId = min.instance.botId;
|
||||||
('');
|
('');
|
||||||
|
@ -978,7 +980,7 @@ export class SystemKeywords {
|
||||||
.get();
|
.get();
|
||||||
|
|
||||||
let val = results.text[0][0];
|
let val = results.text[0][0];
|
||||||
GBLogEx.info(min, `BASIC: Getting '${file}' (GET). Value= ${val}.`);
|
GBLogEx.info(min, `Getting '${file}' (GET). Value= ${val}.`);
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1073,7 +1075,7 @@ export class SystemKeywords {
|
||||||
} else {
|
} else {
|
||||||
maxLines = maxLines;
|
maxLines = maxLines;
|
||||||
}
|
}
|
||||||
GBLogEx.info(min, `BASIC: FIND running on ${file} (maxLines: ${maxLines}) and args: ${JSON.stringify(args)}...`);
|
GBLogEx.info(min, `FIND running on ${file} (maxLines: ${maxLines}) and args: ${JSON.stringify(args)}...`);
|
||||||
|
|
||||||
// Choose data sources based on file type (HTML Table, data variable or sheet file)
|
// Choose data sources based on file type (HTML Table, data variable or sheet file)
|
||||||
|
|
||||||
|
@ -1090,7 +1092,7 @@ export class SystemKeywords {
|
||||||
|
|
||||||
// Transforms table
|
// Transforms table
|
||||||
|
|
||||||
const resultH = await container.evaluate(originalSelector => {
|
let resultH = await container.evaluate(originalSelector => {
|
||||||
const rows = document.querySelectorAll(`${originalSelector} tr`);
|
const rows = document.querySelectorAll(`${originalSelector} tr`);
|
||||||
return Array.from(rows, row => {
|
return Array.from(rows, row => {
|
||||||
const columns = row.querySelectorAll('th');
|
const columns = row.querySelectorAll('th');
|
||||||
|
@ -1098,7 +1100,7 @@ export class SystemKeywords {
|
||||||
});
|
});
|
||||||
}, originalSelector);
|
}, originalSelector);
|
||||||
|
|
||||||
const result = await container.evaluate(originalSelector => {
|
let result = await container.evaluate(originalSelector => {
|
||||||
const rows = document.querySelectorAll(`${originalSelector} tr`);
|
const rows = document.querySelectorAll(`${originalSelector} tr`);
|
||||||
return Array.from(rows, row => {
|
return Array.from(rows, row => {
|
||||||
const columns = row.querySelectorAll('td');
|
const columns = row.querySelectorAll('td');
|
||||||
|
@ -1110,12 +1112,15 @@ export class SystemKeywords {
|
||||||
for (let i = 0; i < resultH[0].length; i++) {
|
for (let i = 0; i < resultH[0].length; i++) {
|
||||||
header[i] = resultH[0][i];
|
header[i] = resultH[0][i];
|
||||||
}
|
}
|
||||||
|
resultH = null;
|
||||||
|
|
||||||
|
|
||||||
rows = [];
|
rows = [];
|
||||||
rows[0] = header;
|
rows[0] = header;
|
||||||
for (let i = 1; i < result.length; i++) {
|
for (let i = 1; i < result.length; i++) {
|
||||||
rows[i] = result[i];
|
rows[i] = result[i];
|
||||||
}
|
}
|
||||||
|
result = null;
|
||||||
} else if (file['cTag']) {
|
} else if (file['cTag']) {
|
||||||
const gbaiName = DialogKeywords.getGBAIPath(min.botId);
|
const gbaiName = DialogKeywords.getGBAIPath(min.botId);
|
||||||
const localName = Path.join('work', gbaiName, 'cache', `csv${GBAdminService.getRndReadableIdentifier()}.csv`);
|
const localName = Path.join('work', gbaiName, 'cache', `csv${GBAdminService.getRndReadableIdentifier()}.csv`);
|
||||||
|
@ -1124,7 +1129,7 @@ export class SystemKeywords {
|
||||||
Fs.writeFileSync(localName, Buffer.from(await response.arrayBuffer()), { encoding: null });
|
Fs.writeFileSync(localName, Buffer.from(await response.arrayBuffer()), { encoding: null });
|
||||||
|
|
||||||
var workbook = new Excel.Workbook();
|
var workbook = new Excel.Workbook();
|
||||||
const worksheet = await workbook.csv.readFile(localName);
|
let worksheet = await workbook.csv.readFile(localName);
|
||||||
header = [];
|
header = [];
|
||||||
rows = [];
|
rows = [];
|
||||||
|
|
||||||
|
@ -1146,6 +1151,7 @@ export class SystemKeywords {
|
||||||
rows.push(outRow);
|
rows.push(outRow);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
worksheet = null;
|
||||||
} else if (file.indexOf('.xlsx') !== -1) {
|
} else if (file.indexOf('.xlsx') !== -1) {
|
||||||
let { baseUrl, client } = await GBDeployer.internalGetDriveClient(min);
|
let { baseUrl, client } = await GBDeployer.internalGetDriveClient(min);
|
||||||
|
|
||||||
|
@ -1191,7 +1197,7 @@ export class SystemKeywords {
|
||||||
|
|
||||||
// Increments columnIndex by looping until find a column match.
|
// Increments columnIndex by looping until find a column match.
|
||||||
|
|
||||||
const filters = [];
|
let filters = [];
|
||||||
let predefinedFilterTypes;
|
let predefinedFilterTypes;
|
||||||
if (params.filterTypes) {
|
if (params.filterTypes) {
|
||||||
predefinedFilterTypes = params.filterTypes.split(',');
|
predefinedFilterTypes = params.filterTypes.split(',');
|
||||||
|
@ -1201,7 +1207,7 @@ export class SystemKeywords {
|
||||||
await CollectionUtil.asyncForEach(args, async arg => {
|
await CollectionUtil.asyncForEach(args, async arg => {
|
||||||
const filter = await SystemKeywords.getFilter(arg);
|
const filter = await SystemKeywords.getFilter(arg);
|
||||||
if (!filter) {
|
if (!filter) {
|
||||||
throw new Error(`BASIC: FIND filter has an error: ${arg} check this and publish .gbdialog again.`);
|
throw new Error(`FIND filter has an error: ${arg} check this and publish .gbdialog again.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
let columnIndex = 0;
|
let columnIndex = 0;
|
||||||
|
@ -1380,15 +1386,18 @@ export class SystemKeywords {
|
||||||
}
|
}
|
||||||
|
|
||||||
const outputArray = await DialogKeywords.getOption({ pid, name: 'output' });
|
const outputArray = await DialogKeywords.getOption({ pid, name: 'output' });
|
||||||
|
filters = null;
|
||||||
|
header = null;
|
||||||
|
rows = null;
|
||||||
|
|
||||||
if (table.length === 1) {
|
if (table.length === 1) {
|
||||||
GBLogEx.info(min, `BASIC: FIND returned no results (zero rows).`);
|
GBLogEx.info(min, `FIND returned no results (zero rows).`);
|
||||||
return null;
|
return null;
|
||||||
} else if (table.length === 2 && !outputArray) {
|
} else if (table.length === 2 && !outputArray) {
|
||||||
GBLogEx.info(min, `BASIC: FIND returned single result: ${table[0]}.`);
|
GBLogEx.info(min, `FIND returned single result: ${table[0]}.`);
|
||||||
return table[1];
|
return table[1];
|
||||||
} else {
|
} else {
|
||||||
GBLogEx.info(min, `BASIC: FIND returned multiple results (Count): ${table.length - 1}.`);
|
GBLogEx.info(min, `FIND returned multiple results (Count): ${table.length - 1}.`);
|
||||||
return table;
|
return table;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1547,7 +1556,7 @@ export class SystemKeywords {
|
||||||
}
|
}
|
||||||
|
|
||||||
public async internalCreateDocument(min, path, content) {
|
public async internalCreateDocument(min, path, content) {
|
||||||
GBLogEx.info(min, `BASIC: CREATE DOCUMENT '${path}...'`);
|
GBLogEx.info(min, `CREATE DOCUMENT '${path}...'`);
|
||||||
let { baseUrl, client } = await GBDeployer.internalGetDriveClient(min);
|
let { baseUrl, client } = await GBDeployer.internalGetDriveClient(min);
|
||||||
const gbaiName = DialogKeywords.getGBAIPath(min.botId);
|
const gbaiName = DialogKeywords.getGBAIPath(min.botId);
|
||||||
const tmpDocx = urlJoin(gbaiName, path);
|
const tmpDocx = urlJoin(gbaiName, path);
|
||||||
|
@ -1583,7 +1592,7 @@ export class SystemKeywords {
|
||||||
*/
|
*/
|
||||||
public async copyFile({ pid, src, dest }) {
|
public async copyFile({ pid, src, dest }) {
|
||||||
const { min, user, params } = await DialogKeywords.getProcessInfo(pid);
|
const { min, user, params } = await DialogKeywords.getProcessInfo(pid);
|
||||||
GBLogEx.info(min, `BASIC: BEGINING COPY '${src}' to '${dest}'`);
|
GBLogEx.info(min, `BEGINING COPY '${src}' to '${dest}'`);
|
||||||
let { baseUrl, client } = await GBDeployer.internalGetDriveClient(min);
|
let { baseUrl, client } = await GBDeployer.internalGetDriveClient(min);
|
||||||
const botId = min.instance.botId;
|
const botId = min.instance.botId;
|
||||||
|
|
||||||
|
@ -1619,13 +1628,13 @@ export class SystemKeywords {
|
||||||
name: `${Path.basename(dest)}`
|
name: `${Path.basename(dest)}`
|
||||||
};
|
};
|
||||||
const file = await client.api(`${baseUrl}/drive/items/${srcFile.id}/copy`).post(destFile);
|
const file = await client.api(`${baseUrl}/drive/items/${srcFile.id}/copy`).post(destFile);
|
||||||
GBLogEx.info(min, `BASIC: FINISHED COPY '${src}' to '${dest}'`);
|
GBLogEx.info(min, `FINISHED COPY '${src}' to '${dest}'`);
|
||||||
return file;
|
return file;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error.code === 'itemNotFound') {
|
if (error.code === 'itemNotFound') {
|
||||||
GBLogEx.info(min, `BASIC: COPY source file not found: ${srcPath}.`);
|
GBLogEx.info(min, `COPY source file not found: ${srcPath}.`);
|
||||||
} else if (error.code === 'nameAlreadyExists') {
|
} else if (error.code === 'nameAlreadyExists') {
|
||||||
GBLogEx.info(min, `BASIC: COPY destination file already exists: ${dstPath}.`);
|
GBLogEx.info(min, `COPY destination file already exists: ${dstPath}.`);
|
||||||
}
|
}
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
@ -1644,7 +1653,7 @@ export class SystemKeywords {
|
||||||
*/
|
*/
|
||||||
public async convert({ pid, src, dest }) {
|
public async convert({ pid, src, dest }) {
|
||||||
const { min, user, params } = await DialogKeywords.getProcessInfo(pid);
|
const { min, user, params } = await DialogKeywords.getProcessInfo(pid);
|
||||||
GBLogEx.info(min, `BASIC: CONVERT '${src}' to '${dest}'`);
|
GBLogEx.info(min, `CONVERT '${src}' to '${dest}'`);
|
||||||
let { baseUrl, client } = await GBDeployer.internalGetDriveClient(min);
|
let { baseUrl, client } = await GBDeployer.internalGetDriveClient(min);
|
||||||
const botId = min.instance.botId;
|
const botId = min.instance.botId;
|
||||||
|
|
||||||
|
@ -1690,9 +1699,9 @@ export class SystemKeywords {
|
||||||
await client.api(`${baseUrl}/drive/root:/${dstPath}:/content`).put(result);
|
await client.api(`${baseUrl}/drive/root:/${dstPath}:/content`).put(result);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error.code === 'itemNotFound') {
|
if (error.code === 'itemNotFound') {
|
||||||
GBLogEx.info(min, `BASIC: CONVERT source file not found: ${srcPath}.`);
|
GBLogEx.info(min, `CONVERT source file not found: ${srcPath}.`);
|
||||||
} else if (error.code === 'nameAlreadyExists') {
|
} else if (error.code === 'nameAlreadyExists') {
|
||||||
GBLogEx.info(min, `BASIC: CONVERT destination file already exists: ${dstPath}.`);
|
GBLogEx.info(min, `CONVERT destination file already exists: ${dstPath}.`);
|
||||||
}
|
}
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
@ -1789,17 +1798,17 @@ export class SystemKeywords {
|
||||||
if (result.status === 401) {
|
if (result.status === 401) {
|
||||||
GBLogEx.info(min, `Waiting 5 secs. before retrying HTTP 401 GET: ${url}`);
|
GBLogEx.info(min, `Waiting 5 secs. before retrying HTTP 401 GET: ${url}`);
|
||||||
await GBUtil.sleep(5 * 1000);
|
await GBUtil.sleep(5 * 1000);
|
||||||
throw new Error(`BASIC: HTTP:${result.status} retry: ${result.statusText}.`);
|
throw new Error(`HTTP:${result.status} retry: ${result.statusText}.`);
|
||||||
}
|
}
|
||||||
if (result.status === 429) {
|
if (result.status === 429) {
|
||||||
GBLogEx.info(min, `Waiting 1min. before retrying HTTP 429 GET: ${url}`);
|
GBLogEx.info(min, `Waiting 1min. before retrying HTTP 429 GET: ${url}`);
|
||||||
await GBUtil.sleep(60 * 1000);
|
await GBUtil.sleep(60 * 1000);
|
||||||
throw new Error(`BASIC: HTTP:${result.status} retry: ${result.statusText}.`);
|
throw new Error(`HTTP:${result.status} retry: ${result.statusText}.`);
|
||||||
}
|
}
|
||||||
if (result.status === 503) {
|
if (result.status === 503) {
|
||||||
GBLogEx.info(min, `Waiting 1h before retrying GET 503: ${url}`);
|
GBLogEx.info(min, `Waiting 1h before retrying GET 503: ${url}`);
|
||||||
await GBUtil.sleep(60 * 60 * 1000);
|
await GBUtil.sleep(60 * 60 * 1000);
|
||||||
throw new Error(`BASIC: HTTP:${result.status} retry: ${result.statusText}.`);
|
throw new Error(`HTTP:${result.status} retry: ${result.statusText}.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result.status === 2000) {
|
if (result.status === 2000) {
|
||||||
|
@ -1809,7 +1818,7 @@ export class SystemKeywords {
|
||||||
bail(new Error(`Expired Token for ${url}.`));
|
bail(new Error(`Expired Token for ${url}.`));
|
||||||
}
|
}
|
||||||
if (result.status != 200) {
|
if (result.status != 200) {
|
||||||
throw new Error(`BASIC: GET ${result.status}: ${result.statusText}.`);
|
throw new Error(`GET ${result.status}: ${result.statusText}.`);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -1852,7 +1861,7 @@ export class SystemKeywords {
|
||||||
if (res) {
|
if (res) {
|
||||||
res['pageMode'] = pageMode;
|
res['pageMode'] = pageMode;
|
||||||
}
|
}
|
||||||
|
result = null;
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1882,10 +1891,10 @@ export class SystemKeywords {
|
||||||
|
|
||||||
let result = await fetch(url, options);
|
let result = await fetch(url, options);
|
||||||
const text = await result.text();
|
const text = await result.text();
|
||||||
GBLogEx.info(min, `BASIC: PUT ${url} (${data}): ${text}`);
|
GBLogEx.info(min, `PUT ${url} (${data}): ${text}`);
|
||||||
|
|
||||||
if (result.status != 200 && result.status != 201) {
|
if (result.status != 200 && result.status != 201) {
|
||||||
throw new Error(`BASIC: PUT ${result.status}: ${result.statusText}.`);
|
throw new Error(`PUT ${result.status}: ${result.statusText}.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
let res = JSON.parse(text);
|
let res = JSON.parse(text);
|
||||||
|
@ -1917,10 +1926,10 @@ export class SystemKeywords {
|
||||||
|
|
||||||
let result = await fetch(url, options);
|
let result = await fetch(url, options);
|
||||||
const text = await result.text();
|
const text = await result.text();
|
||||||
GBLogEx.info(min, `BASIC: POST ${url} (${data}): ${text}`);
|
GBLogEx.info(min, `POST ${url} (${data}): ${text}`);
|
||||||
|
|
||||||
if (result.status != 200 && result.status != 201) {
|
if (result.status != 200 && result.status != 201) {
|
||||||
throw new Error(`BASIC: POST ${result.status}: ${result.statusText}.`);
|
throw new Error(`POST ${result.status}: ${result.statusText}.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
let res = JSON.parse(text);
|
let res = JSON.parse(text);
|
||||||
|
@ -2113,11 +2122,11 @@ export class SystemKeywords {
|
||||||
public async merge({ pid, file, data, key1, key2 }): Promise<any> {
|
public async merge({ pid, file, data, key1, key2 }): Promise<any> {
|
||||||
const { min, user, params } = await DialogKeywords.getProcessInfo(pid);
|
const { min, user, params } = await DialogKeywords.getProcessInfo(pid);
|
||||||
if (!data || data.length === 0) {
|
if (!data || data.length === 0) {
|
||||||
GBLog.verbose(`BASIC: MERGE running on ${file}: NO DATA.`);
|
GBLog.verbose(`MERGE running on ${file}: NO DATA.`);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
GBLogEx.info(min, `BASIC: MERGE running on ${file} and key1: ${key1}, key2: ${key2}...`);
|
GBLogEx.info(min, `MERGE running on ${file} and key1: ${key1}, key2: ${key2}...`);
|
||||||
if (!this.cachedMerge[pid]) {
|
if (!this.cachedMerge[pid]) {
|
||||||
this.cachedMerge[pid] = { file: {} };
|
this.cachedMerge[pid] = { file: {} };
|
||||||
}
|
}
|
||||||
|
@ -2185,7 +2194,7 @@ export class SystemKeywords {
|
||||||
page++;
|
page++;
|
||||||
count = paged.length;
|
count = paged.length;
|
||||||
|
|
||||||
GBLogEx.info(min, `BASIC: MERGE cached: ${rows.length} from page: ${page}.`);
|
GBLogEx.info(min, `MERGE cached: ${rows.length} from page: ${page}.`);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -2404,7 +2413,14 @@ export class SystemKeywords {
|
||||||
await this.saveToStorageBatch({ pid, table: file, rows: fieldsValuesList });
|
await this.saveToStorageBatch({ pid, table: file, rows: fieldsValuesList });
|
||||||
}
|
}
|
||||||
|
|
||||||
GBLogEx.info(min, `BASIC: MERGE results: adds:${adds}, updates:${updates} , skipped: ${skipped}.`);
|
table = null;
|
||||||
|
fieldsValuesList = null;
|
||||||
|
rows = null;
|
||||||
|
header = null;
|
||||||
|
results = null;
|
||||||
|
t = null;
|
||||||
|
|
||||||
|
GBLogEx.info(min, `MERGE results: adds:${adds}, updates:${updates} , skipped: ${skipped}.`);
|
||||||
return { title: file, adds, updates, skipped };
|
return { title: file, adds, updates, skipped };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2445,7 +2461,7 @@ export class SystemKeywords {
|
||||||
const { min, user } = await DialogKeywords.getProcessInfo(pid);
|
const { min, user } = await DialogKeywords.getProcessInfo(pid);
|
||||||
const prompt = `rewrite this sentence in a better way: ${text}`;
|
const prompt = `rewrite this sentence in a better way: ${text}`;
|
||||||
const answer = await ChatServices.continue(min, prompt, 0);
|
const answer = await ChatServices.continue(min, prompt, 0);
|
||||||
GBLogEx.info(min, `BASIC: REWRITE ${text} TO ${answer}`);
|
GBLogEx.info(min, `REWRITE ${text} TO ${answer}`);
|
||||||
return answer;
|
return answer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2532,7 +2548,7 @@ export class SystemKeywords {
|
||||||
|
|
||||||
private async internalAutoSave({ min, handle }) {
|
private async internalAutoSave({ min, handle }) {
|
||||||
const file = GBServer.globals.files[handle];
|
const file = GBServer.globals.files[handle];
|
||||||
GBLogEx.info(min, `BASIC: Auto saving '${file.filename}' (SAVE file).`);
|
GBLogEx.info(min, `Auto saving '${file.filename}' (SAVE file).`);
|
||||||
let { baseUrl, client } = await GBDeployer.internalGetDriveClient(min);
|
let { baseUrl, client } = await GBDeployer.internalGetDriveClient(min);
|
||||||
|
|
||||||
const path = DialogKeywords.getGBAIPath(min.botId, `gbdrive`);
|
const path = DialogKeywords.getGBAIPath(min.botId, `gbdrive`);
|
||||||
|
@ -2556,7 +2572,7 @@ export class SystemKeywords {
|
||||||
|
|
||||||
public async deleteFromStorage({ pid, table, criteria }) {
|
public async deleteFromStorage({ pid, table, criteria }) {
|
||||||
const { min } = await DialogKeywords.getProcessInfo(pid);
|
const { min } = await DialogKeywords.getProcessInfo(pid);
|
||||||
GBLogEx.info(min, `BASIC: DELETE (storage) '${table}' where ${criteria}.`);
|
GBLogEx.info(min, `DELETE '${table}' where ${criteria}.`);
|
||||||
|
|
||||||
const definition = this.getTableFromName(table, min);
|
const definition = this.getTableFromName(table, min);
|
||||||
const filter = await SystemKeywords.getFilter(criteria);
|
const filter = await SystemKeywords.getFilter(criteria);
|
||||||
|
@ -2580,7 +2596,7 @@ export class SystemKeywords {
|
||||||
|
|
||||||
public async deleteFile({ pid, file }) {
|
public async deleteFile({ pid, file }) {
|
||||||
const { min } = await DialogKeywords.getProcessInfo(pid);
|
const { min } = await DialogKeywords.getProcessInfo(pid);
|
||||||
GBLogEx.info(min, `BASIC: DELETE '${file.name}'.`);
|
GBLogEx.info(min, `DELETE '${file.name}'.`);
|
||||||
let { baseUrl, client } = await GBDeployer.internalGetDriveClient(min);
|
let { baseUrl, client } = await GBDeployer.internalGetDriveClient(min);
|
||||||
|
|
||||||
const gbaiPath = DialogKeywords.getGBAIPath(min.botId);
|
const gbaiPath = DialogKeywords.getGBAIPath(min.botId);
|
||||||
|
|
|
@ -93,7 +93,7 @@ export class WebAutomationServices {
|
||||||
|
|
||||||
public async openPage({ pid, handle, sessionKind, sessionName, url, username, password }) {
|
public async openPage({ pid, handle, sessionKind, sessionName, url, username, password }) {
|
||||||
const { min, user } = await DialogKeywords.getProcessInfo(pid);
|
const { min, user } = await DialogKeywords.getProcessInfo(pid);
|
||||||
GBLogEx.info(min, `BASIC: Web Automation OPEN ${sessionName ? sessionName : ''} ${url}.`);
|
GBLogEx.info(min, `Web Automation OPEN ${sessionName ? sessionName : ''} ${url}.`);
|
||||||
|
|
||||||
// Try to find an existing handle.
|
// Try to find an existing handle.
|
||||||
|
|
||||||
|
@ -192,7 +192,7 @@ export class WebAutomationServices {
|
||||||
public async getBySelector({ handle, selector, pid }) {
|
public async getBySelector({ handle, selector, pid }) {
|
||||||
const page = WebAutomationServices.getPageByHandle(handle);
|
const page = WebAutomationServices.getPageByHandle(handle);
|
||||||
const { min, user } = await DialogKeywords.getProcessInfo(pid);
|
const { min, user } = await DialogKeywords.getProcessInfo(pid);
|
||||||
GBLogEx.info(min, `BASIC: Web Automation GET element: ${selector}.`);
|
GBLogEx.info(min, `Web Automation GET element: ${selector}.`);
|
||||||
await page.waitForSelector(selector);
|
await page.waitForSelector(selector);
|
||||||
let elements = await page.$$(selector);
|
let elements = await page.$$(selector);
|
||||||
if (elements && elements.length > 1) {
|
if (elements && elements.length > 1) {
|
||||||
|
@ -217,7 +217,7 @@ export class WebAutomationServices {
|
||||||
const { min, user } = await DialogKeywords.getProcessInfo(pid);
|
const { min, user } = await DialogKeywords.getProcessInfo(pid);
|
||||||
|
|
||||||
const page = WebAutomationServices.getPageByHandle(handle);
|
const page = WebAutomationServices.getPageByHandle(handle);
|
||||||
GBLogEx.info(min, `BASIC: Web Automation GET element by frame: ${selector}.`);
|
GBLogEx.info(min, `Web Automation GET element by frame: ${selector}.`);
|
||||||
await page.waitForSelector(frame);
|
await page.waitForSelector(frame);
|
||||||
let frameHandle = await page.$(frame);
|
let frameHandle = await page.$(frame);
|
||||||
const f = await frameHandle.contentFrame();
|
const f = await frameHandle.contentFrame();
|
||||||
|
@ -239,7 +239,7 @@ export class WebAutomationServices {
|
||||||
const { min, user } = await DialogKeywords.getProcessInfo(pid);
|
const { min, user } = await DialogKeywords.getProcessInfo(pid);
|
||||||
|
|
||||||
const page = WebAutomationServices.getPageByHandle(handle);
|
const page = WebAutomationServices.getPageByHandle(handle);
|
||||||
GBLogEx.info(min, `BASIC: Web Automation HOVER element: ${selector}.`);
|
GBLogEx.info(min, `Web Automation HOVER element: ${selector}.`);
|
||||||
await this.getBySelector({ handle, selector: selector, pid });
|
await this.getBySelector({ handle, selector: selector, pid });
|
||||||
await page.hover(selector);
|
await page.hover(selector);
|
||||||
await this.debugStepWeb(pid, page);
|
await this.debugStepWeb(pid, page);
|
||||||
|
@ -254,7 +254,7 @@ export class WebAutomationServices {
|
||||||
const { min, user } = await DialogKeywords.getProcessInfo(pid);
|
const { min, user } = await DialogKeywords.getProcessInfo(pid);
|
||||||
|
|
||||||
const page = WebAutomationServices.getPageByHandle(handle);
|
const page = WebAutomationServices.getPageByHandle(handle);
|
||||||
GBLogEx.info(min, `BASIC: Web Automation CLICK element: ${frameOrSelector}.`);
|
GBLogEx.info(min, `Web Automation CLICK element: ${frameOrSelector}.`);
|
||||||
if (selector) {
|
if (selector) {
|
||||||
await page.waitForSelector(frameOrSelector);
|
await page.waitForSelector(frameOrSelector);
|
||||||
let frameHandle = await page.$(frameOrSelector);
|
let frameHandle = await page.$(frameOrSelector);
|
||||||
|
@ -297,7 +297,7 @@ export class WebAutomationServices {
|
||||||
const { min, user } = await DialogKeywords.getProcessInfo(pid);
|
const { min, user } = await DialogKeywords.getProcessInfo(pid);
|
||||||
|
|
||||||
const page = WebAutomationServices.getPageByHandle(handle);
|
const page = WebAutomationServices.getPageByHandle(handle);
|
||||||
GBLogEx.info(min, `BASIC: Web Automation PRESS ${char} ON element: ${frame}.`);
|
GBLogEx.info(min, `Web Automation PRESS ${char} ON element: ${frame}.`);
|
||||||
if (char.toLowerCase() === 'enter') {
|
if (char.toLowerCase() === 'enter') {
|
||||||
char = '\n';
|
char = '\n';
|
||||||
}
|
}
|
||||||
|
@ -315,7 +315,7 @@ export class WebAutomationServices {
|
||||||
const { min, user } = await DialogKeywords.getProcessInfo(pid);
|
const { min, user } = await DialogKeywords.getProcessInfo(pid);
|
||||||
|
|
||||||
const page = WebAutomationServices.getPageByHandle(handle);
|
const page = WebAutomationServices.getPageByHandle(handle);
|
||||||
GBLogEx.info(min, `BASIC: Web Automation CLICK LINK TEXT: ${text} ${index}.`);
|
GBLogEx.info(min, `Web Automation CLICK LINK TEXT: ${text} ${index}.`);
|
||||||
if (!index) {
|
if (!index) {
|
||||||
index = 1;
|
index = 1;
|
||||||
}
|
}
|
||||||
|
@ -328,7 +328,7 @@ export class WebAutomationServices {
|
||||||
const { min, user } = await DialogKeywords.getProcessInfo(pid);
|
const { min, user } = await DialogKeywords.getProcessInfo(pid);
|
||||||
|
|
||||||
const page = WebAutomationServices.getPageByHandle(handle);
|
const page = WebAutomationServices.getPageByHandle(handle);
|
||||||
GBLogEx.info(min, `BASIC: Web Automation CLICK BUTTON: ${text} ${index}.`);
|
GBLogEx.info(min, `Web Automation CLICK BUTTON: ${text} ${index}.`);
|
||||||
if (!index) {
|
if (!index) {
|
||||||
index = 1;
|
index = 1;
|
||||||
}
|
}
|
||||||
|
@ -346,7 +346,7 @@ export class WebAutomationServices {
|
||||||
public async screenshot({ pid, handle, selector }) {
|
public async screenshot({ pid, handle, selector }) {
|
||||||
const { min, user } = await DialogKeywords.getProcessInfo(pid);
|
const { min, user } = await DialogKeywords.getProcessInfo(pid);
|
||||||
const page = WebAutomationServices.getPageByHandle(handle);
|
const page = WebAutomationServices.getPageByHandle(handle);
|
||||||
GBLogEx.info(min, `BASIC: Web Automation SCREENSHOT ${selector}.`);
|
GBLogEx.info(min, `Web Automation SCREENSHOT ${selector}.`);
|
||||||
|
|
||||||
const gbaiName = DialogKeywords.getGBAIPath(min.botId);
|
const gbaiName = DialogKeywords.getGBAIPath(min.botId);
|
||||||
const localName = Path.join('work', gbaiName, 'cache', `screen-${GBAdminService.getRndReadableIdentifier()}.jpg`);
|
const localName = Path.join('work', gbaiName, 'cache', `screen-${GBAdminService.getRndReadableIdentifier()}.jpg`);
|
||||||
|
@ -354,7 +354,7 @@ export class WebAutomationServices {
|
||||||
await page.screenshot({ path: localName });
|
await page.screenshot({ path: localName });
|
||||||
|
|
||||||
const url = urlJoin(GBServer.globals.publicAddress, min.botId, 'cache', Path.basename(localName));
|
const url = urlJoin(GBServer.globals.publicAddress, min.botId, 'cache', Path.basename(localName));
|
||||||
GBLogEx.info(min, `BASIC: WebAutomation: Screenshot captured at ${url}.`);
|
GBLogEx.info(min, `WebAutomation: Screenshot captured at ${url}.`);
|
||||||
|
|
||||||
return { data: null, localName: localName, url: url };
|
return { data: null, localName: localName, url: url };
|
||||||
}
|
}
|
||||||
|
@ -369,7 +369,7 @@ export class WebAutomationServices {
|
||||||
|
|
||||||
text = `${text}`;
|
text = `${text}`;
|
||||||
const page = WebAutomationServices.getPageByHandle(handle);
|
const page = WebAutomationServices.getPageByHandle(handle);
|
||||||
GBLogEx.info(min, `BASIC: Web Automation TYPE on ${selector}: ${text}.`);
|
GBLogEx.info(min, `Web Automation TYPE on ${selector}: ${text}.`);
|
||||||
const e = await this.getBySelector({ handle, selector, pid });
|
const e = await this.getBySelector({ handle, selector, pid });
|
||||||
await e.click({ clickCount: 3 });
|
await e.click({ clickCount: 3 });
|
||||||
await page.keyboard.press('Backspace');
|
await page.keyboard.press('Backspace');
|
||||||
|
@ -409,7 +409,7 @@ export class WebAutomationServices {
|
||||||
|
|
||||||
const cookies = await page.cookies();
|
const cookies = await page.cookies();
|
||||||
options.headers.Cookie = cookies.map(ck => ck.name + '=' + ck.value).join(';');
|
options.headers.Cookie = cookies.map(ck => ck.name + '=' + ck.value).join(';');
|
||||||
GBLogEx.info(min, `BASIC: DOWNLOADING '${options.uri}...'`);
|
GBLogEx.info(min, `DOWNLOADING '${options.uri}...'`);
|
||||||
|
|
||||||
let local;
|
let local;
|
||||||
let filename;
|
let filename;
|
||||||
|
@ -455,7 +455,7 @@ export class WebAutomationServices {
|
||||||
file = await client.api(`${baseUrl}/drive/root:/${dstPath}:/content`).put(result);
|
file = await client.api(`${baseUrl}/drive/root:/${dstPath}:/content`).put(result);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error.code === 'nameAlreadyExists') {
|
if (error.code === 'nameAlreadyExists') {
|
||||||
GBLogEx.info(min, `BASIC: DOWNLOAD destination file already exists: ${dstPath}.`);
|
GBLogEx.info(min, `DOWNLOAD destination file already exists: ${dstPath}.`);
|
||||||
}
|
}
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
@ -484,7 +484,7 @@ export class WebAutomationServices {
|
||||||
const { min, user } = await DialogKeywords.getProcessInfo(pid);
|
const { min, user } = await DialogKeywords.getProcessInfo(pid);
|
||||||
|
|
||||||
const page = WebAutomationServices.getPageByHandle(handle);
|
const page = WebAutomationServices.getPageByHandle(handle);
|
||||||
GBLogEx.info(min, `BASIC: Web Automation CLICK element: ${frameOrSelector}.`);
|
GBLogEx.info(min, `Web Automation CLICK element: ${frameOrSelector}.`);
|
||||||
if (frameOrSelector) {
|
if (frameOrSelector) {
|
||||||
const result = await page.$eval(
|
const result = await page.$eval(
|
||||||
frameOrSelector,
|
frameOrSelector,
|
||||||
|
|
|
@ -175,7 +175,7 @@ export const createVm2Pool = ({ min, max, ...limits }) => {
|
||||||
GBServer.globals.debuggers[limits.botId].state = 0;
|
GBServer.globals.debuggers[limits.botId].state = 0;
|
||||||
GBServer.globals.debuggers[limits.botId].stateInfo = 'Fail';
|
GBServer.globals.debuggers[limits.botId].stateInfo = 'Fail';
|
||||||
} else if (stderrCache.includes('Debugger attached.')) {
|
} else if (stderrCache.includes('Debugger attached.')) {
|
||||||
GBLogEx.info(min, `BASIC: General Bots Debugger attached to Node .gbdialog process for ${limits.botId}.`);
|
GBLogEx.info(min, `General Bots Debugger attached to Node .gbdialog process for ${limits.botId}.`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -212,16 +212,16 @@ export const createVm2Pool = ({ min, max, ...limits }) => {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
GBServer.globals.debuggers[limits.botId].scope = variablesText;
|
GBServer.globals.debuggers[limits.botId].scope = variablesText;
|
||||||
GBLogEx.info(min,`BASIC: Breakpoint variables: ${variablesText}`); // (zero-based)
|
GBLogEx.info(min,`Breakpoint variables: ${variablesText}`); // (zero-based)
|
||||||
// Processes breakpoint hits.
|
// Processes breakpoint hits.
|
||||||
|
|
||||||
if (hitBreakpoints.length >= 1) {
|
if (hitBreakpoints.length >= 1) {
|
||||||
GBLogEx.info(min, `BASIC: Break at line ${frame.location.lineNumber + 1}`); // (zero-based)
|
GBLogEx.info(min, `Break at line ${frame.location.lineNumber + 1}`); // (zero-based)
|
||||||
|
|
||||||
GBServer.globals.debuggers[limits.botId].state = 2;
|
GBServer.globals.debuggers[limits.botId].state = 2;
|
||||||
GBServer.globals.debuggers[limits.botId].stateInfo = 'Break';
|
GBServer.globals.debuggers[limits.botId].stateInfo = 'Break';
|
||||||
} else {
|
} else {
|
||||||
GBLog.verbose(`BASIC: Configuring breakpoints if any for ${limits.botId}...`);
|
GBLog.verbose(`Configuring breakpoints if any for ${limits.botId}...`);
|
||||||
// Waits for debugger and setup breakpoints.
|
// Waits for debugger and setup breakpoints.
|
||||||
|
|
||||||
await CollectionUtil.asyncForEach(GBServer.globals.debuggers[limits.botId].breaks, async brk => {
|
await CollectionUtil.asyncForEach(GBServer.globals.debuggers[limits.botId].breaks, async brk => {
|
||||||
|
|
|
@ -39,7 +39,7 @@ const server = net1.createServer(socket => {
|
||||||
socket.write(JSON.stringify({ result }) + '\n');
|
socket.write(JSON.stringify({ result }) + '\n');
|
||||||
socket.end();
|
socket.end();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(`BASIC: RUNTIME: ${error.message}, ${error.stack}`);
|
console.log(`RUNTIME: ${error.message}, ${error.stack}`);
|
||||||
socket.write(JSON.stringify({ error: error.message }) + '\n');
|
socket.write(JSON.stringify({ error: error.message }) + '\n');
|
||||||
socket.end();
|
socket.end();
|
||||||
}
|
}
|
||||||
|
|
|
@ -412,7 +412,7 @@ export class GBConversationalService {
|
||||||
nexmo.message.sendSms(min.instance.smsServiceNumber, mobile, text, {}, (err, data) => {
|
nexmo.message.sendSms(min.instance.smsServiceNumber, mobile, text, {}, (err, data) => {
|
||||||
const message = data.messages ? data.messages[0] : {};
|
const message = data.messages ? data.messages[0] : {};
|
||||||
if (err || message['error-text']) {
|
if (err || message['error-text']) {
|
||||||
GBLog.error(`BASIC: error sending SMS to ${mobile}: ${message['error-text']}`);
|
GBLog.error(`error sending SMS to ${mobile}: ${message['error-text']}`);
|
||||||
reject(message['error-text']);
|
reject(message['error-text']);
|
||||||
} else {
|
} else {
|
||||||
resolve(data);
|
resolve(data);
|
||||||
|
|
|
@ -74,7 +74,7 @@ export class ImageServices {
|
||||||
let buf: any = Buffer.from(await res.arrayBuffer());
|
let buf: any = Buffer.from(await res.arrayBuffer());
|
||||||
Fs.writeFileSync(localName, buf, { encoding: null });
|
Fs.writeFileSync(localName, buf, { encoding: null });
|
||||||
|
|
||||||
GBLogEx.info(min, `BASIC: DALL-E image generated at ${url}.`);
|
GBLogEx.info(min, `DALL-E image generated at ${url}.`);
|
||||||
|
|
||||||
return { localName, url };
|
return { localName, url };
|
||||||
}
|
}
|
||||||
|
|
|
@ -410,7 +410,7 @@ export class WhatsappDirectLine extends GBService {
|
||||||
const botId = this.min.instance.botId;
|
const botId = this.min.instance.botId;
|
||||||
const state = WhatsappDirectLine.state[botId + from];
|
const state = WhatsappDirectLine.state[botId + from];
|
||||||
if (state) {
|
if (state) {
|
||||||
GBLog.verbose(`BASIC: Continuing HEAR from WhatsApp...`);
|
GBLog.verbose(`Continuing HEAR from WhatsApp...`);
|
||||||
WhatsappDirectLine.state[botId + from] = null;
|
WhatsappDirectLine.state[botId + from] = null;
|
||||||
await state.promise(null, text);
|
await state.promise(null, text);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue