fix(core.gbapp): GB Apps can now publish bots and replace root web application.
This commit is contained in:
parent
283e596c80
commit
675c8511cb
7 changed files with 92 additions and 47 deletions
69
package.json
69
package.json
|
@ -15,6 +15,7 @@
|
||||||
},
|
},
|
||||||
"license": "AGPL-3.0",
|
"license": "AGPL-3.0",
|
||||||
"preferGlobal": true,
|
"preferGlobal": true,
|
||||||
|
"private": false,
|
||||||
"bin": {
|
"bin": {
|
||||||
"gbot": "./boot.js"
|
"gbot": "./boot.js"
|
||||||
},
|
},
|
||||||
|
@ -45,9 +46,9 @@
|
||||||
"commit": "git-cz"
|
"commit": "git-cz"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@azure/ms-rest-js": "^2.0.4",
|
"@azure/ms-rest-js": "2.0.4",
|
||||||
"@microsoft/microsoft-graph-client": "^2.0.0",
|
"@microsoft/microsoft-graph-client": "2.0.0",
|
||||||
"@types/validator": "^12.0.1",
|
"@types/validator": "12.0.1",
|
||||||
"adal-node": "0.2.1",
|
"adal-node": "0.2.1",
|
||||||
"async-promises": "0.2.2",
|
"async-promises": "0.2.2",
|
||||||
"azure-arm-cognitiveservices": "3.0.0",
|
"azure-arm-cognitiveservices": "3.0.0",
|
||||||
|
@ -56,66 +57,66 @@
|
||||||
"azure-arm-sql": "5.7.0",
|
"azure-arm-sql": "5.7.0",
|
||||||
"azure-arm-website": "5.7.0",
|
"azure-arm-website": "5.7.0",
|
||||||
"azure-search-client": "3.1.5",
|
"azure-search-client": "3.1.5",
|
||||||
"bluebird": "^3.7.2",
|
"bluebird": "3.7.2",
|
||||||
"body-parser": "1.19.0",
|
"body-parser": "1.19.0",
|
||||||
"botbuilder": "^4.7.0",
|
"botbuilder": "4.7.0",
|
||||||
"botbuilder-ai": "^4.7.0",
|
"botbuilder-ai": "4.7.0",
|
||||||
"botbuilder-dialogs": "^4.7.0",
|
"botbuilder-dialogs": "4.7.0",
|
||||||
"botframework-connector": "^4.7.0",
|
"botframework-connector": "4.7.0",
|
||||||
"botlib": "1.3.2",
|
"botlib": "1.4.0",
|
||||||
"chai": "4.2.0",
|
"chai": "4.2.0",
|
||||||
"cli-spinner": "0.2.10",
|
"cli-spinner": "0.2.10",
|
||||||
"csv-parse": "^4.8.3",
|
"csv-parse": "4.8.3",
|
||||||
"dotenv-extended": "^2.7.1",
|
"dotenv-extended": "2.7.1",
|
||||||
"exceljs": "^3.5.0",
|
"exceljs": "3.5.0",
|
||||||
"express": "4.17.1",
|
"express": "4.17.1",
|
||||||
"express-remove-route": "1.0.0",
|
"express-remove-route": "1.0.0",
|
||||||
"js-beautify": "1.10.2",
|
"js-beautify": "1.10.2",
|
||||||
"marked": "^0.8.0",
|
"marked": "0.8.0",
|
||||||
"mocha": "6.2.2",
|
"mocha": "6.2.2",
|
||||||
"ms-rest-azure": "^3.0.0",
|
"ms-rest-azure": "3.0.0",
|
||||||
"nexmo": "^2.5.2",
|
"nexmo": "2.5.2",
|
||||||
"ngrok": "^3.2.7",
|
"ngrok": "3.2.7",
|
||||||
"npm": "^6.13.4",
|
"npm": "6.13.4",
|
||||||
"opn": "6.0.0",
|
"opn": "6.0.0",
|
||||||
"pragmatismo-io-framework": "1.0.20",
|
"pragmatismo-io-framework": "1.0.20",
|
||||||
"public-ip": "^4.0.0",
|
"public-ip": "4.0.0",
|
||||||
"reflect-metadata": "0.1.13",
|
"reflect-metadata": "0.1.13",
|
||||||
"request-promise": "4.2.5",
|
"request-promise": "4.2.5",
|
||||||
"request-promise-native": "1.0.8",
|
"request-promise-native": "1.0.8",
|
||||||
"rimraf": "^3.0.0",
|
"rimraf": "3.0.0",
|
||||||
"scanf": "^1.1.1",
|
"scanf": "1.1.1",
|
||||||
"sequelize-typescript": "^1.1.0",
|
"sequelize-typescript": "1.1.0",
|
||||||
"shx": "0.3.2",
|
"shx": "0.3.2",
|
||||||
"simple-git": "^1.129.0",
|
"simple-git": "1.129.0",
|
||||||
"sppull": "2.5.1",
|
"sppull": "2.5.1",
|
||||||
"strict-password-generator": "1.1.2",
|
"strict-password-generator": "1.1.2",
|
||||||
"swagger-client": "^3.9.6",
|
"swagger-client": "3.9.6",
|
||||||
"tedious": "^6.6.5",
|
"tedious": "6.6.5",
|
||||||
"typedoc": "^0.15.6",
|
"typedoc": "0.15.6",
|
||||||
"typescript": "^3.7.4",
|
"typescript": "3.7.4",
|
||||||
"url-join": "4.0.1",
|
"url-join": "4.0.1",
|
||||||
"vbscript-to-typescript": "1.0.8",
|
"vbscript-to-typescript": "1.0.8",
|
||||||
"wait-until": "0.0.2",
|
"wait-until": "0.0.2",
|
||||||
"walk-promise": "0.2.0",
|
"walk-promise": "0.2.0",
|
||||||
"washyourmouthoutwithsoap": "^1.0.2"
|
"washyourmouthoutwithsoap": "1.0.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/chai": "^4.2.7",
|
"@types/chai": "4.2.7",
|
||||||
"@types/mocha": "5.2.7",
|
"@types/mocha": "5.2.7",
|
||||||
"@types/url-join": "4.0.0",
|
"@types/url-join": "4.0.0",
|
||||||
"@types/winston": "2.4.4",
|
"@types/winston": "2.4.4",
|
||||||
"ban-sensitive-files": "1.9.2",
|
"ban-sensitive-files": "1.9.2",
|
||||||
"commitizen": "^4.0.3",
|
"commitizen": "4.0.3",
|
||||||
"cz-conventional-changelog": "^3.0.2",
|
"cz-conventional-changelog": "3.0.2",
|
||||||
"dependency-check": "^4.1.0",
|
"dependency-check": "4.1.0",
|
||||||
"git-issues": "1.3.1",
|
"git-issues": "1.3.1",
|
||||||
"license-checker": "25.0.1",
|
"license-checker": "25.0.1",
|
||||||
"nsp": "3.2.1",
|
"nsp": "3.2.1",
|
||||||
"prettier-standard": "^16.1.0",
|
"prettier-standard": "16.1.0",
|
||||||
"semantic-release": "^15.14.0",
|
"semantic-release": "15.14.0",
|
||||||
"travis-deploy-once": "5.0.11",
|
"travis-deploy-once": "5.0.11",
|
||||||
"ts-node": "^8.5.4",
|
"ts-node": "8.5.4",
|
||||||
"tslint": "5.20.1"
|
"tslint": "5.20.1"
|
||||||
},
|
},
|
||||||
"eslintConfig": {
|
"eslintConfig": {
|
||||||
|
|
|
@ -41,6 +41,7 @@ import { LuisRecognizer } from 'botbuilder-ai';
|
||||||
import { GBDialogStep, GBLog, GBMinInstance, IGBConversationalService, IGBCoreService } from 'botlib';
|
import { GBDialogStep, GBLog, GBMinInstance, IGBConversationalService, IGBCoreService } from 'botlib';
|
||||||
import { AzureText } from 'pragmatismo-io-framework';
|
import { AzureText } from 'pragmatismo-io-framework';
|
||||||
import { Messages } from '../strings';
|
import { Messages } from '../strings';
|
||||||
|
const PasswordGenerator = require("strict-password-generator").default;
|
||||||
const Nexmo = require('nexmo');
|
const Nexmo = require('nexmo');
|
||||||
|
|
||||||
export interface LanguagePickerSettings {
|
export interface LanguagePickerSettings {
|
||||||
|
@ -59,6 +60,20 @@ export class GBConversationalService implements IGBConversationalService {
|
||||||
this.coreService = coreService;
|
this.coreService = coreService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static getNewMobileCode() {
|
||||||
|
const passwordGenerator = new PasswordGenerator();
|
||||||
|
const options = {
|
||||||
|
upperCaseAlpha: false,
|
||||||
|
lowerCaseAlpha: false,
|
||||||
|
number: true,
|
||||||
|
specialCharacter: false,
|
||||||
|
minimumLength: 4,
|
||||||
|
maximumLength: 4
|
||||||
|
};
|
||||||
|
let code = passwordGenerator.generatePassword(options);
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
public getCurrentLanguage(step: GBDialogStep) {
|
public getCurrentLanguage(step: GBDialogStep) {
|
||||||
return step.context.activity.locale;
|
return step.context.activity.locale;
|
||||||
}
|
}
|
||||||
|
|
|
@ -288,6 +288,12 @@ STORAGE_SYNC=true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public setWWWRoot(localPath: string)
|
||||||
|
{
|
||||||
|
GBServer.globals.wwwroot = localPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public async deleteInstance(botId: string) {
|
public async deleteInstance(botId: string) {
|
||||||
const options = { where: {} };
|
const options = { where: {} };
|
||||||
options.where = { botId: botId };
|
options.where = { botId: botId };
|
||||||
|
|
|
@ -48,7 +48,7 @@ const rimraf = require('rimraf');
|
||||||
import { GBError, GBLog, GBMinInstance, IGBCoreService, IGBInstance, IGBPackage } from 'botlib';
|
import { GBError, GBLog, GBMinInstance, IGBCoreService, IGBInstance, IGBPackage } from 'botlib';
|
||||||
import { AzureSearch } from 'pragmatismo-io-framework';
|
import { AzureSearch } from 'pragmatismo-io-framework';
|
||||||
import { GBServer } from '../../../src/app';
|
import { GBServer } from '../../../src/app';
|
||||||
import { GuaribasPackage } from '../models/GBModel';
|
import { GuaribasPackage, GuaribasInstance } from '../models/GBModel';
|
||||||
import { GBAdminService } from './../../admin.gbapp/services/GBAdminService';
|
import { GBAdminService } from './../../admin.gbapp/services/GBAdminService';
|
||||||
import { AzureDeployerService } from './../../azuredeployer.gbapp/services/AzureDeployerService';
|
import { AzureDeployerService } from './../../azuredeployer.gbapp/services/AzureDeployerService';
|
||||||
import { KBService } from './../../kb.gbapp/services/KBService';
|
import { KBService } from './../../kb.gbapp/services/KBService';
|
||||||
|
@ -163,16 +163,20 @@ export class GBDeployer {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public async deployBlankBot(botId: string){
|
||||||
|
let instance = await this.importer.createBotInstance(botId);
|
||||||
|
return this.deployBotFull(instance, GBServer.globals.publicAddress);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deploys a bot to the storage.
|
* Deploys a bot to the storage.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public async deployBot(localPath: string, publicAddress: string): Promise<void> {
|
public async deployBotFull(instance: IGBInstance, publicAddress: string): Promise<void> {
|
||||||
const packageName = Path.basename(localPath);
|
|
||||||
|
|
||||||
const service = new AzureDeployerService(this);
|
const service = new AzureDeployerService(this);
|
||||||
let instance = await this.importer.importIfNotExistsBotPackage(undefined, packageName, localPath);
|
|
||||||
|
|
||||||
const username = GBConfigService.get('CLOUD_USERNAME');
|
const username = GBConfigService.get('CLOUD_USERNAME');
|
||||||
const password = GBConfigService.get('CLOUD_PASSWORD');
|
const password = GBConfigService.get('CLOUD_PASSWORD');
|
||||||
const group = GBConfigService.get('CLOUD_GROUP');
|
const group = GBConfigService.get('CLOUD_GROUP');
|
||||||
|
@ -230,6 +234,15 @@ export class GBDeployer {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deploys a bot to the storage from a .gbot folder.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public async deployBotFromLocalPath(localPath: string, publicAddress: string): Promise<void> {
|
||||||
|
const packageName = Path.basename(localPath);
|
||||||
|
let instance = await this.importer.importIfNotExistsBotPackage(undefined, packageName, localPath);
|
||||||
|
this.deployBotFull(instance, publicAddress);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* UndDeploys a bot to the storage.
|
* UndDeploys a bot to the storage.
|
||||||
|
@ -276,7 +289,7 @@ export class GBDeployer {
|
||||||
|
|
||||||
switch (packageType) {
|
switch (packageType) {
|
||||||
case '.gbot':
|
case '.gbot':
|
||||||
await this.deployBot(localPath, GBServer.globals.publicAddress);
|
await this.deployBotFromLocalPath(localPath, GBServer.globals.publicAddress);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '.gbkb':
|
case '.gbkb':
|
||||||
|
@ -406,7 +419,7 @@ export class GBDeployer {
|
||||||
await CollectionUtil.asyncForEach(botPackages, async e => {
|
await CollectionUtil.asyncForEach(botPackages, async e => {
|
||||||
if (e !== 'packages\\boot.gbot') {
|
if (e !== 'packages\\boot.gbot') {
|
||||||
GBLog.info(`Deploying bot: ${e}...`);
|
GBLog.info(`Deploying bot: ${e}...`);
|
||||||
await _this.deployBot(e, GBServer.globals.publicAddress);
|
await _this.deployBotFromLocalPath(e, GBServer.globals.publicAddress);
|
||||||
GBLog.info(`Bot: ${e} deployed...`);
|
GBLog.info(`Bot: ${e} deployed...`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -64,11 +64,18 @@ export class GBImporter {
|
||||||
const instance = await this.core.loadInstance(botId);
|
const instance = await this.core.loadInstance(botId);
|
||||||
|
|
||||||
if (instance.botId === undefined || instance.botId === null) {
|
if (instance.botId === undefined || instance.botId === null) {
|
||||||
console.log("••• Atenção botId é nulo ou undefined");
|
console.log(`Null BotId after load instance with botId: ${botId}.`);
|
||||||
}
|
}
|
||||||
return await this.createOrUpdateInstanceInternal(instance, botId, localPath, settingsJson);
|
return await this.createOrUpdateInstanceInternal(instance, botId, localPath, settingsJson);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async createBotInstance(botId: string) {
|
||||||
|
let fullSettingsJson = { ...GBServer.globals.bootInstance };
|
||||||
|
fullSettingsJson.botId = botId;
|
||||||
|
return await GuaribasInstance.create(fullSettingsJson);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private async createOrUpdateInstanceInternal(instance: IGBInstance,
|
private async createOrUpdateInstanceInternal(instance: IGBInstance,
|
||||||
botId: string, localPath: string, settingsJson: any) {
|
botId: string, localPath: string, settingsJson: any) {
|
||||||
let packageJson = JSON.parse(fs.readFileSync(urlJoin(localPath, 'package.json'), 'utf8'));
|
let packageJson = JSON.parse(fs.readFileSync(urlJoin(localPath, 'package.json'), 'utf8'));
|
||||||
|
@ -83,9 +90,6 @@ export class GBImporter {
|
||||||
if (instance !== null) {
|
if (instance !== null) {
|
||||||
instance = { ...instance, ...fullSettingsJson };
|
instance = { ...instance, ...fullSettingsJson };
|
||||||
|
|
||||||
if (instance.botId === undefined || instance.botId === null) {
|
|
||||||
console.log("••• Atenção botId é nulo ou undefined");
|
|
||||||
}
|
|
||||||
return await this.core.saveInstance(instance);
|
return await this.core.saveInstance(instance);
|
||||||
} else {
|
} else {
|
||||||
return await GuaribasInstance.create(fullSettingsJson);
|
return await GuaribasInstance.create(fullSettingsJson);
|
||||||
|
|
|
@ -110,7 +110,10 @@ export class GBMinService {
|
||||||
) {
|
) {
|
||||||
// Serves default UI on root address '/' if web enabled.
|
// Serves default UI on root address '/' if web enabled.
|
||||||
if (process.env.DISABLE_WEB !== 'true') {
|
if (process.env.DISABLE_WEB !== 'true') {
|
||||||
GBServer.globals.server.use('/', express.static(urlJoin(GBDeployer.deployFolder, GBMinService.uiPackage, 'build')));
|
let url = urlJoin(GBDeployer.deployFolder, GBMinService.uiPackage, 'build');
|
||||||
|
|
||||||
|
GBServer.globals.server.use('/', express.static(GBServer.globals.wwwroot ?
|
||||||
|
GBServer.globals.wwwroot : url));
|
||||||
}
|
}
|
||||||
// Serves the bot information object via HTTP so clients can get
|
// Serves the bot information object via HTTP so clients can get
|
||||||
// instance information stored on server.
|
// instance information stored on server.
|
||||||
|
@ -382,6 +385,7 @@ export class GBMinService {
|
||||||
min.core = this.core;
|
min.core = this.core;
|
||||||
min.conversationalService = this.conversationalService;
|
min.conversationalService = this.conversationalService;
|
||||||
min.adminService = this.adminService;
|
min.adminService = this.adminService;
|
||||||
|
min.deployer = this.deployer;
|
||||||
min.instance = await this.core.loadInstance(min.botId);
|
min.instance = await this.core.loadInstance(min.botId);
|
||||||
min.cbMap = {};
|
min.cbMap = {};
|
||||||
min.scriptMap = {};
|
min.scriptMap = {};
|
||||||
|
|
|
@ -64,6 +64,7 @@ export class RootData {
|
||||||
public bootInstance: IGBInstance; // General Bot Interface Instance
|
public bootInstance: IGBInstance; // General Bot Interface Instance
|
||||||
public minInstances: any[]; //
|
public minInstances: any[]; //
|
||||||
public minBoot: GBMinInstance;
|
public minBoot: GBMinInstance;
|
||||||
|
public wwwroot: string; // .gbui or a static webapp.
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -87,6 +88,7 @@ export class GBServer {
|
||||||
GBServer.globals.appPackages = [];
|
GBServer.globals.appPackages = [];
|
||||||
GBServer.globals.sysPackages = [];
|
GBServer.globals.sysPackages = [];
|
||||||
GBServer.globals.minInstances = [];
|
GBServer.globals.minInstances = [];
|
||||||
|
GBServer.globals.wwwroot = null;
|
||||||
|
|
||||||
server.use(bodyParser.json());
|
server.use(bodyParser.json());
|
||||||
server.use(bodyParser.urlencoded({ extended: true }));
|
server.use(bodyParser.urlencoded({ extended: true }));
|
||||||
|
|
Loading…
Add table
Reference in a new issue