fix(core.gbapp): BASIC and KB improvements.
This commit is contained in:
parent
f3a32d04b4
commit
1bf23cf4e4
8 changed files with 80 additions and 73 deletions
|
@ -98,7 +98,7 @@ export class GBAdminService implements IGBAdminService {
|
|||
maximumLength: 14
|
||||
};
|
||||
let password = passwordGenerator.generatePassword(options);
|
||||
password = password.replace(/[\@\[\=\:\;\?]/g, '#');
|
||||
password = password.replace(/[\@\[\=\:\;\?]/gi, '#');
|
||||
|
||||
return password;
|
||||
}
|
||||
|
|
|
@ -96,50 +96,54 @@ class SysClass {
|
|||
}
|
||||
|
||||
public async save(file: string, ...args): Promise<any> {
|
||||
try {
|
||||
let token =
|
||||
await this.min.adminService.acquireElevatedToken(this.min.instance.instanceId);
|
||||
|
||||
let token =
|
||||
await this.min.adminService.acquireElevatedToken(this.min.instance.instanceId);
|
||||
let siteId = process.env.STORAGE_SITE_ID;
|
||||
let libraryId = process.env.STORAGE_LIBRARY;
|
||||
|
||||
let siteId = process.env.STORAGE_SITE_ID;
|
||||
let libraryId = process.env.STORAGE_LIBRARY;
|
||||
let client = MicrosoftGraph.Client.init({
|
||||
authProvider: done => {
|
||||
done(null, token);
|
||||
}
|
||||
});
|
||||
const botId = this.min.instance.botId;
|
||||
const path = `/${botId}/${botId}.gbdata`;
|
||||
|
||||
let client = MicrosoftGraph.Client.init({
|
||||
authProvider: done => {
|
||||
done(null, token);
|
||||
let res = await client.api(
|
||||
`https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${libraryId}/drive/root:${path}:/children`)
|
||||
.get();
|
||||
|
||||
let document = res.value.filter(m => {
|
||||
return m.name === file
|
||||
});
|
||||
|
||||
await client.api(
|
||||
`https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${libraryId}/drive/items/${document[0].id}/workbook/worksheets('Sheet1')/range(address='A1:Z1')/insert`)
|
||||
.post({});
|
||||
|
||||
if (document === undefined) {
|
||||
throw `File '${file}' specified on save GBasic command SAVE not found. Check the .gbdata or the .gbdialog associated.`;
|
||||
}
|
||||
if (args.length > 27) {
|
||||
throw `File '${file}' has a SAVE call with more than 27 arguments. Check the .gbdialog associated.`;
|
||||
}
|
||||
});
|
||||
const botId = this.min.instance.botId;
|
||||
const path = `/${botId}/${botId}.gbdata`;
|
||||
|
||||
let res = await client.api(
|
||||
`https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${libraryId}/drive/root:${path}:/children`)
|
||||
.get();
|
||||
let body =
|
||||
{ "values": [[]] };
|
||||
|
||||
let document = res.value.filter(m => {
|
||||
return m.name === file
|
||||
});
|
||||
for (let index = 0; index < 26; index++) {
|
||||
body.values[0][index] = args[index];
|
||||
}
|
||||
|
||||
await client.api(
|
||||
`https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${libraryId}/drive/items/${document[0].id}/workbook/worksheets('Sheet1')/range(address='A1:Z1')/insert`)
|
||||
.post({});
|
||||
|
||||
if (document === undefined) {
|
||||
throw `File '${file}' specified on save GBasic command SAVE not found. Check the .gbdata or the .gbdialog associated.`;
|
||||
let res2 = await client.api(
|
||||
`https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${libraryId}/drive/items/${document[0].id}/workbook/worksheets('Sheet1')/range(address='A2:Z2')`)
|
||||
.patch(body);
|
||||
} catch (error) {
|
||||
GBLog.error(`SAVE BASIC error: ${error.message}`);
|
||||
throw error;
|
||||
}
|
||||
if (args.length > 27) {
|
||||
throw `File '${file}' has a SAVE call with more than 27 arguments. Check the .gbdialog associated.`;
|
||||
}
|
||||
|
||||
let body =
|
||||
{ "values": [[]] };
|
||||
|
||||
for (let index = 0; index < 26; index++) {
|
||||
body.values[0][index] = args[index];
|
||||
}
|
||||
|
||||
let res2 = await client.api(
|
||||
`https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${libraryId}/drive/items/${document[0].id}/workbook/worksheets('Sheet1')/range(address='A2:Z2')`)
|
||||
.patch(body);
|
||||
|
||||
}
|
||||
|
||||
|
@ -264,7 +268,7 @@ class SysClass {
|
|||
}
|
||||
|
||||
public async numberOnly(text: string) {
|
||||
return text.replace(/\D/g, "");
|
||||
return text.replace(/\D/gi, "");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -580,12 +580,14 @@ export class GBConversationalService {
|
|||
const member = step.context.activity.from;
|
||||
const user = await sec.ensureUser(min.instance.instanceId, member.id,
|
||||
member.name, "", "web", member.name);
|
||||
text = await min.conversationalService.translate(
|
||||
min.instance.translatorKey ? min.instance.translatorKey : minBoot.instance.translatorKey,
|
||||
min.instance.translatorEndpoint ? min.instance.translatorEndpoint : minBoot.instance.translatorEndpoint,
|
||||
text,
|
||||
user.locale ? user.locale : 'pt'
|
||||
);
|
||||
if (text !== null) {
|
||||
text = await min.conversationalService.translate(
|
||||
min.instance.translatorKey ? min.instance.translatorKey : minBoot.instance.translatorKey,
|
||||
min.instance.translatorEndpoint ? min.instance.translatorEndpoint : minBoot.instance.translatorEndpoint,
|
||||
text,
|
||||
user.locale ? user.locale : 'pt'
|
||||
);
|
||||
}
|
||||
|
||||
return await step.prompt("textPrompt", text ? text : {});
|
||||
}
|
||||
|
@ -600,7 +602,7 @@ export class GBConversationalService {
|
|||
text = await min.conversationalService.translate(
|
||||
min.instance.translatorKey ? min.instance.translatorKey : minBoot.instance.translatorKey,
|
||||
min.instance.translatorEndpoint ? min.instance.translatorEndpoint : minBoot.instance.translatorEndpoint,
|
||||
text,
|
||||
text,
|
||||
user.locale ? user.locale : 'pt'
|
||||
);
|
||||
|
||||
|
|
|
@ -404,6 +404,7 @@ export class GBDeployer implements IGBDeployer {
|
|||
|
||||
case '.gbkb':
|
||||
const service = new KBService(this.core.sequelize);
|
||||
rimraf.sync(localPath);
|
||||
return await service.undeployKbFromStorage(instance, this, p.packageId);
|
||||
|
||||
case '.gbui':
|
||||
|
@ -411,11 +412,11 @@ export class GBDeployer implements IGBDeployer {
|
|||
break;
|
||||
|
||||
case '.gbtheme':
|
||||
|
||||
rimraf.sync(localPath);
|
||||
break;
|
||||
|
||||
case '.gbdialog':
|
||||
|
||||
rimraf.sync(localPath);
|
||||
break;
|
||||
|
||||
case '.gblib':
|
||||
|
|
|
@ -720,7 +720,7 @@ export class GBMinService {
|
|||
}
|
||||
|
||||
public static async callVM(text: string, min: GBMinInstance, step: GBDialogStep) {
|
||||
const mainMethod = text;
|
||||
const mainMethod = text.toLowerCase();
|
||||
min.sandBoxMap[mainMethod][mainMethod].bind(min.sandBoxMap[mainMethod]);
|
||||
return await min.sandBoxMap[mainMethod][mainMethod](step);
|
||||
}
|
||||
|
|
|
@ -88,8 +88,9 @@ export class GBVMService extends GBService {
|
|||
fs.writeFileSync(urlJoin(folder, filename), text);
|
||||
}
|
||||
|
||||
const mainName = filename.replace(/\s|\-/g, '').split('.')[0];
|
||||
min.scriptMap[filename] = mainName;
|
||||
let mainName = filename.replace(/\s|\-/gi, '').split('.')[0];
|
||||
mainName = mainName.toLowerCase();
|
||||
min.scriptMap[filename] = mainName.toLowerCase();
|
||||
|
||||
const fullFilename = urlJoin(folder, filename);
|
||||
// TODO: Implement in development mode, how swap for .vbs files
|
||||
|
@ -138,39 +139,39 @@ export class GBVMService extends GBService {
|
|||
|
||||
// Keywords from General Bots BASIC.
|
||||
|
||||
code = code.replace(/(hear email)/g, `email = askEmail()`);
|
||||
code = code.replace(/(hear email)/gi, `email = askEmail()`);
|
||||
|
||||
code = code.replace(/(hear)\s*(\w+)/g, ($0, $1, $2) => {
|
||||
code = code.replace(/(hear)\s*(\w+)/gi, ($0, $1, $2) => {
|
||||
return `${$2} = hear()`;
|
||||
});
|
||||
code = code.replace(/(\w)\s*\=\s*find\s*(.*)/g, ($0, $1, $2, $3) => {
|
||||
code = code.replace(/(\w)\s*\=\s*find\s*(.*)/gi, ($0, $1, $2, $3) => {
|
||||
return `${$1} = sys().find(${$2})\n`;
|
||||
});
|
||||
|
||||
code = code.replace(/(wait)\s*(\d+)/g, ($0, $1, $2) => {
|
||||
code = code.replace(/(wait)\s*(\d+)/gi, ($0, $1, $2) => {
|
||||
return `sys().wait(${$2})`;
|
||||
});
|
||||
|
||||
code = code.replace(/(get stock for )(.*)/g, ($0, $1, $2) => {
|
||||
code = code.replace(/(get stock for )(.*)/gi, ($0, $1, $2) => {
|
||||
return `let stock = sys().getStock(${$2})`;
|
||||
});
|
||||
|
||||
code = code.replace(/(get)(\s)(.*)/g, ($0, $1, $2) => {
|
||||
code = code.replace(/(get)(\s)(.*)/gi, ($0, $1, $2) => {
|
||||
return `sys().httpGet (${$2})`;
|
||||
});
|
||||
|
||||
code = code.replace(/(create a bot farm using)(\s)(.*)/g, ($0, $1, $2, $3) => {
|
||||
code = code.replace(/(create a bot farm using)(\s)(.*)/gi, ($0, $1, $2, $3) => {
|
||||
return `sys().createABotFarmUsing (${$3})`;
|
||||
});
|
||||
|
||||
code = code.replace(/(talk)(\s)(.*)/g, ($0, $1, $2, $3) => {
|
||||
code = code.replace(/(talk)(\s)(.*)/gi, ($0, $1, $2, $3) => {
|
||||
return `talk (step, ${$3})\n`;
|
||||
});
|
||||
code = code.replace(/(send file)(\s*)(.*)/g, ($0, $1, $2, $3) => {
|
||||
code = code.replace(/(send file)(\s*)(.*)/gi, ($0, $1, $2, $3) => {
|
||||
return `sendFile (step, ${$3})\n`;
|
||||
});
|
||||
|
||||
code = code.replace(/(save)(\s)(.*)/g, ($0, $1, $2, $3) => {
|
||||
code = code.replace(/(save)(\s)(.*)/gi, ($0, $1, $2, $3) => {
|
||||
return `sys().save(${$3})\n`;
|
||||
});
|
||||
|
||||
|
@ -193,7 +194,7 @@ export class GBVMService extends GBService {
|
|||
// Convert TS into JS.
|
||||
const tsfile: string = `${filename}.ts`;
|
||||
let tsCode: string = fs.readFileSync(tsfile, 'utf8');
|
||||
tsCode = tsCode.replace(/export.*\n/g, `export function ${mainName}(step:any) { let resolve = undefined;`);
|
||||
tsCode = tsCode.replace(/export.*\n/gi, `export function ${mainName}(step:any) { let resolve = undefined;`);
|
||||
fs.writeFileSync(tsfile, tsCode);
|
||||
|
||||
const tsc = new TSCompiler();
|
||||
|
@ -275,7 +276,7 @@ export class GBVMService extends GBService {
|
|||
const sandbox: DialogClass = new DialogClass(min, deployer);
|
||||
const context = vm.createContext(sandbox);
|
||||
vm.runInContext(parsedCode, context);
|
||||
min.sandBoxMap[mainName] = sandbox;
|
||||
min.sandBoxMap[mainName.toLowerCase()] = sandbox;
|
||||
GBLog.info(`[GBVMService] Finished loading of ${filename}`);
|
||||
} catch (error) {
|
||||
GBLog.error(`[GBVMService] ERROR loading ${error}`);
|
||||
|
@ -286,20 +287,20 @@ export class GBVMService extends GBService {
|
|||
private handleThisAndAwait(code: string) {
|
||||
// this insertion.
|
||||
|
||||
code = code.replace(/sys\(\)/g, 'this.sys()');
|
||||
code = code.replace(/("[^"]*"|'[^']*')|\btalk\b/g, ($0, $1) => {
|
||||
code = code.replace(/sys\(\)/gi, 'this.sys()');
|
||||
code = code.replace(/("[^"]*"|'[^']*')|\btalk\b/gi, ($0, $1) => {
|
||||
return $1 === undefined ? 'this.talk' : $1;
|
||||
});
|
||||
code = code.replace(/("[^"]*"|'[^']*')|\bhear\b/g, ($0, $1) => {
|
||||
code = code.replace(/("[^"]*"|'[^']*')|\bhear\b/gi, ($0, $1) => {
|
||||
return $1 === undefined ? 'this.hear' : $1;
|
||||
});
|
||||
code = code.replace(/("[^"]*"|'[^']*')|\bsendEmail\b/g, ($0, $1) => {
|
||||
code = code.replace(/("[^"]*"|'[^']*')|\bsendEmail\b/gi, ($0, $1) => {
|
||||
return $1 === undefined ? 'this.sendEmail' : $1;
|
||||
});
|
||||
code = code.replace(/("[^"]*"|'[^']*')|\baskEmail\b/g, ($0, $1) => {
|
||||
code = code.replace(/("[^"]*"|'[^']*')|\baskEmail\b/gi, ($0, $1) => {
|
||||
return $1 === undefined ? 'this.askEmail' : $1;
|
||||
});
|
||||
code = code.replace(/("[^"]*"|'[^']*')|\bsendFile\b/g, ($0, $1) => {
|
||||
code = code.replace(/("[^"]*"|'[^']*')|\bsendFile\b/gi, ($0, $1) => {
|
||||
return $1 === undefined ? 'this.sendFile' : $1;
|
||||
});
|
||||
|
||||
|
|
|
@ -230,7 +230,7 @@ export class AskDialog extends IGBDialog {
|
|||
const urlSufix = 'url:';
|
||||
|
||||
if (answer.content.endsWith('.docx')) {
|
||||
const mainName = answer.content.replace(/\s|\-/g, '').split('.')[0];
|
||||
const mainName = answer.content.replace(/\s|\-/gi, '').split('.')[0];
|
||||
return await GBMinService.callVM(mainName, min, step);
|
||||
} else {
|
||||
await service.sendAnswer(min, AskDialog.getChannel(step), step, answer);
|
||||
|
|
|
@ -57,7 +57,6 @@ import { GBConfigService } from './../../core.gbapp/services/GBConfigService';
|
|||
import { CSService } from '../../customer-satisfaction.gbapp/services/CSService';
|
||||
import { SecService } from '../../security.gblib/services/SecService';
|
||||
import { CollectionUtil } from 'pragmatismo-io-framework';
|
||||
import { try } from 'bluebird';
|
||||
|
||||
/**
|
||||
* Result for quey on KB data.
|
||||
|
@ -302,7 +301,7 @@ export class KBService implements IGBKBService {
|
|||
|
||||
let media = null;
|
||||
|
||||
if (!answer) {
|
||||
if (typeof (answer) !== "string" ) {
|
||||
GBLog.info(`[GBImporter] Answer is NULL related to Question '${question}'.`);
|
||||
answer = 'Existe um problema na base de conhecimento. Fui treinado para entender sua pergunta, avise a quem me criou que a resposta não foi informada para esta pergunta.';
|
||||
} else if (answer.indexOf('.md') > -1) {
|
||||
|
@ -455,7 +454,7 @@ export class KBService implements IGBKBService {
|
|||
|
||||
const locale = step.context.activity.locale;
|
||||
await min.conversationalService.sendText(min, step, Messages[locale].will_answer_projector);
|
||||
html = html.replace(/src\=\"kb\//g, `src=\"../kb/`);
|
||||
html = html.replace(/src\=\"kb\//gi, `src=\"../kb/`);
|
||||
await conversationalService.sendEvent(min, step, 'play', {
|
||||
playerType: 'markdown',
|
||||
data: {
|
||||
|
|
Loading…
Add table
Reference in a new issue