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 = () => {
|
||||
if (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;
|
||||
} // TODO: Encapsulate.
|
||||
|
|
|
@ -153,8 +153,9 @@ export class GBDeployer implements IGBDeployer {
|
|||
public async deployBlankBot(botId: string) {
|
||||
let instance = await this.importer.createBotInstance(botId);
|
||||
|
||||
const bootInstance = GBServer.globals.bootInstance;
|
||||
const accessToken = await GBServer.globals.minBoot.adminService
|
||||
.acquireElevatedToken(GBServer.globals.bootInstance.instanceId);
|
||||
.acquireElevatedToken(bootInstance.instanceId);
|
||||
|
||||
const service = new AzureDeployerService(this);
|
||||
let application = await service.createApplication(accessToken, botId);
|
||||
|
@ -168,6 +169,10 @@ export class GBDeployer implements IGBDeployer {
|
|||
instance.state = 'active';
|
||||
instance.nlpScore = 0.80; // TODO: Migrate to Excel Config.xlsx.
|
||||
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);
|
||||
|
||||
|
@ -281,8 +286,9 @@ export class GBDeployer implements IGBDeployer {
|
|||
let document = res.value.filter(m => {
|
||||
return m.name === "Config.xlsx"
|
||||
});
|
||||
if (document === undefined) {
|
||||
throw `Config.xlsx not found on .bot folder, check the package.`;
|
||||
if (document === undefined || document.length === 0) {
|
||||
GBLog.info(`Config.xlsx not found on .bot folder, check the package.`);
|
||||
return null;
|
||||
}
|
||||
|
||||
// Creates workbook session that will be discarded.
|
||||
|
|
|
@ -184,7 +184,7 @@ export class GBMinService {
|
|||
await (GBServer.globals.minBoot as any).whatsAppDirectLine.received(req, res);
|
||||
}
|
||||
} 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 = () => {
|
||||
if (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;
|
||||
} // TODO: Encapsulate.
|
||||
|
|
|
@ -37,9 +37,8 @@ import { GBLog, GBMinInstance, GBService, IGBCoreService } from 'botlib';
|
|||
import * as fs from 'fs';
|
||||
import { GBDeployer } from './GBDeployer';
|
||||
import { TSCompiler } from './TSCompiler';
|
||||
|
||||
import { CollectionUtil } from 'pragmatismo-io-framework';
|
||||
const walkPromise = require('walk-promise');
|
||||
|
||||
const vm = require('vm');
|
||||
import urlJoin = require('url-join');
|
||||
import { DialogClass } from './GBAPIService';
|
||||
|
@ -69,63 +68,65 @@ export class GBVMService extends GBService {
|
|||
const files = await walkPromise(folder);
|
||||
this.addHearDialog(min);
|
||||
|
||||
return Promise.all(
|
||||
files.map(async file => {
|
||||
await CollectionUtil.asyncForEach(files, async file => {
|
||||
if (!file) {
|
||||
|
||||
let filename: string = file.name;
|
||||
return;
|
||||
}
|
||||
|
||||
if (filename.endsWith('.docx')) {
|
||||
const wordFile = filename;
|
||||
const vbsFile = filename.substr(0, filename.indexOf('docx')) + 'vbs';
|
||||
const fullVbsFile = urlJoin(folder, vbsFile);
|
||||
const docxStat = fs.statSync(urlJoin(folder, wordFile));
|
||||
let filename: string = file.name;
|
||||
|
||||
if (filename.endsWith('.docx')) {
|
||||
const wordFile = filename;
|
||||
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.
|
||||
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.
|
||||
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 {
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private async getTextFromWord(folder: string, filename: string) {
|
||||
|
|
|
@ -103,7 +103,7 @@ export class AskDialog extends IGBDialog {
|
|||
const translatorEnabled = () => {
|
||||
if (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;
|
||||
} // TODO: Encapsulate.
|
||||
|
|
|
@ -129,7 +129,7 @@ export class WhatsappDirectLine extends GBService {
|
|||
}
|
||||
}
|
||||
|
||||
public resetConversationId(number) {
|
||||
public async resetConversationId(number) {
|
||||
this.conversationIds[number] = undefined;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue