fix(basic.gblib): GBAI automatic retrieval.
This commit is contained in:
parent
6992bf0ae5
commit
04e69b9d99
10 changed files with 115 additions and 80 deletions
|
@ -54,6 +54,7 @@ import crypto from 'crypto';
|
||||||
import Fs from 'fs';
|
import Fs from 'fs';
|
||||||
import { GBServer } from '../../../src/app.js';
|
import { GBServer } from '../../../src/app.js';
|
||||||
import { GuaribasUser } from '../../security.gbapp/models/index.js';
|
import { GuaribasUser } from '../../security.gbapp/models/index.js';
|
||||||
|
import { DialogKeywords } from '../../basic.gblib/services/DialogKeywords.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Services for server administration.
|
* Services for server administration.
|
||||||
|
@ -129,10 +130,12 @@ export class GBAdminService implements IGBAdminService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async undeployPackageCommand(text: string, min: GBMinInstance) {
|
public static async undeployPackageCommand(text: string, min: GBMinInstance) {
|
||||||
|
|
||||||
const packageName = text.split(' ')[1];
|
const packageName = text.split(' ')[1];
|
||||||
const importer = new GBImporter(min.core);
|
const importer = new GBImporter(min.core);
|
||||||
const deployer = new GBDeployer(min.core, importer);
|
const deployer = new GBDeployer(min.core, importer);
|
||||||
const localFolder = Path.join('work', `${min.instance.botId}.gbai`, Path.basename(packageName));
|
const path = DialogKeywords.getGBAIPath(min.botId, null, packageName);
|
||||||
|
const localFolder = Path.join('work', path);
|
||||||
await deployer.undeployPackageFromLocalPath(min.instance, localFolder);
|
await deployer.undeployPackageFromLocalPath(min.instance, localFolder);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,15 +152,13 @@ export class GBAdminService implements IGBAdminService {
|
||||||
}
|
}
|
||||||
await deployer['deployPackage2'](min, user, urlJoin(additionalPath, packageName));
|
await deployer['deployPackage2'](min, user, urlJoin(additionalPath, packageName));
|
||||||
} else {
|
} else {
|
||||||
const siteName = text.split(' ')[1];
|
const gbaiPath = DialogKeywords.getGBAIPath(min.instance.botId, null, packageName);
|
||||||
const folderName = text.split(' ')[2];
|
const localFolder = Path.join('work', gbaiPath);
|
||||||
|
|
||||||
const localFolder = Path.join('work', `${min.instance.botId}.gbai`, Path.basename(folderName));
|
|
||||||
|
|
||||||
// .gbot packages are handled using storage API, so no download
|
// .gbot packages are handled using storage API, so no download
|
||||||
// of local resources is required.
|
// of local resources is required.
|
||||||
|
|
||||||
await deployer['downloadFolder'](min, Path.join('work', `${min.instance.botId}.gbai`), Path.basename(folderName));
|
await deployer['downloadFolder'](min, localFolder);
|
||||||
await deployer['deployPackage2'](min, user, localFolder);
|
await deployer['deployPackage2'](min, user, localFolder);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -134,7 +134,7 @@ export class DialogKeywords {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const gbaiName = `${min.botId}.gbai`;
|
const gbaiName = DialogKeywords.getGBAIPath(min.botId);
|
||||||
const localName = Path.join('work', gbaiName, 'cache', `img${GBAdminService.getRndReadableIdentifier()}.jpg`);
|
const localName = Path.join('work', gbaiName, 'cache', `img${GBAdminService.getRndReadableIdentifier()}.jpg`);
|
||||||
|
|
||||||
await ChartServices.screenshot(definition, localName);
|
await ChartServices.screenshot(definition, localName);
|
||||||
|
@ -204,28 +204,28 @@ export class DialogKeywords {
|
||||||
*
|
*
|
||||||
* @example EXIT
|
* @example EXIT
|
||||||
*/
|
*/
|
||||||
public async exit({}) {}
|
public async exit({ }) { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get active tasks.
|
* Get active tasks.
|
||||||
*
|
*
|
||||||
* @example list = ACTIVE TASKS
|
* @example list = ACTIVE TASKS
|
||||||
*/
|
*/
|
||||||
public async getActiveTasks({ pid }) {}
|
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({ pid, 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({ pid, name }) {}
|
public async fndContact({ pid, name }) { }
|
||||||
|
|
||||||
public getContentLocaleWithCulture(contentLocale) {
|
public getContentLocaleWithCulture(contentLocale) {
|
||||||
switch (contentLocale) {
|
switch (contentLocale) {
|
||||||
|
@ -676,7 +676,7 @@ export class DialogKeywords {
|
||||||
* @example MENU
|
* @example MENU
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public async showMenu({}) {
|
public async showMenu({ }) {
|
||||||
// https://github.com/GeneralBots/BotServer/issues/237
|
// https://github.com/GeneralBots/BotServer/issues/237
|
||||||
// return await beginDialog('/menu');
|
// return await beginDialog('/menu');
|
||||||
}
|
}
|
||||||
|
@ -783,7 +783,7 @@ export class DialogKeywords {
|
||||||
|
|
||||||
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.getGBDataPath(botId);
|
const path = DialogKeywords.getGBAIPath(botId);
|
||||||
let url = `${baseUrl}/drive/root:/${path}:/children`;
|
let url = `${baseUrl}/drive/root:/${path}:/children`;
|
||||||
|
|
||||||
GBLog.info(`Loading HEAR AS .xlsx options from Sheet: ${url}`);
|
GBLog.info(`Loading HEAR AS .xlsx options from Sheet: ${url}`);
|
||||||
|
@ -1028,11 +1028,28 @@ export class DialogKeywords {
|
||||||
GBLog.error(`BASIC RUNTIME ERR HEAR ${error.message ? error.message : error}\n Stack:${error.stack}`);
|
GBLog.error(`BASIC RUNTIME ERR HEAR ${error.message ? error.message : error}\n Stack:${error.stack}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static getGBDataPath(botId) {
|
static getGBAIPath(botId, packageType = null, packageName = null) {
|
||||||
|
const gbai = `${botId}.gbai`;
|
||||||
|
if (!packageType && !packageName) {
|
||||||
|
return GBConfigService.get('DEV_GBAI') ?
|
||||||
|
GBConfigService.get('DEV_GBAI') :
|
||||||
|
gbai;
|
||||||
|
}
|
||||||
|
|
||||||
return GBConfigService.get('GBDIALOG_GBDATABOT')?
|
if (GBConfigService.get('DEV_GBAI')) {
|
||||||
GBConfigService.get('GBDIALOG_GBDATABOT'):
|
|
||||||
urljoin(`${botId}.gbai`, `${botId}.gbdata`);
|
return urljoin(GBConfigService.get('DEV_GBAI'),
|
||||||
|
packageName ?
|
||||||
|
packageName :
|
||||||
|
`${botId}.${packageType}`);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
return urljoin(gbai,
|
||||||
|
packageName ?
|
||||||
|
packageName :
|
||||||
|
`${botId}.${packageType}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1110,7 +1127,7 @@ export class DialogKeywords {
|
||||||
const element = filename._page ? filename._page : filename.screenshot ? filename : null;
|
const element = filename._page ? filename._page : filename.screenshot ? filename : null;
|
||||||
|
|
||||||
if (element) {
|
if (element) {
|
||||||
const gbaiName = `${min.botId}.gbai`;
|
const gbaiName = DialogKeywords.getGBAIPath(min.botId);
|
||||||
const localName = Path.join('work', gbaiName, 'cache', `img${GBAdminService.getRndReadableIdentifier()}.jpg`);
|
const localName = Path.join('work', gbaiName, 'cache', `img${GBAdminService.getRndReadableIdentifier()}.jpg`);
|
||||||
await element.screenshot({ path: localName, fullPage: true });
|
await element.screenshot({ path: localName, fullPage: true });
|
||||||
|
|
||||||
|
@ -1130,14 +1147,16 @@ export class DialogKeywords {
|
||||||
|
|
||||||
await min.conversationalService['playMarkdown'](min, md, DialogKeywords.getChannel(), mobile);
|
await min.conversationalService['playMarkdown'](min, md, DialogKeywords.getChannel(), mobile);
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
const gbaiName = DialogKeywords.getGBAIPath(min.botId, `gbkb`);
|
||||||
|
|
||||||
GBLog.info(`BASIC: Sending the file ${filename} to mobile ${mobile}.`);
|
GBLog.info(`BASIC: Sending the file ${filename} to mobile ${mobile}.`);
|
||||||
let url: string;
|
let url: string;
|
||||||
if (!filename.startsWith('https://')) {
|
if (!filename.startsWith('https://')) {
|
||||||
url = urlJoin(
|
url = urlJoin(
|
||||||
GBServer.globals.publicAddress,
|
GBServer.globals.publicAddress,
|
||||||
'kb',
|
'kb',
|
||||||
`${min.botId}.gbai`,
|
gbaiName,
|
||||||
`${min.botId}.gbkb`,
|
|
||||||
'assets',
|
'assets',
|
||||||
filename
|
filename
|
||||||
);
|
);
|
||||||
|
@ -1160,7 +1179,7 @@ export class DialogKeywords {
|
||||||
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');
|
||||||
|
|
||||||
const gbaiName = `${min.botId}.gbai`;
|
const gbaiName = DialogKeywords.getGBAIPath(min.botId);
|
||||||
const localName = Path.join('work', gbaiName, 'cache', `qr${GBAdminService.getRndReadableIdentifier()}.png`);
|
const localName = Path.join('work', gbaiName, 'cache', `qr${GBAdminService.getRndReadableIdentifier()}.png`);
|
||||||
Fs.writeFileSync(localName, buf, { encoding: null });
|
Fs.writeFileSync(localName, buf, { encoding: null });
|
||||||
const url = urlJoin(GBServer.globals.publicAddress, min.botId, 'cache', Path.basename(localName));
|
const url = urlJoin(GBServer.globals.publicAddress, min.botId, 'cache', Path.basename(localName));
|
||||||
|
|
|
@ -140,7 +140,7 @@ export class GBVMService extends GBService {
|
||||||
|
|
||||||
// Hot swap for .vbs files.
|
// Hot swap for .vbs files.
|
||||||
const fullFilename = urlJoin(folder, filename);
|
const fullFilename = urlJoin(folder, filename);
|
||||||
if (process.env.GBDIALOG_HOTSWAP) {
|
if (process.env.DEV_HOTSWAP) {
|
||||||
Fs.watchFile(fullFilename, async () => {
|
Fs.watchFile(fullFilename, async () => {
|
||||||
await this.translateBASIC(fullFilename, mainName, min);
|
await this.translateBASIC(fullFilename, mainName, min);
|
||||||
const parsedCode: string = Fs.readFileSync(jsfile, 'utf8');
|
const parsedCode: string = Fs.readFileSync(jsfile, 'utf8');
|
||||||
|
@ -371,7 +371,8 @@ export class GBVMService extends GBService {
|
||||||
}
|
}
|
||||||
|
|
||||||
const botId = min.botId;
|
const botId = min.botId;
|
||||||
const gbdialogPath = urlJoin(process.cwd(), 'work', `${botId}.gbai`, `${botId}.gbdialog`);
|
const path = DialogKeywords.getGBAIPath(min.botId,`gbdialog`);
|
||||||
|
const gbdialogPath = urlJoin(process.cwd(), 'work', path);
|
||||||
const scriptPath = urlJoin(gbdialogPath, `${text}.js`);
|
const scriptPath = urlJoin(gbdialogPath, `${text}.js`);
|
||||||
|
|
||||||
let code = min.sandBoxMap[text];
|
let code = min.sandBoxMap[text];
|
||||||
|
|
|
@ -90,9 +90,9 @@ export class ImageProcessingServices {
|
||||||
});
|
});
|
||||||
|
|
||||||
const botId = min.instance.botId;
|
const botId = min.instance.botId;
|
||||||
const gbaiName = `${botId}.gbai`;
|
const path = DialogKeywords.getGBAIPath(min.botId);
|
||||||
const img = await joinImages(paths);
|
const img = await joinImages(paths);
|
||||||
const localName = Path.join('work', gbaiName, 'cache', `img-mrg${GBAdminService.getRndReadableIdentifier()}.png`);
|
const localName = Path.join('work', path, 'cache', `img-mrg${GBAdminService.getRndReadableIdentifier()}.png`);
|
||||||
const url = urlJoin(GBServer.globals.publicAddress, min.botId, 'cache', Path.basename(localName));
|
const url = urlJoin(GBServer.globals.publicAddress, min.botId, 'cache', Path.basename(localName));
|
||||||
img.toFile(localName);
|
img.toFile(localName);
|
||||||
|
|
||||||
|
|
|
@ -233,7 +233,7 @@ export class SystemKeywords {
|
||||||
// headers.
|
// headers.
|
||||||
|
|
||||||
const { min, user } = await DialogKeywords.getProcessInfo(pid);
|
const { min, user } = await DialogKeywords.getProcessInfo(pid);
|
||||||
const gbaiName = `${min.botId}.gbai`;
|
const gbaiName = DialogKeywords.getGBAIPath(min.botId);
|
||||||
const browser = await GBSSR.createBrowser(null);
|
const browser = await GBSSR.createBrowser(null);
|
||||||
const page = await browser.newPage();
|
const page = await browser.newPage();
|
||||||
|
|
||||||
|
@ -326,7 +326,7 @@ export class SystemKeywords {
|
||||||
|
|
||||||
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 gbaiName = `${min.botId}.gbai`;
|
const gbaiName = DialogKeywords.getGBAIPath(min.botId);
|
||||||
const tmpDocx = urlJoin(gbaiName, `${botId}.gbdrive`, `tmp${GBAdminService.getRndReadableIdentifier()}.docx`);
|
const tmpDocx = urlJoin(gbaiName, `${botId}.gbdrive`, `tmp${GBAdminService.getRndReadableIdentifier()}.docx`);
|
||||||
|
|
||||||
// Performs the conversion operation.
|
// Performs the conversion operation.
|
||||||
|
@ -489,7 +489,7 @@ export class SystemKeywords {
|
||||||
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.getGBDataPath(botId);
|
const path = DialogKeywords.getGBAIPath(botId, 'gbdata');
|
||||||
|
|
||||||
address = address.indexOf(':') !== -1 ? address : address + ':' + address;
|
address = address.indexOf(':') !== -1 ? address : address + ':' + address;
|
||||||
|
|
||||||
|
@ -535,7 +535,7 @@ export class SystemKeywords {
|
||||||
GBLog.info(`BASIC: Saving '${file}' (SAVE file).`);
|
GBLog.info(`BASIC: Saving '${file}' (SAVE file).`);
|
||||||
let { baseUrl, client } = await GBDeployer.internalGetDriveClient(min);
|
let { baseUrl, client } = await GBDeployer.internalGetDriveClient(min);
|
||||||
const botId = min.instance.botId;
|
const botId = min.instance.botId;
|
||||||
const path = `/${botId}.gbai/${botId}.gbdrive`;
|
const path = DialogKeywords.getGBAIPath(min.botId,`gbdrive`);
|
||||||
|
|
||||||
// Checks if it is a GB FILE object.
|
// Checks if it is a GB FILE object.
|
||||||
|
|
||||||
|
@ -569,7 +569,7 @@ export class SystemKeywords {
|
||||||
GBLog.info(`BASIC: Saving '${file}' (SAVE). Args: ${args.join(',')}.`);
|
GBLog.info(`BASIC: 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.getGBDataPath(botId);
|
const path = DialogKeywords.getGBAIPath(botId, 'gbdata');
|
||||||
|
|
||||||
let document = await this.internalGetDocument(client, baseUrl, path, file);
|
let document = await this.internalGetDocument(client, baseUrl, path, file);
|
||||||
let sheets = await client.api(`${baseUrl}/drive/items/${document.id}/workbook/worksheets`).get();
|
let sheets = await client.api(`${baseUrl}/drive/items/${document.id}/workbook/worksheets`).get();
|
||||||
|
@ -622,8 +622,8 @@ export class SystemKeywords {
|
||||||
} else {
|
} else {
|
||||||
GBLog.info(`BASIC: GET '${addressOrHeaders}' in '${file}'.`);
|
GBLog.info(`BASIC: GET '${addressOrHeaders}' in '${file}'.`);
|
||||||
let { baseUrl, client } = await GBDeployer.internalGetDriveClient(min);
|
let { baseUrl, client } = await GBDeployer.internalGetDriveClient(min);
|
||||||
const botId = min.instance.botId;
|
const botId = min.instance.botId;''
|
||||||
const path = DialogKeywords.getGBDataPath(botId);
|
const path = DialogKeywords.getGBAIPath(botId, 'gbdata');
|
||||||
|
|
||||||
let document = await this.internalGetDocument(client, baseUrl, path, file);
|
let document = await this.internalGetDocument(client, baseUrl, path, file);
|
||||||
|
|
||||||
|
@ -695,7 +695,7 @@ export class SystemKeywords {
|
||||||
args.shift();
|
args.shift();
|
||||||
|
|
||||||
const botId = min.instance.botId;
|
const botId = min.instance.botId;
|
||||||
const path = DialogKeywords.getGBDataPath(botId);
|
const path = DialogKeywords.getGBAIPath(botId, 'gbdata');
|
||||||
|
|
||||||
// MAX LINES property.
|
// MAX LINES property.
|
||||||
|
|
||||||
|
@ -751,7 +751,7 @@ export class SystemKeywords {
|
||||||
rows[i] = result[i];
|
rows[i] = result[i];
|
||||||
}
|
}
|
||||||
} else if (file['cTag']) {
|
} else if (file['cTag']) {
|
||||||
const gbaiName = `${min.botId}.gbai`;
|
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`);
|
||||||
const url = file['@microsoft.graph.downloadUrl'];
|
const url = file['@microsoft.graph.downloadUrl'];
|
||||||
const response = await fetch(url);
|
const response = await fetch(url);
|
||||||
|
@ -1101,7 +1101,8 @@ export class SystemKeywords {
|
||||||
const { min, user, params } = await DialogKeywords.getProcessInfo(pid);
|
const { min, user, params } = await DialogKeywords.getProcessInfo(pid);
|
||||||
let { baseUrl, client } = await GBDeployer.internalGetDriveClient(min);
|
let { baseUrl, client } = await GBDeployer.internalGetDriveClient(min);
|
||||||
const botId = min.instance.botId;
|
const botId = min.instance.botId;
|
||||||
let path = `/${botId}.gbai/${botId}.gbdrive`;
|
const path = DialogKeywords.getGBAIPath(min.botId, `gbdrive`);
|
||||||
|
|
||||||
|
|
||||||
// Extracts each part of path to call create folder to each
|
// Extracts each part of path to call create folder to each
|
||||||
// one of them.
|
// one of them.
|
||||||
|
@ -1150,7 +1151,8 @@ export class SystemKeywords {
|
||||||
public async shareFolder({ pid, folder, email, message }) {
|
public async shareFolder({ pid, folder, email, message }) {
|
||||||
const { min, user, params } = await DialogKeywords.getProcessInfo(pid);
|
const { min, user, params } = await DialogKeywords.getProcessInfo(pid);
|
||||||
let { baseUrl, client } = await GBDeployer.internalGetDriveClient(min);
|
let { baseUrl, client } = await GBDeployer.internalGetDriveClient(min);
|
||||||
const root = urlJoin(`/${min.botId}.gbai/${min.botId}.gbdrive`, folder);
|
const path = DialogKeywords.getGBAIPath(min.botId,`gbdrive`);
|
||||||
|
const root = urlJoin(path, folder);
|
||||||
|
|
||||||
const src = await client.api(`${baseUrl}/drive/root:/${root}`).get();
|
const src = await client.api(`${baseUrl}/drive/root:/${root}`).get();
|
||||||
|
|
||||||
|
@ -1188,7 +1190,7 @@ export class SystemKeywords {
|
||||||
|
|
||||||
// Determines full path at source and destination.
|
// Determines full path at source and destination.
|
||||||
|
|
||||||
const root = DialogKeywords.getGBDataPath(botId);
|
const root = DialogKeywords.getGBAIPath(botId, 'gbdrive');
|
||||||
const srcPath = urlJoin(root, src);
|
const srcPath = urlJoin(root, src);
|
||||||
const dstPath = urlJoin(root, dest);
|
const dstPath = urlJoin(root, dest);
|
||||||
|
|
||||||
|
@ -1248,10 +1250,10 @@ export class SystemKeywords {
|
||||||
dest = dest.replace(/\\/gi, '/');
|
dest = dest.replace(/\\/gi, '/');
|
||||||
|
|
||||||
// Determines full path at source and destination.
|
// Determines full path at source and destination.
|
||||||
|
const path = DialogKeywords.getGBAIPath(min.botId,`gbdrive`);
|
||||||
const root = urlJoin(`/${botId}.gbai/${botId}.gbdrive`);
|
const root = path;
|
||||||
const srcPath = urlJoin(root, src);
|
const srcPath = urlJoin(root, src);
|
||||||
const dstPath = urlJoin(`/${botId}.gbai/${botId}.gbdrive`, dest);
|
const dstPath = urlJoin(path dest);
|
||||||
|
|
||||||
// Checks if the destination contains subfolders that
|
// Checks if the destination contains subfolders that
|
||||||
// need to be created.
|
// need to be created.
|
||||||
|
@ -1442,7 +1444,7 @@ export class SystemKeywords {
|
||||||
public async fill({ pid, templateName, data }) {
|
public async fill({ pid, templateName, data }) {
|
||||||
const { min, user } = await DialogKeywords.getProcessInfo(pid);
|
const { min, user } = await DialogKeywords.getProcessInfo(pid);
|
||||||
const botId = min.instance.botId;
|
const botId = min.instance.botId;
|
||||||
const gbaiName = `${botId}.gbai`;
|
const gbaiName = DialogKeywords.getGBAIPath(botId, 'gbdata');
|
||||||
let localName;
|
let localName;
|
||||||
|
|
||||||
// Downloads template from .gbdrive.
|
// Downloads template from .gbdrive.
|
||||||
|
@ -1599,7 +1601,7 @@ export class SystemKeywords {
|
||||||
|
|
||||||
const { min, user, params } = await DialogKeywords.getProcessInfo(pid);
|
const { min, user, params } = await DialogKeywords.getProcessInfo(pid);
|
||||||
const botId = min.instance.botId;
|
const botId = min.instance.botId;
|
||||||
const path = DialogKeywords.getGBDataPath(botId);
|
const path = DialogKeywords.getGBAIPath(botId, 'gbdata');
|
||||||
|
|
||||||
// MAX LINES property.
|
// MAX LINES property.
|
||||||
|
|
||||||
|
|
|
@ -323,7 +323,7 @@ export class WebAutomationServices {
|
||||||
const page = WebAutomationServices.getPageByHandle(handle);
|
const page = WebAutomationServices.getPageByHandle(handle);
|
||||||
GBLog.info(`BASIC: Web Automation SCREENSHOT ${selector}.`);
|
GBLog.info(`BASIC: Web Automation SCREENSHOT ${selector}.`);
|
||||||
|
|
||||||
const gbaiName = `${min.botId}.gbai`;
|
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`);
|
||||||
|
|
||||||
await page.screenshot({ path: localName });
|
await page.screenshot({ path: localName });
|
||||||
|
@ -412,8 +412,8 @@ export class WebAutomationServices {
|
||||||
folder = folder.replace(/\\/gi, '/');
|
folder = folder.replace(/\\/gi, '/');
|
||||||
|
|
||||||
// Determines full path at source and destination.
|
// Determines full path at source and destination.
|
||||||
|
const path = DialogKeywords.getGBAIPath(min.botId,`gbdrive`);
|
||||||
const root = urlJoin(`/${botId}.gbai/${botId}.gbdrive`);
|
const root = path;
|
||||||
const dstPath = urlJoin(root, folder, filename);
|
const dstPath = urlJoin(root, folder, filename);
|
||||||
|
|
||||||
// Checks if the destination contains subfolders that
|
// Checks if the destination contains subfolders that
|
||||||
|
|
|
@ -58,6 +58,7 @@ import { GBImporter } from './GBImporterService.js';
|
||||||
import { TeamsService } from '../../teams.gblib/services/TeamsService.js';
|
import { TeamsService } from '../../teams.gblib/services/TeamsService.js';
|
||||||
import MicrosoftGraph from '@microsoft/microsoft-graph-client';
|
import MicrosoftGraph from '@microsoft/microsoft-graph-client';
|
||||||
import { GBLogEx } from './GBLogEx.js';
|
import { GBLogEx } from './GBLogEx.js';
|
||||||
|
import { DialogKeywords } from '../../basic.gblib/services/DialogKeywords.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deployer service for bots, themes, ai and more.
|
* Deployer service for bots, themes, ai and more.
|
||||||
|
@ -410,7 +411,7 @@ export class GBDeployer implements IGBDeployer {
|
||||||
// Retrieves all files in .bot folder.
|
// Retrieves all files in .bot folder.
|
||||||
|
|
||||||
const botId = min.instance.botId;
|
const botId = min.instance.botId;
|
||||||
const path = `/${botId}.gbai/${botId}.gbot`;
|
const path = DialogKeywords.getGBAIPath(botId, 'gbot');
|
||||||
let url = `https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${libraryId}/drive/root:${path}:/children`;
|
let url = `https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${libraryId}/drive/root:${path}:/children`;
|
||||||
|
|
||||||
GBLog.info(`Loading .gbot from Excel: ${url}`);
|
GBLog.info(`Loading .gbot from Excel: ${url}`);
|
||||||
|
@ -482,7 +483,8 @@ export class GBDeployer implements IGBDeployer {
|
||||||
// Retrieves all files in remote folder.
|
// Retrieves all files in remote folder.
|
||||||
|
|
||||||
const botId = min.instance.botId;
|
const botId = min.instance.botId;
|
||||||
const path = urlJoin(`/${botId}.gbai`, remotePath);
|
let path = DialogKeywords.getGBAIPath(min.botId);
|
||||||
|
path = urlJoin(path, remotePath);
|
||||||
let url = `${baseUrl}/drive/root:${path}:/children`;
|
let url = `${baseUrl}/drive/root:${path}:/children`;
|
||||||
|
|
||||||
GBLog.info(`Download URL: ${url}`);
|
GBLog.info(`Download URL: ${url}`);
|
||||||
|
@ -817,16 +819,17 @@ export class GBDeployer implements IGBDeployer {
|
||||||
* Servers bot storage assets to be used by web, WhatsApp and other channels.
|
* Servers bot storage assets to be used by web, WhatsApp and other channels.
|
||||||
*/
|
*/
|
||||||
public static mountGBKBAssets(packageName: any, botId: string, filename: string) {
|
public static mountGBKBAssets(packageName: any, botId: string, filename: string) {
|
||||||
|
const gbaiName = DialogKeywords.getGBAIPath(botId);
|
||||||
|
|
||||||
// Servers menu assets.
|
// Servers menu assets.
|
||||||
|
|
||||||
GBServer.globals.server.use(
|
GBServer.globals.server.use(
|
||||||
`/kb/${botId}.gbai/${packageName}/subjects`,
|
`/kb/${gbaiName}/${packageName}/subjects`,
|
||||||
express.static(urlJoin(filename, 'subjects'))
|
express.static(urlJoin(filename, 'subjects'))
|
||||||
);
|
);
|
||||||
|
|
||||||
// Servers all other assets in .gbkb folders.
|
// Servers all other assets in .gbkb folders.
|
||||||
|
|
||||||
const gbaiName = `${botId}.gbai`;
|
|
||||||
GBServer.globals.server.use(
|
GBServer.globals.server.use(
|
||||||
`/kb/${gbaiName}/${packageName}/assets`,
|
`/kb/${gbaiName}/${packageName}/assets`,
|
||||||
express.static(urlJoin('work', gbaiName, filename, 'assets'))
|
express.static(urlJoin('work', gbaiName, filename, 'assets'))
|
||||||
|
@ -849,7 +852,7 @@ export class GBDeployer implements IGBDeployer {
|
||||||
express.static(urlJoin('work', gbaiName, `${botId}.gbdata`, 'public'))
|
express.static(urlJoin('work', gbaiName, `${botId}.gbdata`, 'public'))
|
||||||
);
|
);
|
||||||
|
|
||||||
GBLog.verbose(`KB (.gbkb) assets accessible at: /kb/${botId}.gbai/${packageName}.`);
|
GBLog.verbose(`KB (.gbkb) assets accessible at: /kb/${gbaiName}/${packageName}.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -87,6 +87,7 @@ import { GoogleChatDirectLine } from '../../google-chat.gblib/services/GoogleCha
|
||||||
import { SystemKeywords } from '../../basic.gblib/services/SystemKeywords.js';
|
import { SystemKeywords } from '../../basic.gblib/services/SystemKeywords.js';
|
||||||
import Path from 'path';
|
import Path from 'path';
|
||||||
import { GBSSR } from './GBSSR.js';
|
import { GBSSR } from './GBSSR.js';
|
||||||
|
import { DialogKeywords } from '../../basic.gblib/services/DialogKeywords.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Minimal service layer for a bot and encapsulation of BOT Framework calls.
|
* Minimal service layer for a bot and encapsulation of BOT Framework calls.
|
||||||
|
@ -280,37 +281,38 @@ export class GBMinService {
|
||||||
|
|
||||||
// Install per bot deployed packages.
|
// Install per bot deployed packages.
|
||||||
|
|
||||||
let packagePath = `work/${min.botId}.gbai/${min.botId}.gbdialog`;
|
let packagePath = urlJoin(`work`, DialogKeywords.getGBAIPath(min.botId, 'gbdialog'));
|
||||||
if (Fs.existsSync(packagePath)) {
|
if (Fs.existsSync(packagePath)) {
|
||||||
await this.deployer['deployPackage2'](min, user, packagePath);
|
await this.deployer['deployPackage2'](min, user, packagePath);
|
||||||
}
|
}
|
||||||
packagePath = `work/${min.botId}.gbai/${min.botId}.gbapp`;
|
packagePath = urlJoin(`work`, DialogKeywords.getGBAIPath(min.botId, 'gbapp'));
|
||||||
if (Fs.existsSync(packagePath)) {
|
if (Fs.existsSync(packagePath)) {
|
||||||
await this.deployer['deployPackage2'](min, user, packagePath);
|
await this.deployer['deployPackage2'](min, user, packagePath);
|
||||||
}
|
}
|
||||||
packagePath = `work/${min.botId}.gbai/${min.botId}.gbtheme`;
|
packagePath = urlJoin(`work`, DialogKeywords.getGBAIPath(min.botId, 'gbtheme'));
|
||||||
if (Fs.existsSync(packagePath)) {
|
if (Fs.existsSync(packagePath)) {
|
||||||
await this.deployer['deployPackage2'](min, user, packagePath);
|
await this.deployer['deployPackage2'](min, user, packagePath);
|
||||||
}
|
}
|
||||||
packagePath = `work/${min.botId}.gbai/${min.botId}.gblib`;
|
packagePath = urlJoin(`work`, DialogKeywords.getGBAIPath(min.botId, `gblib`));
|
||||||
if (Fs.existsSync(packagePath)) {
|
if (Fs.existsSync(packagePath)) {
|
||||||
await this.deployer['deployPackage2'](min, user, packagePath);
|
await this.deployer['deployPackage2'](min, user, packagePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
let dir = `work/${min.botId}.gbai/cache`;
|
const gbai = DialogKeywords.getGBAIPath(min.botId);
|
||||||
|
let dir = `work/${gbai}/cache`;
|
||||||
|
|
||||||
if (!Fs.existsSync(dir)) {
|
if (!Fs.existsSync(dir)) {
|
||||||
mkdirp.sync(dir);
|
mkdirp.sync(dir);
|
||||||
}
|
}
|
||||||
dir = `work/${min.botId}.gbai/profile`;
|
dir = `${gbai}/profile`;
|
||||||
if (!Fs.existsSync(dir)) {
|
if (!Fs.existsSync(dir)) {
|
||||||
mkdirp.sync(dir);
|
mkdirp.sync(dir);
|
||||||
}
|
}
|
||||||
dir = `work/${min.botId}.gbai/uploads`;
|
dir = `${gbai}/uploads`;
|
||||||
if (!Fs.existsSync(dir)) {
|
if (!Fs.existsSync(dir)) {
|
||||||
mkdirp.sync(dir);
|
mkdirp.sync(dir);
|
||||||
}
|
}
|
||||||
dir = `work/${min.botId}.gbai/${min.botId}.gbui`;
|
dir = DialogKeywords.getGBAIPath(min.botId, `gbui`);
|
||||||
if (!Fs.existsSync(dir)) {
|
if (!Fs.existsSync(dir)) {
|
||||||
mkdirp.sync(dir);
|
mkdirp.sync(dir);
|
||||||
}
|
}
|
||||||
|
@ -925,7 +927,8 @@ export class GBMinService {
|
||||||
ps: null,
|
ps: null,
|
||||||
qs: null
|
qs: null
|
||||||
});
|
});
|
||||||
const folder = `work/${min.instance.botId}.gbai/cache`;
|
const path = DialogKeywords.getGBAIPath(min.botId);
|
||||||
|
const folder = `work/${path}/cache`;
|
||||||
const filename = `${GBAdminService.generateUuid()}.png`;
|
const filename = `${GBAdminService.generateUuid()}.png`;
|
||||||
|
|
||||||
Fs.writeFileSync(path.join(folder, filename), data);
|
Fs.writeFileSync(path.join(folder, filename), data);
|
||||||
|
@ -1080,7 +1083,8 @@ export class GBMinService {
|
||||||
private static async downloadAttachmentAndWrite(attachment) {
|
private static async downloadAttachmentAndWrite(attachment) {
|
||||||
const url = attachment.contentUrl;
|
const url = attachment.contentUrl;
|
||||||
const localFolder = Path.join('work');
|
const localFolder = Path.join('work');
|
||||||
const localFileName = Path.join(localFolder, `${this['min'].botId}.gbai`, 'uploads', attachment.name);
|
const path = DialogKeywords.getGBAIPath(this['min'].botId);
|
||||||
|
const localFileName = Path.join(localFolder, path, 'uploads', attachment.name);
|
||||||
|
|
||||||
let res;
|
let res;
|
||||||
if (url.startsWith('data:')) {
|
if (url.startsWith('data:')) {
|
||||||
|
|
|
@ -49,6 +49,7 @@ import { GBLogEx } from './GBLogEx.js';
|
||||||
import urlJoin from 'url-join';
|
import urlJoin from 'url-join';
|
||||||
import { GBDeployer } from './GBDeployer.js';
|
import { GBDeployer } from './GBDeployer.js';
|
||||||
import { GBMinService } from './GBMinService.js';
|
import { GBMinService } from './GBMinService.js';
|
||||||
|
import { DialogKeywords } from '../../basic.gblib/services/DialogKeywords.js';
|
||||||
const puppeteer = require('puppeteer-extra');
|
const puppeteer = require('puppeteer-extra');
|
||||||
const hidden = require('puppeteer-extra-plugin-stealth');
|
const hidden = require('puppeteer-extra-plugin-stealth');
|
||||||
const { executablePath } = require('puppeteer');
|
const { executablePath } = require('puppeteer');
|
||||||
|
@ -283,12 +284,13 @@ export class GBSSR {
|
||||||
GBServer.globals.minInstances[0]:
|
GBServer.globals.minInstances[0]:
|
||||||
GBServer.globals.minInstances.filter(p => p.instance.botId === botId)[0];
|
GBServer.globals.minInstances.filter(p => p.instance.botId === botId)[0];
|
||||||
|
|
||||||
|
const path = DialogKeywords.getGBAIPath(min.botId,`gbui`);
|
||||||
|
|
||||||
if (min && req.originalUrl && prerender && exclude) {
|
if (min && req.originalUrl && prerender && exclude) {
|
||||||
const path = Path.join(
|
const path = Path.join(
|
||||||
process.env.PWD,
|
process.env.PWD,
|
||||||
'work',
|
'work',
|
||||||
`${min.instance.botId}.gbai`,
|
path,
|
||||||
`${min.instance.botId}.gbui`,
|
|
||||||
'index.html'
|
'index.html'
|
||||||
);
|
);
|
||||||
const html = Fs.readFileSync(path, 'utf8');
|
const html = Fs.readFileSync(path, 'utf8');
|
||||||
|
|
|
@ -73,6 +73,7 @@ import { min } from 'lodash';
|
||||||
import { GBAdminService } from '../../admin.gbapp/services/GBAdminService.js';
|
import { GBAdminService } from '../../admin.gbapp/services/GBAdminService.js';
|
||||||
import { text } from 'body-parser';
|
import { text } from 'body-parser';
|
||||||
import { GBVMService } from '../../basic.gblib/services/GBVMService.js';
|
import { GBVMService } from '../../basic.gblib/services/GBVMService.js';
|
||||||
|
import { DialogKeywords } from 'packages/basic.gblib/services/DialogKeywords.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Result for quey on KB data.
|
* Result for quey on KB data.
|
||||||
|
@ -528,10 +529,9 @@ export class KBService implements IGBKBService {
|
||||||
const isBasic = answer.toLowerCase().startsWith('/basic');
|
const isBasic = answer.toLowerCase().startsWith('/basic');
|
||||||
if (/TALK\s*\".*\"/gi.test(answer) || isBasic) {
|
if (/TALK\s*\".*\"/gi.test(answer) || isBasic) {
|
||||||
const code = isBasic ? answer.substr(6) : answer;
|
const code = isBasic ? answer.substr(6) : answer;
|
||||||
const gbaiName = `${min.instance.botId}.gbai`;
|
const path = DialogKeywords.getGBAIPath(min.botId,`gbdialog`);
|
||||||
const gbdialogName = `${min.instance.botId}.gbdialog`;
|
|
||||||
const scriptName = `tmp${GBAdminService.getRndReadableIdentifier()}.docx`;
|
const scriptName = `tmp${GBAdminService.getRndReadableIdentifier()}.docx`;
|
||||||
const localName = Path.join('work', gbaiName, gbdialogName, `${scriptName}`);
|
const localName = Path.join('work', path, `${scriptName}`);
|
||||||
Fs.writeFileSync(localName, code, { encoding: null });
|
Fs.writeFileSync(localName, code, { encoding: null });
|
||||||
answer = scriptName;
|
answer = scriptName;
|
||||||
|
|
||||||
|
@ -603,18 +603,19 @@ export class KBService implements IGBKBService {
|
||||||
answer.content.endsWith('.xls') ||
|
answer.content.endsWith('.xls') ||
|
||||||
answer.content.endsWith('.xlsx')
|
answer.content.endsWith('.xlsx')
|
||||||
) {
|
) {
|
||||||
|
const path = DialogKeywords.getGBAIPath(min.botId, `gbkb`);
|
||||||
const doc = urlJoin(
|
const doc = urlJoin(
|
||||||
GBServer.globals.publicAddress,
|
GBServer.globals.publicAddress,
|
||||||
'kb',
|
'kb',
|
||||||
`${min.instance.botId}.gbai`,
|
path,
|
||||||
`${min.instance.botId}.gbkb`,
|
|
||||||
'assets',
|
'assets',
|
||||||
answer.content
|
answer.content
|
||||||
);
|
);
|
||||||
const url = `http://view.officeapps.live.com/op/view.aspx?src=${doc}`;
|
const url = `http://view.officeapps.live.com/op/view.aspx?src=${doc}`;
|
||||||
await this.playUrl(min, min.conversationalService, step, url, channel);
|
await this.playUrl(min, min.conversationalService, step, url, channel);
|
||||||
} else if (answer.content.endsWith('.pdf')) {
|
} else if (answer.content.endsWith('.pdf')) {
|
||||||
const url = urlJoin('kb', `${min.instance.botId}.gbai`, `${min.instance.botId}.gbkb`, 'assets', answer.content);
|
const path = DialogKeywords.getGBAIPath(min.botId,`gbkb`);
|
||||||
|
const url = urlJoin('kb', path, 'assets', answer.content);
|
||||||
await this.playUrl(min, min.conversationalService, step, url, channel);
|
await this.playUrl(min, min.conversationalService, step, url, channel);
|
||||||
} else if (answer.format === '.md') {
|
} else if (answer.format === '.md') {
|
||||||
await min.conversationalService['playMarkdown'](min, answer.content, channel, step, min.conversationalService);
|
await min.conversationalService['playMarkdown'](min, answer.content, channel, step, min.conversationalService);
|
||||||
|
@ -679,20 +680,21 @@ export class KBService implements IGBKBService {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else if (file !== null && file.name.endsWith('.docx')) {
|
} else if (file !== null && file.name.endsWith('.docx')) {
|
||||||
const gbaiName = `${instance.botId}.gbai`;
|
const path = DialogKeywords.getGBAIPath(instance.botId, `gbkb`);
|
||||||
const gbkbName = `${instance.botId}.gbkb`;
|
const localName = Path.join('work', path, 'articles', file.name);
|
||||||
const localName = Path.join('work', gbaiName, gbkbName, 'articles', file.name);
|
|
||||||
const buffer = Fs.readFileSync(localName, { encoding: null });
|
const buffer = Fs.readFileSync(localName, { encoding: null });
|
||||||
var options = {
|
var options = {
|
||||||
buffer: buffer,
|
buffer: buffer,
|
||||||
convertImage: async image => {
|
convertImage: async image => {
|
||||||
const localName = Path.join(
|
const localName = Path.join(
|
||||||
'work',
|
'work',
|
||||||
gbaiName,
|
DialogKeywords.getGBAIPath(instance.botId),
|
||||||
'cache',
|
'cache',
|
||||||
`img-docx${GBAdminService.getRndReadableIdentifier()}.png`
|
`img-docx${GBAdminService.getRndReadableIdentifier()}.png`
|
||||||
);
|
);
|
||||||
const url = urlJoin(GBServer.globals.publicAddress, instance.botId, 'cache', Path.basename(localName));
|
const url = urlJoin(GBServer.globals.publicAddress,
|
||||||
|
DialogKeywords.getGBAIPath(instance.botId).replace(/\.[^/.]+$/, "")
|
||||||
|
, 'cache', Path.basename(localName));
|
||||||
const buffer = await image.read();
|
const buffer = await image.read();
|
||||||
Fs.writeFileSync(localName, buffer, { encoding: null });
|
Fs.writeFileSync(localName, buffer, { encoding: null });
|
||||||
return { src: url };
|
return { src: url };
|
||||||
|
@ -994,11 +996,11 @@ export class KBService implements IGBKBService {
|
||||||
|
|
||||||
GBLog.info(`[GBDeployer] Start Bot Server Side Rendering... ${localPath}`);
|
GBLog.info(`[GBDeployer] Start Bot Server Side Rendering... ${localPath}`);
|
||||||
const html = await GBSSR.getHTML(min);
|
const html = await GBSSR.getHTML(min);
|
||||||
const path = Path.join(
|
let path = DialogKeywords.getGBAIPath(min.botId,`gbui`);
|
||||||
|
path = Path.join(
|
||||||
process.env.PWD,
|
process.env.PWD,
|
||||||
'work',
|
'work',
|
||||||
`${min.instance.botId}.gbai`,
|
path,
|
||||||
`${min.instance.botId}.gbui`,
|
|
||||||
'index.html'
|
'index.html'
|
||||||
);
|
);
|
||||||
GBLogEx.info(min, `[GBDeployer] Saving SSR HTML in ${path}.`);
|
GBLogEx.info(min, `[GBDeployer] Saving SSR HTML in ${path}.`);
|
||||||
|
@ -1044,9 +1046,10 @@ export class KBService implements IGBKBService {
|
||||||
if (channel === 'whatsapp') {
|
if (channel === 'whatsapp') {
|
||||||
await min.conversationalService.sendFile(min, step, null, answer.content, '');
|
await min.conversationalService.sendFile(min, step, null, answer.content, '');
|
||||||
} else {
|
} else {
|
||||||
|
const path = DialogKeywords.getGBAIPath(min.botId, `gbkb`);
|
||||||
await conversationalService.sendEvent(min, step, 'play', {
|
await conversationalService.sendEvent(min, step, 'play', {
|
||||||
playerType: 'video',
|
playerType: 'video',
|
||||||
data: urlJoin(`${min.instance.botId}.gbai`, `${min.instance.botId}.gbkb`, 'videos', answer.content)
|
data: urlJoin(path, 'videos', answer.content)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue