Skip to content

Commit

Permalink
fix(core.gbapp): GB Apps can now publish bots and replace root web ap…
Browse files Browse the repository at this point in the history
…plication.
  • Loading branch information
rodrigorodriguez committed Feb 25, 2020
1 parent 283e596 commit 675c851
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 47 deletions.
69 changes: 35 additions & 34 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
},
"license": "AGPL-3.0",
"preferGlobal": true,
"private": false,
"bin": {
"gbot": "./boot.js"
},
Expand Down Expand Up @@ -45,9 +46,9 @@
"commit": "git-cz"
},
"dependencies": {
"@azure/ms-rest-js": "^2.0.4",
"@microsoft/microsoft-graph-client": "^2.0.0",
"@types/validator": "^12.0.1",
"@azure/ms-rest-js": "2.0.4",
"@microsoft/microsoft-graph-client": "2.0.0",
"@types/validator": "12.0.1",
"adal-node": "0.2.1",
"async-promises": "0.2.2",
"azure-arm-cognitiveservices": "3.0.0",
Expand All @@ -56,66 +57,66 @@
"azure-arm-sql": "5.7.0",
"azure-arm-website": "5.7.0",
"azure-search-client": "3.1.5",
"bluebird": "^3.7.2",
"bluebird": "3.7.2",
"body-parser": "1.19.0",
"botbuilder": "^4.7.0",
"botbuilder-ai": "^4.7.0",
"botbuilder-dialogs": "^4.7.0",
"botframework-connector": "^4.7.0",
"botlib": "1.3.2",
"botbuilder": "4.7.0",
"botbuilder-ai": "4.7.0",
"botbuilder-dialogs": "4.7.0",
"botframework-connector": "4.7.0",
"botlib": "1.4.0",
"chai": "4.2.0",
"cli-spinner": "0.2.10",
"csv-parse": "^4.8.3",
"dotenv-extended": "^2.7.1",
"exceljs": "^3.5.0",
"csv-parse": "4.8.3",
"dotenv-extended": "2.7.1",
"exceljs": "3.5.0",
"express": "4.17.1",
"express-remove-route": "1.0.0",
"js-beautify": "1.10.2",
"marked": "^0.8.0",
"marked": "0.8.0",
"mocha": "6.2.2",
"ms-rest-azure": "^3.0.0",
"nexmo": "^2.5.2",
"ngrok": "^3.2.7",
"npm": "^6.13.4",
"ms-rest-azure": "3.0.0",
"nexmo": "2.5.2",
"ngrok": "3.2.7",
"npm": "6.13.4",
"opn": "6.0.0",
"pragmatismo-io-framework": "1.0.20",
"public-ip": "^4.0.0",
"public-ip": "4.0.0",
"reflect-metadata": "0.1.13",
"request-promise": "4.2.5",
"request-promise-native": "1.0.8",
"rimraf": "^3.0.0",
"scanf": "^1.1.1",
"sequelize-typescript": "^1.1.0",
"rimraf": "3.0.0",
"scanf": "1.1.1",
"sequelize-typescript": "1.1.0",
"shx": "0.3.2",
"simple-git": "^1.129.0",
"simple-git": "1.129.0",
"sppull": "2.5.1",
"strict-password-generator": "1.1.2",
"swagger-client": "^3.9.6",
"tedious": "^6.6.5",
"typedoc": "^0.15.6",
"typescript": "^3.7.4",
"swagger-client": "3.9.6",
"tedious": "6.6.5",
"typedoc": "0.15.6",
"typescript": "3.7.4",
"url-join": "4.0.1",
"vbscript-to-typescript": "1.0.8",
"wait-until": "0.0.2",
"walk-promise": "0.2.0",
"washyourmouthoutwithsoap": "^1.0.2"
"washyourmouthoutwithsoap": "1.0.2"
},
"devDependencies": {
"@types/chai": "^4.2.7",
"@types/chai": "4.2.7",
"@types/mocha": "5.2.7",
"@types/url-join": "4.0.0",
"@types/winston": "2.4.4",
"ban-sensitive-files": "1.9.2",
"commitizen": "^4.0.3",
"cz-conventional-changelog": "^3.0.2",
"dependency-check": "^4.1.0",
"commitizen": "4.0.3",
"cz-conventional-changelog": "3.0.2",
"dependency-check": "4.1.0",
"git-issues": "1.3.1",
"license-checker": "25.0.1",
"nsp": "3.2.1",
"prettier-standard": "^16.1.0",
"semantic-release": "^15.14.0",
"prettier-standard": "16.1.0",
"semantic-release": "15.14.0",
"travis-deploy-once": "5.0.11",
"ts-node": "^8.5.4",
"ts-node": "8.5.4",
"tslint": "5.20.1"
},
"eslintConfig": {
Expand Down
15 changes: 15 additions & 0 deletions packages/core.gbapp/services/GBConversationalService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { LuisRecognizer } from 'botbuilder-ai';
import { GBDialogStep, GBLog, GBMinInstance, IGBConversationalService, IGBCoreService } from 'botlib';
import { AzureText } from 'pragmatismo-io-framework';
import { Messages } from '../strings';
const PasswordGenerator = require("strict-password-generator").default;
const Nexmo = require('nexmo');

export interface LanguagePickerSettings {
Expand All @@ -59,6 +60,20 @@ export class GBConversationalService implements IGBConversationalService {
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) {
return step.context.activity.locale;
}
Expand Down
6 changes: 6 additions & 0 deletions packages/core.gbapp/services/GBCoreService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,12 @@ STORAGE_SYNC=true
}
}

