new(basic.gblib): DEV_GBAI introduced to share a .gbdata among dev. team.
This commit is contained in:
parent
0ef0fc01f5
commit
2de41ee250
9 changed files with 91 additions and 62 deletions
|
@ -94,7 +94,7 @@
|
||||||
"botframework-connector": "4.18.0",
|
"botframework-connector": "4.18.0",
|
||||||
"botlib": "3.0.9",
|
"botlib": "3.0.9",
|
||||||
"c3-chart-maker": "0.2.8",
|
"c3-chart-maker": "0.2.8",
|
||||||
"cd": "0.3.3",
|
"cd": "^0.3.3",
|
||||||
"chatgpt": "2.4.2",
|
"chatgpt": "2.4.2",
|
||||||
"chrome-remote-interface": "0.31.3",
|
"chrome-remote-interface": "0.31.3",
|
||||||
"cli-progress": "3.11.2",
|
"cli-progress": "3.11.2",
|
||||||
|
@ -128,6 +128,7 @@
|
||||||
"node-html-parser": "6.1.5",
|
"node-html-parser": "6.1.5",
|
||||||
"node-nlp": "4.26.1",
|
"node-nlp": "4.26.1",
|
||||||
"node-tesseract-ocr": "2.2.1",
|
"node-tesseract-ocr": "2.2.1",
|
||||||
|
"npm": "9.6.1",
|
||||||
"open": "8.4.0",
|
"open": "8.4.0",
|
||||||
"open-docxtemplater-image-module": "1.0.3",
|
"open-docxtemplater-image-module": "1.0.3",
|
||||||
"pdf-extraction": "1.0.2",
|
"pdf-extraction": "1.0.2",
|
||||||
|
|
|
@ -152,13 +152,17 @@ export class GBAdminService implements IGBAdminService {
|
||||||
}
|
}
|
||||||
await deployer['deployPackage2'](min, user, urlJoin(additionalPath, packageName));
|
await deployer['deployPackage2'](min, user, urlJoin(additionalPath, packageName));
|
||||||
} else {
|
} else {
|
||||||
const gbaiPath = DialogKeywords.getGBAIPath(min.instance.botId, null, packageName);
|
const folderName = text.split(' ')[2];
|
||||||
|
const packageType = Path.extname(folderName).substr(1);
|
||||||
|
const gbaiPath = DialogKeywords.getGBAIPath(min.instance.botId, packageType, null);
|
||||||
const localFolder = Path.join('work', gbaiPath);
|
const localFolder = Path.join('work', gbaiPath);
|
||||||
|
|
||||||
// .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.
|
||||||
|
const gbai = DialogKeywords.getGBAIPath(min.instance.botId);
|
||||||
await deployer['downloadFolder'](min, localFolder);
|
await deployer ['downloadFolder'](min,
|
||||||
|
Path.join('work', `${gbai}`),
|
||||||
|
Path.basename(localFolder));
|
||||||
await deployer['deployPackage2'](min, user, localFolder);
|
await deployer['deployPackage2'](min, user, localFolder);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1029,7 +1029,7 @@ export class DialogKeywords {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static getGBAIPath(botId, packageType = null, packageName = null) {
|
static getGBAIPath(botId, packageType = null, packageName = null) {
|
||||||
const gbai = `${botId}.gbai`;
|
let gbai = `${botId}.gbai`;
|
||||||
if (!packageType && !packageName) {
|
if (!packageType && !packageName) {
|
||||||
return GBConfigService.get('DEV_GBAI') ?
|
return GBConfigService.get('DEV_GBAI') ?
|
||||||
GBConfigService.get('DEV_GBAI') :
|
GBConfigService.get('DEV_GBAI') :
|
||||||
|
@ -1037,7 +1037,8 @@ export class DialogKeywords {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GBConfigService.get('DEV_GBAI')) {
|
if (GBConfigService.get('DEV_GBAI')) {
|
||||||
|
gbai = GBConfigService.get('DEV_GBAI');
|
||||||
|
botId = gbai.replace(/\.[^/.]+$/, "");
|
||||||
return urljoin(GBConfigService.get('DEV_GBAI'),
|
return urljoin(GBConfigService.get('DEV_GBAI'),
|
||||||
packageName ?
|
packageName ?
|
||||||
packageName :
|
packageName :
|
||||||
|
|
|
@ -511,7 +511,7 @@ export class SystemKeywords {
|
||||||
* Retrives a document from the drive, given a path and filename.
|
* Retrives a document from the drive, given a path and filename.
|
||||||
*/
|
*/
|
||||||
private async internalGetDocument(client: any, baseUrl: any, path: string, file: string) {
|
private async internalGetDocument(client: any, baseUrl: any, path: string, file: string) {
|
||||||
let res = await client.api(`${baseUrl}/drive/root:${path}:/children`).get();
|
let res = await client.api(`${baseUrl}/drive/root:/${path}:/children`).get();
|
||||||
|
|
||||||
let documents = res.value.filter(m => {
|
let documents = res.value.filter(m => {
|
||||||
return m.name.toLowerCase() === file.toLowerCase();
|
return m.name.toLowerCase() === file.toLowerCase();
|
||||||
|
|
|
@ -412,7 +412,7 @@ export class GBDeployer implements IGBDeployer {
|
||||||
|
|
||||||
const botId = min.instance.botId;
|
const botId = min.instance.botId;
|
||||||
const path = DialogKeywords.getGBAIPath(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}`);
|
||||||
const res = await client.api(url).get();
|
const res = await client.api(url).get();
|
||||||
|
@ -482,10 +482,10 @@ export class GBDeployer implements IGBDeployer {
|
||||||
|
|
||||||
// Retrieves all files in remote folder.
|
// Retrieves all files in remote folder.
|
||||||
|
|
||||||
const botId = min.instance.botId;
|
|
||||||
let path = DialogKeywords.getGBAIPath(min.botId);
|
let path = DialogKeywords.getGBAIPath(min.botId);
|
||||||
path = urlJoin(path, remotePath);
|
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}`);
|
||||||
|
|
||||||
|
|
|
@ -300,19 +300,32 @@ export class GBMinService {
|
||||||
|
|
||||||
const gbai = DialogKeywords.getGBAIPath(min.botId);
|
const gbai = DialogKeywords.getGBAIPath(min.botId);
|
||||||
let dir = `work/${gbai}/cache`;
|
let dir = `work/${gbai}/cache`;
|
||||||
|
const botId = gbai.replace(/\.[^/.]+$/, "");
|
||||||
|
|
||||||
if (!Fs.existsSync(dir)) {
|
if (!Fs.existsSync(dir)) {
|
||||||
mkdirp.sync(dir);
|
mkdirp.sync(dir);
|
||||||
}
|
}
|
||||||
dir = `${gbai}/profile`;
|
dir = `work/${gbai}/profile`;
|
||||||
if (!Fs.existsSync(dir)) {
|
if (!Fs.existsSync(dir)) {
|
||||||
mkdirp.sync(dir);
|
mkdirp.sync(dir);
|
||||||
}
|
}
|
||||||
dir = `${gbai}/uploads`;
|
dir = `work/${gbai}/uploads`;
|
||||||
if (!Fs.existsSync(dir)) {
|
if (!Fs.existsSync(dir)) {
|
||||||
mkdirp.sync(dir);
|
mkdirp.sync(dir);
|
||||||
}
|
}
|
||||||
dir = DialogKeywords.getGBAIPath(min.botId, `gbui`);
|
dir = `work/${gbai}/${botId}.gbkb`;
|
||||||
|
if (!Fs.existsSync(dir)) {
|
||||||
|
mkdirp.sync(dir);
|
||||||
|
}
|
||||||
|
dir = `work/${gbai}/${botId}.gbdialog`;
|
||||||
|
if (!Fs.existsSync(dir)) {
|
||||||
|
mkdirp.sync(dir);
|
||||||
|
}
|
||||||
|
dir = `work/${gbai}/${botId}.gbot`;
|
||||||
|
if (!Fs.existsSync(dir)) {
|
||||||
|
mkdirp.sync(dir);
|
||||||
|
}
|
||||||
|
dir = `work/${gbai}/${botId}.gbui`;
|
||||||
if (!Fs.existsSync(dir)) {
|
if (!Fs.existsSync(dir)) {
|
||||||
mkdirp.sync(dir);
|
mkdirp.sync(dir);
|
||||||
}
|
}
|
||||||
|
@ -840,7 +853,7 @@ export class GBMinService {
|
||||||
|
|
||||||
// Default activity processing and handler.
|
// Default activity processing and handler.
|
||||||
|
|
||||||
await adapter['processActivity'](req, res, async context => {
|
const handler = async context => {
|
||||||
// Handle activity text issues.
|
// Handle activity text issues.
|
||||||
|
|
||||||
if (!context.activity.text) {
|
if (!context.activity.text) {
|
||||||
|
@ -1035,7 +1048,19 @@ export class GBMinService {
|
||||||
|
|
||||||
await step.beginDialog('/ask', { isReturning: true });
|
await step.beginDialog('/ask', { isReturning: true });
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
await adapter['processActivity'](req, res, handler);
|
||||||
|
} catch (error) {
|
||||||
|
if (error.code === 401){
|
||||||
|
GBLog.error('Calling processActivity due to Signing Key could not be retrieved error.');
|
||||||
|
await adapter['processActivity'](req, res, handler);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -92,7 +92,7 @@ export class GBSSR {
|
||||||
'tiqcdn'
|
'tiqcdn'
|
||||||
];
|
];
|
||||||
|
|
||||||
public static preparePuppeteer(profilePath){
|
public static preparePuppeteer(profilePath) {
|
||||||
let args = [
|
let args = [
|
||||||
'--check-for-update-interval=2592000',
|
'--check-for-update-interval=2592000',
|
||||||
'--disable-accelerated-2d-canvas',
|
'--disable-accelerated-2d-canvas',
|
||||||
|
@ -128,7 +128,7 @@ export class GBSSR {
|
||||||
public static async createBrowser(profilePath): Promise<any> {
|
public static async createBrowser(profilePath): Promise<any> {
|
||||||
const opts = this.preparePuppeteer(profilePath);
|
const opts = this.preparePuppeteer(profilePath);
|
||||||
puppeteer.use(hidden());
|
puppeteer.use(hidden());
|
||||||
const browser = await puppeteer.launch( opts );
|
const browser = await puppeteer.launch(opts);
|
||||||
return browser;
|
return browser;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -279,44 +279,38 @@ export class GBSSR {
|
||||||
|
|
||||||
// Reads from static HTML when a bot is crawling.
|
// Reads from static HTML when a bot is crawling.
|
||||||
|
|
||||||
const botId = req.originalUrl ? req.originalUrl.substr(1) : GBServer.globals.minInstances[0].botId; // TODO: Get only bot.
|
const botId =
|
||||||
let min: GBMinInstance = req.url === '/'?
|
req.originalUrl || req.originalUrl === '/' ? req.originalUrl.substr(1) : GBServer.globals.minInstances[0].botId;
|
||||||
GBServer.globals.minInstances[0]:
|
let min: GBMinInstance =
|
||||||
GBServer.globals.minInstances.filter(p => p.instance.botId === botId)[0];
|
req.url === '/'
|
||||||
|
? GBServer.globals.minInstances[0]
|
||||||
let path = DialogKeywords.getGBAIPath(min.botId,`gbui`);
|
: GBServer.globals.minInstances.filter(p => p.instance.botId === botId)[0];
|
||||||
|
|
||||||
|
let path = DialogKeywords.getGBAIPath(botId, `gbui`);
|
||||||
|
|
||||||
if (min && req.originalUrl && prerender && exclude) {
|
if (min && req.originalUrl && prerender && exclude) {
|
||||||
path = Path.join(
|
path = Path.join(process.env.PWD, 'work', path, 'index.html');
|
||||||
process.env.PWD,
|
|
||||||
'work',
|
|
||||||
path,
|
|
||||||
'index.html'
|
|
||||||
);
|
|
||||||
const html = Fs.readFileSync(path, 'utf8');
|
const html = Fs.readFileSync(path, 'utf8');
|
||||||
res.status(200).send(html);
|
res.status(200).send(html);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
path = Path.join(
|
path = Path.join(
|
||||||
process.env.PWD,
|
process.env.PWD,
|
||||||
GBDeployer.deployFolder,
|
GBDeployer.deployFolder,
|
||||||
GBMinService.uiPackage,
|
GBMinService.uiPackage,
|
||||||
'build',
|
'build',
|
||||||
min ? `index.html` : req.url
|
min ? `index.html` : req.url
|
||||||
);
|
);
|
||||||
if (Fs.existsSync(path)) {
|
if (Fs.existsSync(path)) {
|
||||||
if (min){
|
if (min) {
|
||||||
let html = Fs.readFileSync(path, 'utf8');
|
let html = Fs.readFileSync(path, 'utf8');
|
||||||
html = html.replace(/\{botId\}/gi, min.botId);
|
html = html.replace(/\{botId\}/gi, min.botId);
|
||||||
html = html.replace(/\{theme\}/gi, min.instance.theme);
|
html = html.replace(/\{theme\}/gi, min.instance.theme);
|
||||||
html = html.replace(/\{title\}/gi, min.instance.title);
|
html = html.replace(/\{title\}/gi, min.instance.title);
|
||||||
res.send(html).end();
|
res.send(html).end();
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
res.sendFile(path);
|
res.sendFile(path);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
GBLogEx.info(min, `HTTP 404: ${req.url}.`);
|
GBLogEx.info(min, `HTTP 404: ${req.url}.`);
|
||||||
|
|
|
@ -608,27 +608,31 @@ export class WhatsappDirectLine extends GBService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public inputMessage(client, conversationId: string, text: string, from, fromName: string, group, attachments: File) {
|
public inputMessage(client, conversationId: string, text: string, from, fromName: string, group, attachments: File) {
|
||||||
return client.apis.Conversations.Conversations_PostActivity({
|
try {
|
||||||
conversationId: conversationId,
|
return client.apis.Conversations.Conversations_PostActivity({
|
||||||
activity: {
|
conversationId: conversationId,
|
||||||
textFormat: 'plain',
|
activity: {
|
||||||
text: text,
|
textFormat: 'plain',
|
||||||
type: 'message',
|
text: text,
|
||||||
mobile: from,
|
type: 'message',
|
||||||
group: group,
|
mobile: from,
|
||||||
attachments: attachments,
|
group: group,
|
||||||
|
attachments: attachments,
|
||||||
|
|
||||||
// Use from container to transport information to GBMinService.receiver.
|
// Use from container to transport information to GBMinService.receiver.
|
||||||
|
|
||||||
from: {
|
from: {
|
||||||
id: from,
|
id: from,
|
||||||
name: fromName,
|
name: fromName,
|
||||||
channelIdEx: 'whatsapp',
|
channelIdEx: 'whatsapp',
|
||||||
group: group
|
group: group
|
||||||
},
|
},
|
||||||
replyToId: from
|
replyToId: from
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} catch (e) {
|
||||||
|
GBLog.error(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public pollMessages(client, conversationId, from, fromName) {
|
public pollMessages(client, conversationId, from, fromName) {
|
||||||
|
@ -1024,9 +1028,7 @@ export class WhatsappDirectLine extends GBService {
|
||||||
activeMin = GBServer.globals.minInstances.filter(p => p.instance.botId === botId)[0];
|
activeMin = GBServer.globals.minInstances.filter(p => p.instance.botId === botId)[0];
|
||||||
await (activeMin as any).whatsAppDirectLine.received(req, res);
|
await (activeMin as any).whatsAppDirectLine.received(req, res);
|
||||||
return; // EXIT HERE.
|
return; // EXIT HERE.
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
GBLog.warn(`Group: ${group} not associated with botId:${botId}.`);
|
GBLog.warn(`Group: ${group} not associated with botId:${botId}.`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
10
src/app.ts
10
src/app.ts
|
@ -98,18 +98,20 @@ export class GBServer {
|
||||||
GBServer.globals.debuggers = [];
|
GBServer.globals.debuggers = [];
|
||||||
GBServer.globals.indexSemaphore = new Mutex();
|
GBServer.globals.indexSemaphore = new Mutex();
|
||||||
|
|
||||||
|
|
||||||
server.use(bodyParser.json());
|
server.use(bodyParser.json());
|
||||||
server.use(bodyParser.urlencoded({ extended: true }));
|
server.use(bodyParser.urlencoded({ extended: true }));
|
||||||
|
|
||||||
process.on('unhandledRejection', (err, p) => {
|
process.on('unhandledRejection', (err, p) => {
|
||||||
GBLog.error(`UNHANDLED_REJECTION(promises): ${err.toString()} ${err['stack']?'\n'+err['stack']:''}`);
|
GBLog.error(`UNHANDLED_REJECTION(promises): ${err.toString()} ${err['stack'] ? '\n' + err['stack'] : ''}`);
|
||||||
|
if (err['response']?.obj?.httpStatusCode === 404) {
|
||||||
|
GBLog.warn(`Check reverse proxy: ${process.env.BOT_URL} as it seems to be invalid.`);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
process.on('uncaughtException', (err, p) => {
|
process.on('uncaughtException', (err, p) => {
|
||||||
GBLog.error(`UNCAUGHT_EXCEPTION: ${err.toString()} ${err['stack']?'\n'+err['stack']:''}`);
|
GBLog.error(`UNCAUGHT_EXCEPTION: ${err.toString()} ${err['stack'] ? '\n' + err['stack'] : ''}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Creates working directory.
|
// Creates working directory.
|
||||||
|
|
||||||
process.env.PWD = process.cwd();
|
process.env.PWD = process.cwd();
|
||||||
|
|
Loading…
Add table
Reference in a new issue