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 { GBServer } from '../../../src/app.js';
|
||||
import { GuaribasUser } from '../../security.gbapp/models/index.js';
|
||||
import { DialogKeywords } from '../../basic.gblib/services/DialogKeywords.js';
|
||||
|
||||
/**
|
||||
* Services for server administration.
|
||||
|
@ -129,10 +130,12 @@ export class GBAdminService implements IGBAdminService {
|
|||
}
|
||||
|
||||
public static async undeployPackageCommand(text: string, min: GBMinInstance) {
|
||||
|
||||
const packageName = text.split(' ')[1];
|
||||
const importer = new GBImporter(min.core);
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -149,15 +152,13 @@ export class GBAdminService implements IGBAdminService {
|
|||
}
|
||||
await deployer['deployPackage2'](min, user, urlJoin(additionalPath, packageName));
|
||||
} else {
|
||||
const siteName = text.split(' ')[1];
|
||||
const folderName = text.split(' ')[2];
|
||||
|
||||
const localFolder = Path.join('work', `${min.instance.botId}.gbai`, Path.basename(folderName));
|
||||
const gbaiPath = DialogKeywords.getGBAIPath(min.instance.botId, null, packageName);
|
||||
const localFolder = Path.join('work', gbaiPath);
|
||||
|
||||
// .gbot packages are handled using storage API, so no download
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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`);
|
||||
|
||||
await ChartServices.screenshot(definition, localName);
|
||||
|
@ -204,28 +204,28 @@ export class DialogKeywords {
|
|||
*
|
||||
* @example EXIT
|
||||
*/
|
||||
public async exit({}) {}
|
||||
public async exit({ }) { }
|
||||
|
||||
/**
|
||||
* Get active tasks.
|
||||
*
|
||||
* @example list = ACTIVE TASKS
|
||||
*/
|
||||
public async getActiveTasks({ pid }) {}
|
||||
public async getActiveTasks({ pid }) { }
|
||||
|
||||
/**
|
||||
* Creates a new deal.
|
||||
*
|
||||
* @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.
|
||||
*
|
||||
* @example list = FIND CONTACT "Sandra"
|
||||
*/
|
||||
public async fndContact({ pid, name }) {}
|
||||
public async fndContact({ pid, name }) { }
|
||||
|
||||
public getContentLocaleWithCulture(contentLocale) {
|
||||
switch (contentLocale) {
|
||||
|
@ -676,7 +676,7 @@ export class DialogKeywords {
|
|||
* @example MENU
|
||||
*
|
||||
*/
|
||||
public async showMenu({}) {
|
||||
public async showMenu({ }) {
|
||||
// https://github.com/GeneralBots/BotServer/issues/237
|
||||
// return await beginDialog('/menu');
|
||||
}
|
||||
|
@ -783,7 +783,7 @@ export class DialogKeywords {
|
|||
|
||||
let { baseUrl, client } = await GBDeployer.internalGetDriveClient(min);
|
||||
const botId = min.instance.botId;
|
||||
const path = DialogKeywords.getGBDataPath(botId);
|
||||
const path = DialogKeywords.getGBAIPath(botId);
|
||||
let url = `${baseUrl}/drive/root:/${path}:/children`;
|
||||
|
||||
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}`);
|
||||
}
|
||||
}
|
||||
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')?
|
||||
GBConfigService.get('GBDIALOG_GBDATABOT'):
|
||||
urljoin(`${botId}.gbai`, `${botId}.gbdata`);
|
||||
if (GBConfigService.get('DEV_GBAI')) {
|
||||
|
||||
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;
|
||||
|
||||
if (element) {
|
||||
const gbaiName = `${min.botId}.gbai`;
|
||||
const gbaiName = DialogKeywords.getGBAIPath(min.botId);
|
||||
const localName = Path.join('work', gbaiName, 'cache', `img${GBAdminService.getRndReadableIdentifier()}.jpg`);
|
||||
await element.screenshot({ path: localName, fullPage: true });
|
||||
|
||||
|
@ -1130,14 +1147,16 @@ export class DialogKeywords {
|
|||
|
||||
await min.conversationalService['playMarkdown'](min, md, DialogKeywords.getChannel(), mobile);
|
||||
} else {
|
||||
|
||||
const gbaiName = DialogKeywords.getGBAIPath(min.botId, `gbkb`);
|
||||
|
||||
GBLog.info(`BASIC: Sending the file ${filename} to mobile ${mobile}.`);
|
||||
let url: string;
|
||||
if (!filename.startsWith('https://')) {
|
||||
url = urlJoin(
|
||||
GBServer.globals.publicAddress,
|
||||
'kb',
|
||||
`${min.botId}.gbai`,
|
||||
`${min.botId}.gbkb`,
|
||||
gbaiName,
|
||||
'assets',
|
||||
filename
|
||||
);
|
||||
|
@ -1160,7 +1179,7 @@ export class DialogKeywords {
|
|||
const data = img.replace(/^data:image\/\w+;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`);
|
||||
Fs.writeFileSync(localName, buf, { encoding: null });
|
||||
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.
|
||||
const fullFilename = urlJoin(folder, filename);
|
||||
if (process.env.GBDIALOG_HOTSWAP) {
|
||||
if (process.env.DEV_HOTSWAP) {
|
||||
Fs.watchFile(fullFilename, async () => {
|
||||
await this.translateBASIC(fullFilename, mainName, min);
|
||||
const parsedCode: string = Fs.readFileSync(jsfile, 'utf8');
|
||||
|
@ -371,7 +371,8 @@ export class GBVMService extends GBService {
|
|||
}
|
||||
|
||||
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`);
|
||||
|
||||
let code = min.sandBoxMap[text];
|
||||
|
|
|
@ -90,9 +90,9 @@ export class ImageProcessingServices {
|
|||
});
|
||||
|
||||
const botId = min.instance.botId;
|
||||
const gbaiName = `${botId}.gbai`;
|
||||
const path = DialogKeywords.getGBAIPath(min.botId);
|
||||
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));
|
||||
img.toFile(localName);
|
||||
|
||||
|
|
|
@ -233,7 +233,7 @@ export class SystemKeywords {
|
|||
// headers.
|
||||
|
||||
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 page = await browser.newPage();
|
||||
|
||||
|
@ -326,7 +326,7 @@ export class SystemKeywords {
|
|||
|
||||
let { baseUrl, client } = await GBDeployer.internalGetDriveClient(min);
|
||||
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`);
|
||||
|
||||
// Performs the conversion operation.
|
||||
|
@ -489,7 +489,7 @@ export class SystemKeywords {
|
|||
let { baseUrl, client } = await GBDeployer.internalGetDriveClient(min);
|
||||
|
||||
const botId = min.instance.botId;
|
||||
const path = DialogKeywords.getGBDataPath(botId);
|
||||
const path = DialogKeywords.getGBAIPath(botId, 'gbdata');
|
||||
|
||||
address = address.indexOf(':') !== -1 ? address : address + ':' + address;
|
||||
|
||||
|
@ -535,7 +535,7 @@ export class SystemKeywords {
|
|||
GBLog.info(`BASIC: Saving '${file}' (SAVE file).`);
|
||||
let { baseUrl, client } = await GBDeployer.internalGetDriveClient(min);
|
||||
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.
|
||||
|
||||
|
@ -569,7 +569,7 @@ export class SystemKeywords {
|
|||
GBLog.info(`BASIC: Saving '${file}' (SAVE). Args: ${args.join(',')}.`);
|
||||
let { baseUrl, client } = await GBDeployer.internalGetDriveClient(min);
|
||||
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 sheets = await client.api(`${baseUrl}/drive/items/${document.id}/workbook/worksheets`).get();
|
||||
|
@ -622,8 +622,8 @@ export class SystemKeywords {
|
|||
} else {
|
||||
GBLog.info(`BASIC: GET '${addressOrHeaders}' in '${file}'.`);
|
||||
let { baseUrl, client } = await GBDeployer.internalGetDriveClient(min);
|
||||
const botId = min.instance.botId;
|
||||
const path = DialogKeywords.getGBDataPath(botId);
|
||||
const botId = min.instance.botId;''
|
||||
const path = DialogKeywords.getGBAIPath(botId, 'gbdata');
|
||||
|
||||
let document = await this.internalGetDocument(client, baseUrl, path, file);
|
||||
|
||||
|
@ -695,7 +695,7 @@ export class SystemKeywords {
|
|||
args.shift();
|
||||
|
||||
const botId = min.instance.botId;
|
||||
const path = DialogKeywords.getGBDataPath(botId);
|
||||
const path = DialogKeywords.getGBAIPath(botId, 'gbdata');
|
||||
|
||||
// MAX LINES property.
|
||||
|
||||
|
@ -751,7 +751,7 @@ export class SystemKeywords {
|
|||
rows[i] = result[i];
|
||||
}
|
||||
} 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 url = file['@microsoft.graph.downloadUrl'];
|
||||
const response = await fetch(url);
|
||||
|
@ -1101,7 +1101,8 @@ export class SystemKeywords {
|
|||
const { min, user, params } = await DialogKeywords.getProcessInfo(pid);
|
||||
let { baseUrl, client } = await GBDeployer.internalGetDriveClient(min);
|
||||
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
|
||||
// one of them.
|
||||
|
@ -1150,7 +1151,8 @@ export class SystemKeywords {
|
|||
public async shareFolder({ pid, folder, email, message }) {
|
||||
const { min, user, params } = await DialogKeywords.getProcessInfo(pid);
|
||||
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();
|
||||
|
||||
|
@ -1188,7 +1190,7 @@ export class SystemKeywords {
|
|||
|
||||
// Determines full path at source and destination.
|
||||
|
||||
const root = DialogKeywords.getGBDataPath(botId);
|
||||
const root = DialogKeywords.getGBAIPath(botId, 'gbdrive');
|
||||
const srcPath = urlJoin(root, src);
|
||||
const dstPath = urlJoin(root, dest);
|
||||
|
||||
|
@ -1248,10 +1250,10 @@ export class SystemKeywords {
|
|||
dest = dest.replace(/\\/gi, '/');
|
||||
|
||||
// Determines full path at source and destination.
|
||||
|
||||
const root = urlJoin(`/${botId}.gbai/${botId}.gbdrive`);
|
||||
const path = DialogKeywords.getGBAIPath(min.botId,`gbdrive`);
|
||||
const root = path;
|
||||
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
|
||||
// need to be created.
|
||||
|
@ -1442,7 +1444,7 @@ export class SystemKeywords {
|
|||
public async fill({ pid, templateName, data }) {
|
||||
const { min, user } = await DialogKeywords.getProcessInfo(pid);
|
||||
const botId = min.instance.botId;
|
||||
const gbaiName = `${botId}.gbai`;
|
||||
const gbaiName = DialogKeywords.getGBAIPath(botId, 'gbdata');
|
||||
let localName;
|
||||
|
||||
// Downloads template from .gbdrive.
|
||||
|
@ -1599,7 +1601,7 @@ export class SystemKeywords {
|
|||
|
||||
const { min, user, params } = await DialogKeywords.getProcessInfo(pid);
|
||||
const botId = min.instance.botId;
|
||||
const path = DialogKeywords.getGBDataPath(botId);
|
||||
const path = DialogKeywords.getGBAIPath(botId, 'gbdata');
|
||||
|
||||
// MAX LINES property.
|
||||
|
||||
|
|
|
@ -323,7 +323,7 @@ export class WebAutomationServices {
|
|||
const page = WebAutomationServices.getPageByHandle(handle);
|
||||
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`);
|
||||
|
||||
await page.screenshot({ path: localName });
|
||||
|
@ -412,8 +412,8 @@ export class WebAutomationServices {
|
|||
folder = folder.replace(/\\/gi, '/');
|
||||
|
||||
// Determines full path at source and destination.
|
||||
|
||||
const root = urlJoin(`/${botId}.gbai/${botId}.gbdrive`);
|
||||
const path = DialogKeywords.getGBAIPath(min.botId,`gbdrive`);
|
||||
const root = path;
|
||||
const dstPath = urlJoin(root, folder, filename);
|
||||
|
||||
// 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 MicrosoftGraph from '@microsoft/microsoft-graph-client';
|
||||
import { GBLogEx } from './GBLogEx.js';
|
||||
import { DialogKeywords } from '../../basic.gblib/services/DialogKeywords.js';
|
||||
|
||||
/**
|
||||
* Deployer service for bots, themes, ai and more.
|
||||
|
@ -410,7 +411,7 @@ export class GBDeployer implements IGBDeployer {
|
|||
// Retrieves all files in .bot folder.
|
||||
|
||||
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`;
|
||||
|
||||
GBLog.info(`Loading .gbot from Excel: ${url}`);
|
||||
|
@ -482,7 +483,8 @@ export class GBDeployer implements IGBDeployer {
|
|||
// Retrieves all files in remote folder.
|
||||
|
||||
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`;
|
||||
|
||||
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.
|
||||
*/
|
||||
public static mountGBKBAssets(packageName: any, botId: string, filename: string) {
|
||||
const gbaiName = DialogKeywords.getGBAIPath(botId);
|
||||
|
||||
// Servers menu assets.
|
||||
|
||||
GBServer.globals.server.use(
|
||||
`/kb/${botId}.gbai/${packageName}/subjects`,
|
||||
`/kb/${gbaiName}/${packageName}/subjects`,
|
||||
express.static(urlJoin(filename, 'subjects'))
|
||||
);
|
||||
|
||||
// Servers all other assets in .gbkb folders.
|
||||
|
||||
const gbaiName = `${botId}.gbai`;
|
||||
GBServer.globals.server.use(
|
||||
`/kb/${gbaiName}/${packageName}/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'))
|
||||
);
|
||||
|
||||
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 Path from 'path';
|
||||
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.
|
||||
|
@ -280,37 +281,38 @@ export class GBMinService {
|
|||
|
||||
// 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)) {
|
||||
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)) {
|
||||
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)) {
|
||||
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)) {
|
||||
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)) {
|
||||
mkdirp.sync(dir);
|
||||
}
|
||||
dir = `work/${min.botId}.gbai/profile`;
|
||||
dir = `${gbai}/profile`;
|
||||
if (!Fs.existsSync(dir)) {
|
||||
mkdirp.sync(dir);
|
||||
}
|
||||
dir = `work/${min.botId}.gbai/uploads`;
|
||||
dir = `${gbai}/uploads`;
|
||||
if (!Fs.existsSync(dir)) {
|
||||
mkdirp.sync(dir);
|
||||
}
|
||||
dir = `work/${min.botId}.gbai/${min.botId}.gbui`;
|
||||
dir = DialogKeywords.getGBAIPath(min.botId, `gbui`);
|
||||
if (!Fs.existsSync(dir)) {
|
||||
mkdirp.sync(dir);
|
||||
}
|
||||
|
@ -925,7 +927,8 @@ export class GBMinService {
|
|||
ps: 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`;
|
||||
|
||||
Fs.writeFileSync(path.join(folder, filename), data);
|
||||
|
@ -1080,7 +1083,8 @@ export class GBMinService {
|
|||
private static async downloadAttachmentAndWrite(attachment) {
|
||||
const url = attachment.contentUrl;
|
||||
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;
|
||||
if (url.startsWith('data:')) {
|
||||
|
|
|
@ -49,6 +49,7 @@ import { GBLogEx } from './GBLogEx.js';
|
|||
import urlJoin from 'url-join';
|
||||
import { GBDeployer } from './GBDeployer.js';
|
||||
import { GBMinService } from './GBMinService.js';
|
||||
import { DialogKeywords } from '../../basic.gblib/services/DialogKeywords.js';
|
||||
const puppeteer = require('puppeteer-extra');
|
||||
const hidden = require('puppeteer-extra-plugin-stealth');
|
||||
const { executablePath } = require('puppeteer');
|
||||
|
@ -283,12 +284,13 @@ export class GBSSR {
|
|||
GBServer.globals.minInstances[0]:
|
||||
GBServer.globals.minInstances.filter(p => p.instance.botId === botId)[0];
|
||||
|
||||
const path = DialogKeywords.getGBAIPath(min.botId,`gbui`);
|
||||
|
||||
if (min && req.originalUrl && prerender && exclude) {
|
||||
const path = Path.join(
|
||||
process.env.PWD,
|
||||
'work',
|
||||
`${min.instance.botId}.gbai`,
|
||||
`${min.instance.botId}.gbui`,
|
||||
path,
|
||||
'index.html'
|
||||
);
|
||||
const html = Fs.readFileSync(path, 'utf8');
|
||||
|
|
|
@ -73,6 +73,7 @@ import { min } from 'lodash';
|
|||
import { GBAdminService } from '../../admin.gbapp/services/GBAdminService.js';
|
||||
import { text } from 'body-parser';
|
||||
import { GBVMService } from '../../basic.gblib/services/GBVMService.js';
|
||||
import { DialogKeywords } from 'packages/basic.gblib/services/DialogKeywords.js';
|
||||
|
||||
/**
|
||||
* Result for quey on KB data.
|
||||
|
@ -528,10 +529,9 @@ export class KBService implements IGBKBService {
|
|||
const isBasic = answer.toLowerCase().startsWith('/basic');
|
||||
if (/TALK\s*\".*\"/gi.test(answer) || isBasic) {
|
||||
const code = isBasic ? answer.substr(6) : answer;
|
||||
const gbaiName = `${min.instance.botId}.gbai`;
|
||||
const gbdialogName = `${min.instance.botId}.gbdialog`;
|
||||
const path = DialogKeywords.getGBAIPath(min.botId,`gbdialog`);
|
||||
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 });
|
||||
answer = scriptName;
|
||||
|
||||
|
@ -603,18 +603,19 @@ export class KBService implements IGBKBService {
|
|||
answer.content.endsWith('.xls') ||
|
||||
answer.content.endsWith('.xlsx')
|
||||
) {
|
||||
const path = DialogKeywords.getGBAIPath(min.botId, `gbkb`);
|
||||
const doc = urlJoin(
|
||||
GBServer.globals.publicAddress,
|
||||
'kb',
|
||||
`${min.instance.botId}.gbai`,
|
||||
`${min.instance.botId}.gbkb`,
|
||||
path,
|
||||
'assets',
|
||||
answer.content
|
||||
);
|
||||
const url = `http://view.officeapps.live.com/op/view.aspx?src=${doc}`;
|
||||
await this.playUrl(min, min.conversationalService, step, url, channel);
|
||||
} 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);
|
||||
} else if (answer.format === '.md') {
|
||||
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')) {
|
||||
const gbaiName = `${instance.botId}.gbai`;
|
||||
const gbkbName = `${instance.botId}.gbkb`;
|
||||
const localName = Path.join('work', gbaiName, gbkbName, 'articles', file.name);
|
||||
const path = DialogKeywords.getGBAIPath(instance.botId, `gbkb`);
|
||||
const localName = Path.join('work', path, 'articles', file.name);
|
||||
const buffer = Fs.readFileSync(localName, { encoding: null });
|
||||
var options = {
|
||||
buffer: buffer,
|
||||
convertImage: async image => {
|
||||
const localName = Path.join(
|
||||
'work',
|
||||
gbaiName,
|
||||
DialogKeywords.getGBAIPath(instance.botId),
|
||||
'cache',
|
||||
`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();
|
||||
Fs.writeFileSync(localName, buffer, { encoding: null });
|
||||
return { src: url };
|
||||
|
@ -994,11 +996,11 @@ export class KBService implements IGBKBService {
|
|||
|
||||
GBLog.info(`[GBDeployer] Start Bot Server Side Rendering... ${localPath}`);
|
||||
const html = await GBSSR.getHTML(min);
|
||||
const path = Path.join(
|
||||
let path = DialogKeywords.getGBAIPath(min.botId,`gbui`);
|
||||
path = Path.join(
|
||||
process.env.PWD,
|
||||
'work',
|
||||
`${min.instance.botId}.gbai`,
|
||||
`${min.instance.botId}.gbui`,
|
||||
path,
|
||||
'index.html'
|
||||
);
|
||||
GBLogEx.info(min, `[GBDeployer] Saving SSR HTML in ${path}.`);
|
||||
|
@ -1044,9 +1046,10 @@ export class KBService implements IGBKBService {
|
|||
if (channel === 'whatsapp') {
|
||||
await min.conversationalService.sendFile(min, step, null, answer.content, '');
|
||||
} else {
|
||||
const path = DialogKeywords.getGBAIPath(min.botId, `gbkb`);
|
||||
await conversationalService.sendEvent(min, step, 'play', {
|
||||
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