public setWWWRoot(localPath: string)
{
GBServer.globals.wwwroot = localPath;
}


public async deleteInstance(botId: string) {
const options = { where: {} };
options.where = { botId: botId };
Expand Down
29 changes: 21 additions & 8 deletions packages/core.gbapp/services/GBDeployer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const rimraf = require('rimraf');
import { GBError, GBLog, GBMinInstance, IGBCoreService, IGBInstance, IGBPackage } from 'botlib';
import { AzureSearch } from 'pragmatismo-io-framework';
import { GBServer } from '../../../src/app';
import { GuaribasPackage } from '../models/GBModel';
import { GuaribasPackage, GuaribasInstance } from '../models/GBModel';
import { GBAdminService } from './../../admin.gbapp/services/GBAdminService';
import { AzureDeployerService } from './../../azuredeployer.gbapp/services/AzureDeployerService';
import { KBService } from './../../kb.gbapp/services/KBService';
Expand Down Expand Up @@ -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.
*/

public async deployBot(localPath: string, publicAddress: string): Promise<void> {
const packageName = Path.basename(localPath);
public async deployBotFull(instance: IGBInstance, publicAddress: string): Promise<void> {

const service = new AzureDeployerService(this);
let instance = await this.importer.importIfNotExistsBotPackage(undefined, packageName, localPath);

const username = GBConfigService.get('CLOUD_USERNAME');
const password = GBConfigService.get('CLOUD_PASSWORD');
const group = GBConfigService.get('CLOUD_GROUP');
Expand Down Expand Up @@ -227,9 +231,18 @@ export class GBDeployer {
await GBServer.globals.minService.mountBot(instance);
}
await this.core.saveInstance(instance);

}

/**
* 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.
Expand Down Expand Up @@ -276,7 +289,7 @@ export class GBDeployer {

switch (packageType) {
case '.gbot':
await this.deployBot(localPath, GBServer.globals.publicAddress);
await this.deployBotFromLocalPath(localPath, GBServer.globals.publicAddress);
break;

case '.gbkb':
Expand Down Expand Up @@ -406,7 +419,7 @@ export class GBDeployer {
await CollectionUtil.asyncForEach(botPackages, async e => {
if (e !== 'packages\\boot.gbot') {
GBLog.info(`Deploying bot: ${e}...`);
await _this.deployBot(e, GBServer.globals.publicAddress);
await _this.deployBotFromLocalPath(e, GBServer.globals.publicAddress);
GBLog.info(`Bot: ${e} deployed...`);
}
});
Expand Down
12 changes: 8 additions & 4 deletions packages/core.gbapp/services/GBImporterService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,18 @@ export class GBImporter {
const instance = await this.core.loadInstance(botId);

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);
}

public async createBotInstance(botId: string) {
let fullSettingsJson = { ...GBServer.globals.bootInstance };
fullSettingsJson.botId = botId;
return await GuaribasInstance.create(fullSettingsJson);
}


private async createOrUpdateInstanceInternal(instance: IGBInstance,
botId: string, localPath: string, settingsJson: any) {
let packageJson = JSON.parse(fs.readFileSync(urlJoin(localPath, 'package.json'), 'utf8'));
Expand All @@ -83,9 +90,6 @@ export class GBImporter {
if (instance !== null) {
instance = { ...instance, ...fullSettingsJson };

if (instance.botId === undefined || instance.botId === null) {
console.log("••• Atenção botId é nulo ou undefined");
}
return await this.core.saveInstance(instance);
} else {
return await GuaribasInstance.create(fullSettingsJson);
Expand Down
6 changes: 5 additions & 1 deletion packages/core.gbapp/services/GBMinService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,10 @@ export class GBMinService {
) {
// Serves default UI on root address '/' if web enabled.
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
// instance information stored on server.
Expand Down Expand Up @@ -382,6 +385,7 @@ export class GBMinService {
min.core = this.core;
min.conversationalService = this.conversationalService;
min.adminService = this.adminService;
min.deployer = this.deployer;
min.instance = await this.core.loadInstance(min.botId);
min.cbMap = {};
min.scriptMap = {};
Expand Down
2 changes: 2 additions & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export class RootData {
public bootInstance: IGBInstance; // General Bot Interface Instance
public minInstances: any[]; //
public minBoot: GBMinInstance;
public wwwroot: string; // .gbui or a static webapp.
}

/**
Expand All @@ -87,6 +88,7 @@ export class GBServer {
GBServer.globals.appPackages = [];
GBServer.globals.sysPackages = [];
GBServer.globals.minInstances = [];
GBServer.globals.wwwroot = null;

server.use(bodyParser.json());
server.use(bodyParser.urlencoded({ extended: true }));
Expand Down

0 comments on commit 675c851

Please sign in to comment.