fix(core.gbapp): Several fixes and translator swicher.
This commit is contained in:
parent
5a99ef09aa
commit
cca148818e
6 changed files with 68 additions and 61 deletions
|
@ -538,7 +538,7 @@ export class GBConversationalService {
|
||||||
const translatorEnabled = () => {
|
const translatorEnabled = () => {
|
||||||
if (min.instance.params) {
|
if (min.instance.params) {
|
||||||
const params = JSON.parse(min.instance.params);
|
const params = JSON.parse(min.instance.params);
|
||||||
return params['Enable Worldwide Translator'] === "TRUE";
|
return params ? params['Enable Worldwide Translator'] === "TRUE" : false;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
} // TODO: Encapsulate.
|
} // TODO: Encapsulate.
|
||||||
|
|
|
@ -153,8 +153,9 @@ export class GBDeployer implements IGBDeployer {
|
||||||
public async deployBlankBot(botId: string) {
|
public async deployBlankBot(botId: string) {
|
||||||
let instance = await this.importer.createBotInstance(botId);
|
let instance = await this.importer.createBotInstance(botId);
|
||||||
|
|
||||||
|
const bootInstance = GBServer.globals.bootInstance;
|
||||||
const accessToken = await GBServer.globals.minBoot.adminService
|
const accessToken = await GBServer.globals.minBoot.adminService
|
||||||
.acquireElevatedToken(GBServer.globals.bootInstance.instanceId);
|
.acquireElevatedToken(bootInstance.instanceId);
|
||||||
|
|
||||||
const service = new AzureDeployerService(this);
|
const service = new AzureDeployerService(this);
|
||||||
let application = await service.createApplication(accessToken, botId);
|
let application = await service.createApplication(accessToken, botId);
|
||||||
|
@ -168,6 +169,10 @@ export class GBDeployer implements IGBDeployer {
|
||||||
instance.state = 'active';
|
instance.state = 'active';
|
||||||
instance.nlpScore = 0.80; // TODO: Migrate to Excel Config.xlsx.
|
instance.nlpScore = 0.80; // TODO: Migrate to Excel Config.xlsx.
|
||||||
instance.searchScore = 0.45;
|
instance.searchScore = 0.45;
|
||||||
|
instance.whatsappServiceKey = bootInstance.whatsappServiceKey;
|
||||||
|
instance.whatsappBotKey = bootInstance.whatsappBotKey;
|
||||||
|
instance.whatsappServiceNumber = bootInstance.whatsappServiceNumber;
|
||||||
|
instance.whatsappServiceUrl = bootInstance.whatsappServiceUrl;
|
||||||
|
|
||||||
await this.core.saveInstance(instance);
|
await this.core.saveInstance(instance);
|
||||||
|
|
||||||
|
@ -281,8 +286,9 @@ export class GBDeployer implements IGBDeployer {
|
||||||
let document = res.value.filter(m => {
|
let document = res.value.filter(m => {
|
||||||
return m.name === "Config.xlsx"
|
return m.name === "Config.xlsx"
|
||||||
});
|
});
|
||||||
if (document === undefined) {
|
if (document === undefined || document.length === 0) {
|
||||||
throw `Config.xlsx not found on .bot folder, check the package.`;
|
GBLog.info(`Config.xlsx not found on .bot folder, check the package.`);
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Creates workbook session that will be discarded.
|
// Creates workbook session that will be discarded.
|
||||||
|
|
|
@ -184,7 +184,7 @@ export class GBMinService {
|
||||||
await (GBServer.globals.minBoot as any).whatsAppDirectLine.received(req, res);
|
await (GBServer.globals.minBoot as any).whatsAppDirectLine.received(req, res);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
GBLog.error(`Error on Whatsapp callback: ${error}`);
|
GBLog.error(`Error on Whatsapp callback: ${error.data ? error.data : error}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -705,7 +705,7 @@ export class GBMinService {
|
||||||
const translatorEnabled = () => {
|
const translatorEnabled = () => {
|
||||||
if (min.instance.params) {
|
if (min.instance.params) {
|
||||||
const params = JSON.parse(min.instance.params);
|
const params = JSON.parse(min.instance.params);
|
||||||
return params['Enable Worldwide Translator'] === "TRUE";
|
return params?params['Enable Worldwide Translator'] === "TRUE": false;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
} // TODO: Encapsulate.
|
} // TODO: Encapsulate.
|
||||||
|
|
|
@ -37,9 +37,8 @@ import { GBLog, GBMinInstance, GBService, IGBCoreService } from 'botlib';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import { GBDeployer } from './GBDeployer';
|
import { GBDeployer } from './GBDeployer';
|
||||||
import { TSCompiler } from './TSCompiler';
|
import { TSCompiler } from './TSCompiler';
|
||||||
|
import { CollectionUtil } from 'pragmatismo-io-framework';
|
||||||
const walkPromise = require('walk-promise');
|
const walkPromise = require('walk-promise');
|
||||||
|
|
||||||
const vm = require('vm');
|
const vm = require('vm');
|
||||||
import urlJoin = require('url-join');
|
import urlJoin = require('url-join');
|
||||||
import { DialogClass } from './GBAPIService';
|
import { DialogClass } from './GBAPIService';
|
||||||
|
@ -69,63 +68,65 @@ export class GBVMService extends GBService {
|
||||||
const files = await walkPromise(folder);
|
const files = await walkPromise(folder);
|
||||||
this.addHearDialog(min);
|
this.addHearDialog(min);
|
||||||
|
|
||||||
return Promise.all(
|
await CollectionUtil.asyncForEach(files, async file => {
|
||||||
files.map(async file => {
|
if (!file) {
|
||||||
|
|
||||||
let filename: string = file.name;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (filename.endsWith('.docx')) {
|
let filename: string = file.name;
|
||||||
const wordFile = filename;
|
|
||||||
const vbsFile = filename.substr(0, filename.indexOf('docx')) + 'vbs';
|
if (filename.endsWith('.docx')) {
|
||||||
const fullVbsFile = urlJoin(folder, vbsFile);
|
const wordFile = filename;
|
||||||
const docxStat = fs.statSync(urlJoin(folder, wordFile));
|
const vbsFile = filename.substr(0, filename.indexOf('docx')) + 'vbs';
|
||||||
|
const fullVbsFile = urlJoin(folder, vbsFile);
|
||||||
|
const docxStat = fs.statSync(urlJoin(folder, wordFile));
|
||||||
|
const interval = 30000; // If compiled is older 30 seconds, then recompile.
|
||||||
|
let writeVBS = true;
|
||||||
|
if (fs.existsSync(fullVbsFile)) {
|
||||||
|
const vbsStat = fs.statSync(fullVbsFile);
|
||||||
|
if (docxStat.mtimeMs < (vbsStat.mtimeMs + interval)) {
|
||||||
|
writeVBS = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (writeVBS) {
|
||||||
|
|
||||||
|
let text = await this.getTextFromWord(folder, wordFile);
|
||||||
|
fs.writeFileSync(urlJoin(folder, vbsFile), text);
|
||||||
|
}
|
||||||
|
|
||||||
|
filename = vbsFile;
|
||||||
|
|
||||||
|
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
|
||||||
|
// fs.watchFile(fullFilename, async () => {
|
||||||
|
// await this.run(fullFilename, min, deployer, mainName);
|
||||||
|
// });
|
||||||
|
|
||||||
|
const compiledAt = fs.statSync(fullFilename);
|
||||||
|
const jsfile = urlJoin(folder, `${filename}.js`);
|
||||||
|
|
||||||
|
if (fs.existsSync(jsfile)) {
|
||||||
|
const jsStat = fs.statSync(jsfile);
|
||||||
const interval = 30000; // If compiled is older 30 seconds, then recompile.
|
const interval = 30000; // If compiled is older 30 seconds, then recompile.
|
||||||
let writeVBS = true;
|
if (compiledAt.isFile() && compiledAt.mtimeMs > (jsStat.mtimeMs + interval)) {
|
||||||
if (fs.existsSync(fullVbsFile)) {
|
|
||||||
const vbsStat = fs.statSync(fullVbsFile);
|
|
||||||
if (docxStat.mtimeMs < (vbsStat.mtimeMs + interval)) {
|
|
||||||
writeVBS = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (writeVBS) {
|
|
||||||
|
|
||||||
let text = await this.getTextFromWord(folder, wordFile);
|
|
||||||
fs.writeFileSync(urlJoin(folder, vbsFile), text);
|
|
||||||
}
|
|
||||||
|
|
||||||
filename = vbsFile;
|
|
||||||
|
|
||||||
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
|
|
||||||
// fs.watchFile(fullFilename, async () => {
|
|
||||||
// await this.run(fullFilename, min, deployer, mainName);
|
|
||||||
// });
|
|
||||||
|
|
||||||
const compiledAt = fs.statSync(fullFilename);
|
|
||||||
const jsfile = urlJoin(folder, `${filename}.js`);
|
|
||||||
|
|
||||||
if (fs.existsSync(jsfile)) {
|
|
||||||
const jsStat = fs.statSync(jsfile);
|
|
||||||
const interval = 30000; // If compiled is older 30 seconds, then recompile.
|
|
||||||
if (compiledAt.isFile() && compiledAt.mtimeMs > (jsStat.mtimeMs + interval)) {
|
|
||||||
await this.executeBASIC(fullFilename, min, deployer, mainName);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
const parsedCode: string = fs.readFileSync(jsfile, 'utf8');
|
|
||||||
this.executeJS(min, deployer, parsedCode, mainName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
await this.executeBASIC(fullFilename, min, deployer, mainName);
|
await this.executeBASIC(fullFilename, min, deployer, mainName);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
const parsedCode: string = fs.readFileSync(jsfile, 'utf8');
|
||||||
|
this.executeJS(min, deployer, parsedCode, mainName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
else {
|
||||||
);
|
await this.executeBASIC(fullFilename, min, deployer, mainName);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private async getTextFromWord(folder: string, filename: string) {
|
private async getTextFromWord(folder: string, filename: string) {
|
||||||
|
|
|
@ -103,7 +103,7 @@ export class AskDialog extends IGBDialog {
|
||||||
const translatorEnabled = () => {
|
const translatorEnabled = () => {
|
||||||
if (min.instance.params) {
|
if (min.instance.params) {
|
||||||
const params = JSON.parse(min.instance.params);
|
const params = JSON.parse(min.instance.params);
|
||||||
return params['Enable Worldwide Translator'] === "TRUE";
|
return params?params['Enable Worldwide Translator'] === "TRUE": false;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
} // TODO: Encapsulate.
|
} // TODO: Encapsulate.
|
||||||
|
|
|
@ -129,7 +129,7 @@ export class WhatsappDirectLine extends GBService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public resetConversationId(number) {
|
public async resetConversationId(number) {
|
||||||
this.conversationIds[number] = undefined;
|
this.conversationIds[number] = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue