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",
|
||||
"botlib": "3.0.9",
|
||||
"c3-chart-maker": "0.2.8",
|
||||
"cd": "0.3.3",
|
||||
"cd": "^0.3.3",
|
||||
"chatgpt": "2.4.2",
|
||||
"chrome-remote-interface": "0.31.3",
|
||||
"cli-progress": "3.11.2",
|
||||
|
@ -128,6 +128,7 @@
|
|||
"node-html-parser": "6.1.5",
|
||||
"node-nlp": "4.26.1",
|
||||
"node-tesseract-ocr": "2.2.1",
|
||||
"npm": "9.6.1",
|
||||
"open": "8.4.0",
|
||||
"open-docxtemplater-image-module": "1.0.3",
|
||||
"pdf-extraction": "1.0.2",
|
||||
|
|
|
@ -152,13 +152,17 @@ export class GBAdminService implements IGBAdminService {
|
|||
}
|
||||
await deployer['deployPackage2'](min, user, urlJoin(additionalPath, packageName));
|
||||
} 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);
|
||||
|
||||
// .gbot packages are handled using storage API, so no download
|
||||
// of local resources is required.
|
||||
|
||||
await deployer['downloadFolder'](min, localFolder);
|
||||
const gbai = DialogKeywords.getGBAIPath(min.instance.botId);
|
||||
await deployer ['downloadFolder'](min,
|
||||
Path.join('work', `${gbai}`),
|
||||
Path.basename(localFolder));
|
||||
await deployer['deployPackage2'](min, user, localFolder);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1029,7 +1029,7 @@ export class DialogKeywords {
|
|||
}
|
||||
}
|
||||
static getGBAIPath(botId, packageType = null, packageName = null) {
|
||||
const gbai = `${botId}.gbai`;
|
||||
let gbai = `${botId}.gbai`;
|
||||
if (!packageType && !packageName) {
|
||||
return GBConfigService.get('DEV_GBAI') ?
|
||||
GBConfigService.get('DEV_GBAI') :
|
||||
|
@ -1037,7 +1037,8 @@ export class DialogKeywords {
|
|||
}
|
||||
|
||||
if (GBConfigService.get('DEV_GBAI')) {
|
||||
|
||||
gbai = GBConfigService.get('DEV_GBAI');
|
||||
botId = gbai.replace(/\.[^/.]+$/, "");
|
||||
return urljoin(GBConfigService.get('DEV_GBAI'),
|
||||
packageName ?
|
||||
packageName :
|
||||
|
|
|
@ -511,7 +511,7 @@ export class SystemKeywords {
|
|||
* Retrives a document from the drive, given a path and filename.
|
||||
*/
|
||||
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 => {
|
||||
return m.name.toLowerCase() === file.toLowerCase();
|
||||
|
|
|
@ -412,7 +412,7 @@ export class GBDeployer implements IGBDeployer {
|
|||
|
||||
const botId = min.instance.botId;
|
||||
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}`);
|
||||
const res = await client.api(url).get();
|
||||
|
@ -482,10 +482,10 @@ export class GBDeployer implements IGBDeployer {
|
|||
|
||||
// Retrieves all files in remote folder.
|
||||
|
||||
const botId = min.instance.botId;
|
||||
|
||||
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}`);
|
||||
|
||||
|
|
|
@ -300,19 +300,32 @@ export class GBMinService {
|
|||
|
||||
const gbai = DialogKeywords.getGBAIPath(min.botId);
|
||||
let dir = `work/${gbai}/cache`;
|
||||
const botId = gbai.replace(/\.[^/.]+$/, "");
|
||||
|
||||
if (!Fs.existsSync(dir)) {
|
||||
mkdirp.sync(dir);
|
||||
}
|
||||
dir = `${gbai}/profile`;
|
||||
dir = `work/${gbai}/profile`;
|
||||
if (!Fs.existsSync(dir)) {
|
||||
mkdirp.sync(dir);
|
||||
}
|
||||
dir = `${gbai}/uploads`;
|
||||
dir = `work/${gbai}/uploads`;
|
||||
if (!Fs.existsSync(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)) {
|
||||
mkdirp.sync(dir);
|
||||
}
|
||||
|
@ -840,7 +853,7 @@ export class GBMinService {
|
|||
|
||||
// Default activity processing and handler.
|
||||
|
||||
await adapter['processActivity'](req, res, async context => {
|
||||
const handler = async context => {
|
||||
// Handle activity text issues.
|
||||
|
||||
if (!context.activity.text) {
|
||||
|
@ -1035,7 +1048,19 @@ export class GBMinService {
|
|||
|
||||
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'
|
||||
];
|
||||
|
||||
public static preparePuppeteer(profilePath){
|
||||
public static preparePuppeteer(profilePath) {
|
||||
let args = [
|
||||
'--check-for-update-interval=2592000',
|
||||
'--disable-accelerated-2d-canvas',
|
||||
|
@ -128,7 +128,7 @@ export class GBSSR {
|
|||
public static async createBrowser(profilePath): Promise<any> {
|
||||
const opts = this.preparePuppeteer(profilePath);
|
||||
puppeteer.use(hidden());
|
||||
const browser = await puppeteer.launch( opts );
|
||||
const browser = await puppeteer.launch(opts);
|
||||
return browser;
|
||||
}
|
||||
|
||||
|
@ -279,44 +279,38 @@ export class GBSSR {
|
|||
|
||||
// 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.
|
||||
let min: GBMinInstance = req.url === '/'?
|
||||
GBServer.globals.minInstances[0]:
|
||||
GBServer.globals.minInstances.filter(p => p.instance.botId === botId)[0];
|
||||
|
||||
let path = DialogKeywords.getGBAIPath(min.botId,`gbui`);
|
||||
const botId =
|
||||
req.originalUrl || req.originalUrl === '/' ? req.originalUrl.substr(1) : GBServer.globals.minInstances[0].botId;
|
||||
let min: GBMinInstance =
|
||||
req.url === '/'
|
||||
? GBServer.globals.minInstances[0]
|
||||
: GBServer.globals.minInstances.filter(p => p.instance.botId === botId)[0];
|
||||
|
||||
let path = DialogKeywords.getGBAIPath(botId, `gbui`);
|
||||
|
||||
if (min && req.originalUrl && prerender && exclude) {
|
||||
path = Path.join(
|
||||
process.env.PWD,
|
||||
'work',
|
||||
path,
|
||||
'index.html'
|
||||
);
|
||||
path = Path.join(process.env.PWD, 'work', path, 'index.html');
|
||||
const html = Fs.readFileSync(path, 'utf8');
|
||||
res.status(200).send(html);
|
||||
return true;
|
||||
} else {
|
||||
|
||||
path = Path.join(
|
||||
process.env.PWD,
|
||||
GBDeployer.deployFolder,
|
||||
GBMinService.uiPackage,
|
||||
'build',
|
||||
min ? `index.html` : req.url
|
||||
);
|
||||
);
|
||||
if (Fs.existsSync(path)) {
|
||||
if (min){
|
||||
if (min) {
|
||||
let html = Fs.readFileSync(path, 'utf8');
|
||||
html = html.replace(/\{botId\}/gi, min.botId);
|
||||
html = html.replace(/\{theme\}/gi, min.instance.theme);
|
||||
html = html.replace(/\{title\}/gi, min.instance.title);
|
||||
res.send(html).end();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
res.sendFile(path);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
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) {
|
||||
return client.apis.Conversations.Conversations_PostActivity({
|
||||
conversationId: conversationId,
|
||||
activity: {
|
||||
textFormat: 'plain',
|
||||
text: text,
|
||||
type: 'message',
|
||||
mobile: from,
|
||||
group: group,
|
||||
attachments: attachments,
|
||||
try {
|
||||
return client.apis.Conversations.Conversations_PostActivity({
|
||||
conversationId: conversationId,
|
||||
activity: {
|
||||
textFormat: 'plain',
|
||||
text: text,
|
||||
type: 'message',
|
||||
mobile: from,
|
||||
group: group,
|
||||
attachments: attachments,
|
||||
|
||||
// Use from container to transport information to GBMinService.receiver.
|
||||
// Use from container to transport information to GBMinService.receiver.
|
||||
|
||||
from: {
|
||||
id: from,
|
||||
name: fromName,
|
||||
channelIdEx: 'whatsapp',
|
||||
group: group
|
||||
},
|
||||
replyToId: from
|
||||
}
|
||||
});
|
||||
from: {
|
||||
id: from,
|
||||
name: fromName,
|
||||
channelIdEx: 'whatsapp',
|
||||
group: group
|
||||
},
|
||||
replyToId: from
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
GBLog.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
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];
|
||||
await (activeMin as any).whatsAppDirectLine.received(req, res);
|
||||
return; // EXIT HERE.
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
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.indexSemaphore = new Mutex();
|
||||
|
||||
|
||||
server.use(bodyParser.json());
|
||||
server.use(bodyParser.urlencoded({ extended: true }));
|
||||
|
||||
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) => {
|
||||
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.
|
||||
|
||||
process.env.PWD = process.cwd();
|
||||
|
|
Loading…
Add table
Reference in a new issue