Merge pull request #106 from rodrigorodriguez/master

fix(core.gbapp): Self-replication on Azure
This commit is contained in:
Rodrigo Rodriguez 2019-06-05 19:04:25 -03:00 committed by GitHub
commit e3b1f9b874
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 30 additions and 9 deletions

6
package-lock.json generated
View file

@ -3013,9 +3013,9 @@
"integrity": "sha512-3BWQEbArzHkw49BCdyNxqmSnLzkrL396Q0c+VcdabT3t75wV+dc4bwzSBuLfG0KW+fBjhSR4BXM8IQfnIZU0Vg==" "integrity": "sha512-3BWQEbArzHkw49BCdyNxqmSnLzkrL396Q0c+VcdabT3t75wV+dc4bwzSBuLfG0KW+fBjhSR4BXM8IQfnIZU0Vg=="
}, },
"botlib": { "botlib": {
"version": "1.2.0", "version": "1.2.1",
"resolved": "https://registry.npmjs.org/botlib/-/botlib-1.2.0.tgz", "resolved": "https://registry.npmjs.org/botlib/-/botlib-1.2.1.tgz",
"integrity": "sha512-JXA1LkRR8GEnb2W5/3N6H+aPnJv4b5J2XV9WiHo8zp9gW87i5g/F/wo8drDcqEfSOF2ZpHD3HyEFfbBcUY6C6A==", "integrity": "sha512-r9mjcag3Ttq3m6p1pewx094Os+dNLDb6rcBiTdGQMFjjeKLzqrLL3NGusYytOGyZek13TKeVciT9aU5ZQGofEQ==",
"requires": { "requires": {
"async": "2.6.2", "async": "2.6.2",
"botbuilder": "4.4.0", "botbuilder": "4.4.0",

View file

@ -65,7 +65,7 @@
"botbuilder-choices": "4.0.0-preview1.2", "botbuilder-choices": "4.0.0-preview1.2",
"botbuilder-dialogs": "4.4.0", "botbuilder-dialogs": "4.4.0",
"botbuilder-prompts": "4.0.0-preview1.2", "botbuilder-prompts": "4.0.0-preview1.2",
"botlib": "1.2.0", "botlib": "^1.2.1",
"chai": "4.2.0", "chai": "4.2.0",
"child_process": "1.0.2", "child_process": "1.0.2",
"chokidar": "3.0.0", "chokidar": "3.0.0",

View file

@ -39,6 +39,7 @@
import { GBLog, IGBCoreService, IGBInstallationDeployer, IGBInstance, IGBPackage } from 'botlib'; import { GBLog, IGBCoreService, IGBInstallationDeployer, IGBInstance, IGBPackage } from 'botlib';
import * as fs from 'fs'; import * as fs from 'fs';
import { Sequelize } from 'sequelize-typescript'; import { Sequelize } from 'sequelize-typescript';
import { GBServer } from '../../../src/app';
import { GBAdminPackage } from '../../admin.gbapp/index'; import { GBAdminPackage } from '../../admin.gbapp/index';
import { GBAdminService } from '../../admin.gbapp/services/GBAdminService'; import { GBAdminService } from '../../admin.gbapp/services/GBAdminService';
import { GBAnalyticsPackage } from '../../analytics.gblib'; import { GBAnalyticsPackage } from '../../analytics.gblib';
@ -261,6 +262,20 @@ STORAGE_SYNC=true
} }
} }
public installWebHook(isGet: boolean, url: string, callback: any) {
if (isGet) {
GBServer.globals.server.get(url, (req, res) => {
callback(req, res);
});
} else {
GBServer.globals.server.post(url, (req, res) => {
callback(req, res);
});
}
}
public async saveInstance(fullInstance: any) { public async saveInstance(fullInstance: any) {
const options = { where: {} }; const options = { where: {} };
options.where = { botId: fullInstance.botId }; options.where = { botId: fullInstance.botId };

View file

@ -47,7 +47,7 @@ const graph = require('@microsoft/microsoft-graph-client');
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, GuaribasInstance } from '../models/GBModel'; import { GuaribasPackage } 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';
@ -232,7 +232,7 @@ export class GBDeployer {
switch (packageType) { switch (packageType) {
case '.gbot': case '.gbot':
await this.deployBot(localPath, min.proxyAddress); await this.deployBot(localPath, GBServer.globals.publicAddress);
case '.gbkb': case '.gbkb':
const service = new KBService(this.core.sequelize); const service = new KBService(this.core.sequelize);
@ -371,6 +371,7 @@ export class GBDeployer {
GBLog.info(`Theme (.gbtheme) assets accessible at: /themes/${filenameOnly}.`); GBLog.info(`Theme (.gbtheme) assets accessible at: /themes/${filenameOnly}.`);
} else if (Path.extname(filename) === '.gbkb') { } else if (Path.extname(filename) === '.gbkb') {
server.use(`/kb/${filenameOnly}/subjects`, express.static(urlJoin(filename, 'subjects'))); server.use(`/kb/${filenameOnly}/subjects`, express.static(urlJoin(filename, 'subjects')));
server.use(`/kb/${filenameOnly}/images`, express.static(urlJoin(filename, 'images')));
GBLog.info(`KB (.gbkb) assets accessible at: /kb/${filenameOnly}.`); GBLog.info(`KB (.gbkb) assets accessible at: /kb/${filenameOnly}.`);
} else if (Path.extname(filename) === '.gbui') { } else if (Path.extname(filename) === '.gbui') {
// Already Handled // Already Handled

View file

@ -232,7 +232,7 @@ export class GBMinService {
*/ */
private async sendInstanceToClient(req, bootInstance: IGBInstance, res: any, webchatToken: any) { private async sendInstanceToClient(req, bootInstance: IGBInstance, res: any, webchatToken: any) {
let botId = req.params.botId; let botId = req.params.botId;
if (botId === '[default]'|| botId === undefined) { if (botId === '[default]' || botId === undefined) {
botId = GBConfigService.get('BOT_ID'); botId = GBConfigService.get('BOT_ID');
} }
const instance = await this.core.loadInstance(botId); const instance = await this.core.loadInstance(botId);
@ -377,7 +377,7 @@ export class GBMinService {
if (p.getDialogs !== undefined) { if (p.getDialogs !== undefined) {
const dialogs = p.getDialogs(min); const dialogs = p.getDialogs(min);
dialogs.forEach(dialog => { dialogs.forEach(dialog => {
min.dialogs.add(new WaterfallDialog(dialog.name, dialog.waterfall)); min.dialogs.add(new WaterfallDialog(dialog.id, dialog.waterfall));
}); });
} }
}, this); }, this);
@ -497,6 +497,9 @@ export class GBMinService {
min.sandBoxMap[mainMethod].step = step; min.sandBoxMap[mainMethod].step = step;
min.sandBoxMap[mainMethod][mainMethod].bind(min.sandBoxMap[mainMethod]); min.sandBoxMap[mainMethod][mainMethod].bind(min.sandBoxMap[mainMethod]);
await min.sandBoxMap[mainMethod][mainMethod](); await min.sandBoxMap[mainMethod][mainMethod]();
} else if (context.activity.text.charAt(0) === '/') {
await step.beginDialog(context.activity.text);
} else if (context.activity.text === 'admin') { } else if (context.activity.text === 'admin') {
await step.beginDialog('/admin'); await step.beginDialog('/admin');

View file

@ -54,7 +54,7 @@ export class CSService {
instanceId: number, instanceId: number,
questionTyped: string, questionTyped: string,
questionText: string): Promise<GuaribasQuestionAlternate> { questionText: string): Promise<GuaribasQuestionAlternate> {
return GuaribasQuestionAlternate.create({ return await GuaribasQuestionAlternate.create({
questionTyped: questionTyped, questionTyped: questionTyped,
questionText: questionText questionText: questionText
}); });

View file

@ -56,6 +56,7 @@ const appPackages: IGBPackage[] = [];
*/ */
export class RootData { export class RootData {
public publicAddress: string; public publicAddress: string;
public server: any;
} }
/** /**
@ -74,6 +75,7 @@ export class GBServer {
GBServer.globals = new RootData(); GBServer.globals = new RootData();
const port = GBConfigService.getServerPort(); const port = GBConfigService.getServerPort();
const server = express(); const server = express();
GBServer.globals.server = server;
server.use(bodyParser.json()); server.use(bodyParser.json());
server.use(bodyParser.urlencoded({ extended: true })); server.use(bodyParser.urlencoded({ extended: true }));