diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a1c73a6..ac7ea92f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,78 +1,3 @@ -## [1.3.8](https://github.com/pragmatismo-io/BotServer/compare/1.3.7...1.3.8) (2019-06-18) - - -### Bug Fixes - -* **core.gbapp:** ms-rest-azure updated due to https://github.com/Azure/ms-rest-js/issues/347. ([d61d2f8](https://github.com/pragmatismo-io/BotServer/commit/d61d2f8)) -* **whatsapp.gblib:** Fixing loop behaviour. ([10d2a4a](https://github.com/pragmatismo-io/BotServer/commit/10d2a4a)) - -## [1.3.7](https://github.com/pragmatismo-io/BotServer/compare/1.3.6...1.3.7) (2019-06-05) - - -### Bug Fixes - -* **core.gbapp:** Self-replication on Azure ([f29c8c2](https://github.com/pragmatismo-io/BotServer/commit/f29c8c2)) -* **core.gbapp:** Self-replication on Azure ([4d484d0](https://github.com/pragmatismo-io/BotServer/commit/4d484d0)) - -## [1.3.6](https://github.com/pragmatismo-io/BotServer/compare/1.3.5...1.3.6) (2019-05-27) - - -### Bug Fixes - -* **core.gbapp:** Self-replication on Azure ([5f0fb3b](https://github.com/pragmatismo-io/BotServer/commit/5f0fb3b)) -* **core.gbapp:** Self-replication on Azure ([2509157](https://github.com/pragmatismo-io/BotServer/commit/2509157)) -* **core.gbapp:** Self-replication on Azure ([8850370](https://github.com/pragmatismo-io/BotServer/commit/8850370)) - -## [1.3.5](https://github.com/pragmatismo-io/BotServer/compare/1.3.4...1.3.5) (2019-05-27) - - -### Bug Fixes - -* **core.gbapp:** Self-replication on Azure ([f64cc4c](https://github.com/pragmatismo-io/BotServer/commit/f64cc4c)) - -## [1.3.4](https://github.com/pragmatismo-io/BotServer/compare/1.3.3...1.3.4) (2019-05-27) - - -### Bug Fixes - -* **core.gbapp:** Self-replication on Azure ([e82a813](https://github.com/pragmatismo-io/BotServer/commit/e82a813)) - -## [1.3.3](https://github.com/pragmatismo-io/BotServer/compare/1.3.2...1.3.3) (2019-05-27) - - -### Bug Fixes - -* **core.gbapp:** Self-replication on Azure ([bf602c6](https://github.com/pragmatismo-io/BotServer/commit/bf602c6)) -* **core.gbapp:** Self-replication on Azure ([3cca504](https://github.com/pragmatismo-io/BotServer/commit/3cca504)) -* **core.gbapp:** Self-replication on Azure ([05edafd](https://github.com/pragmatismo-io/BotServer/commit/05edafd)) - -## [1.3.2](https://github.com/pragmatismo-io/BotServer/compare/1.3.1...1.3.2) (2019-05-26) - - -### Bug Fixes - -* **core.gbapp:** Self-replication on Azure. ([2ccae38](https://github.com/pragmatismo-io/BotServer/commit/2ccae38)) -* **core.gbapp:** Self-replication on Azure. ([4b7d29d](https://github.com/pragmatismo-io/BotServer/commit/4b7d29d)) - -## [1.3.1](https://github.com/pragmatismo-io/BotServer/compare/1.3.0...1.3.1) (2019-05-25) - - -### Bug Fixes - -* **core.gbapp:** Azure deployment. ([f1b8eb2](https://github.com/pragmatismo-io/BotServer/commit/f1b8eb2)) -* **core.gbapp:** Azure deployment. ([49e1743](https://github.com/pragmatismo-io/BotServer/commit/49e1743)) -* **core.gbapp:** Azure Deployment. ([f8fab38](https://github.com/pragmatismo-io/BotServer/commit/f8fab38)) -* **core.gbapp:** ESNext in tsconfig.json to match MSFT. ([01b8dd5](https://github.com/pragmatismo-io/BotServer/commit/01b8dd5)) -* **core.gbapp:** Fixing loading of instances. ([bc9c588](https://github.com/pragmatismo-io/BotServer/commit/bc9c588)) -* **core.gbapp:** Investigating BASIC broken. ([f0ec25e](https://github.com/pragmatismo-io/BotServer/commit/f0ec25e)) -* **core.gbapp:** package.json artifacts sync. ([01d34a6](https://github.com/pragmatismo-io/BotServer/commit/01d34a6)) -* **core.gbapp:** Publishing in Azure. ([4d6779e](https://github.com/pragmatismo-io/BotServer/commit/4d6779e)) -* **core.gbapp:** Removing POC code. ([56f46f4](https://github.com/pragmatismo-io/BotServer/commit/56f46f4)) -* **kb.gbapp:** Typo fix. ([ba26578](https://github.com/pragmatismo-io/BotServer/commit/ba26578)) -* **whatsapp.gblib:** Enabling Whatsapp. ([4351b87](https://github.com/pragmatismo-io/BotServer/commit/4351b87)) -* **whatsapp.gblib:** Enabling Whatsapp. ([74f5936](https://github.com/pragmatismo-io/BotServer/commit/74f5936)) -* **whatsapp.lib:** Enabling Whatsapp. ([85249e5](https://github.com/pragmatismo-io/BotServer/commit/85249e5)) - # [1.3.0](https://github.com/pragmatismo-io/BotServer/compare/1.2.2...1.3.0) (2019-05-12) diff --git a/package.json b/package.json index b459902a..da8fc217 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "botserver", - "version": "1.3.8", + "version": "1.3.0", "description": "General Bot Community Edition open-core server.", "main": "./boot.js", "bugs": "https://github.com/pragmatismo-io/BotServer/issues", diff --git a/packages/core.gbapp/services/GBCoreService.ts b/packages/core.gbapp/services/GBCoreService.ts index 73b06546..c7b9454a 100644 --- a/packages/core.gbapp/services/GBCoreService.ts +++ b/packages/core.gbapp/services/GBCoreService.ts @@ -373,9 +373,7 @@ STORAGE_SYNC=true GBLog.info(`Loading sys package: ${e.name}...`); const p = Object.create(e.prototype) as IGBPackage; - if (e.name === 'GBWhatsappPackage') { - sysPackages.push(p); - } + sysPackages.push(p); p.loadPackage(core, core.sequelize); }); diff --git a/packages/core.gbapp/services/GBMinService.ts b/packages/core.gbapp/services/GBMinService.ts index 271f21f4..dd085c47 100644 --- a/packages/core.gbapp/services/GBMinService.ts +++ b/packages/core.gbapp/services/GBMinService.ts @@ -111,6 +111,7 @@ export class GBMinService { bootInstance: IGBInstance, server: any, appPackages: IGBPackage[], + sysPackages: IGBPackage[], instances: IGBInstance[], deployer: GBDeployer, proxyAddress: string @@ -137,7 +138,7 @@ export class GBMinService { // Build bot adapter. - const { min, adapter, conversationState } = await this.buildBotAdapter(instance, proxyAddress); + const { min, adapter, conversationState } = await this.buildBotAdapter(instance, proxyAddress, sysPackages); // Install default VBA module. @@ -145,7 +146,7 @@ export class GBMinService { // Call the loadBot context.activity for all packages. - this.invokeLoadBot(appPackages, min, server); + this.invokeLoadBot(appPackages, sysPackages, min, server); // Serves individual URL for each bot conversational interface... @@ -313,7 +314,7 @@ export class GBMinService { } } - private async buildBotAdapter(instance: any, proxyAddress: string) { + private async buildBotAdapter(instance: any, proxyAddress: string, sysPackages: IGBPackage[]) { const adapter = new BotFrameworkAdapter({ appId: instance.marketplaceId, appPassword: instance.marketplacePassword @@ -341,7 +342,7 @@ export class GBMinService { min.cbMap = {}; min.scriptMap = {}; min.sandBoxMap = {}; - min.packages = GBServer.globals.sysPackages[0]; // HACK: Whatsapp now. + min.packages = sysPackages; min.userProfile = conversationState.createProperty('userProfile'); const dialogState = conversationState.createProperty('dialogState'); @@ -352,27 +353,17 @@ export class GBMinService { return { min, adapter, conversationState }; } - private invokeLoadBot(appPackages: any[], min: GBMinInstance, server: any) { - const sysPackages: IGBPackage[] = []; - // NOTE: A semicolon is necessary before this line. - [ - GBCorePackage, - GBSecurityPackage, - GBAdminPackage, - GBKBPackage, - GBAnalyticsPackage, - GBCustomerSatisfactionPackage, - GBWhatsappPackage - ].forEach(sysPackage => { - const p = Object.create(sysPackage.prototype) as IGBPackage; - p.loadBot(min); - sysPackages.push(p); - if (sysPackage.name === 'GBWhatsappPackage') { + private invokeLoadBot(appPackages: IGBPackage[], sysPackages: IGBPackage[], min: GBMinInstance, server: any) { + let index = 0; + sysPackages.forEach(e => { + e.loadBot(min); + if (index === 6) { // TODO: Remove this magic number and use a map. const url = '/instances/:botId/whatsapp'; server.post(url, (req, res) => { - (p as any).channel.received(req, res); + (e as any).channel.received(req, res); }); } + index++; }, this); appPackages.forEach(p => { diff --git a/packages/whatsapp.gblib/index.ts b/packages/whatsapp.gblib/index.ts index c1722da9..c518ebd3 100644 --- a/packages/whatsapp.gblib/index.ts +++ b/packages/whatsapp.gblib/index.ts @@ -62,6 +62,10 @@ export class GBWhatsappPackage implements IGBPackage { } } + public getChannel() { + return this.channel; + } + public getDialogs(min: GBMinInstance) { GBLog.verbose(`getDialogs called.`); } diff --git a/packages/whatsapp.gblib/services/WhatsappDirectLine.ts b/packages/whatsapp.gblib/services/WhatsappDirectLine.ts index e6509b6a..ae504c39 100644 --- a/packages/whatsapp.gblib/services/WhatsappDirectLine.ts +++ b/packages/whatsapp.gblib/services/WhatsappDirectLine.ts @@ -222,7 +222,8 @@ export class WhatsappDirectLine extends GBService { }; try { - const result = request.post(options); + // tslint:disable-next-line: await-promise + const result = await request.post(options); GBLog.info(result); } catch (error) { GBLog.error(`Error sending message to Whatsapp provider ${error.message}`); diff --git a/src/app.ts b/src/app.ts index 62e52352..d5543eb8 100644 --- a/src/app.ts +++ b/src/app.ts @@ -57,7 +57,7 @@ const appPackages: IGBPackage[] = []; export class RootData { public publicAddress: string; public server: any; - sysPackages: any; + public sysPackages: any[]; } /** @@ -123,7 +123,7 @@ export class GBServer { // Deploys system and user packages. GBLog.info(`Deploying packages...`); - GBServer.globals.sysPackages = core.loadSysPackages(core); + const sysPackages = core.loadSysPackages(core); await core.checkStorage(azureDeployer); await deployer.deployPackages(core, server, appPackages); @@ -151,7 +151,7 @@ export class GBServer { // Builds minimal service infrastructure. const minService: GBMinService = new GBMinService(core, conversationalService, adminService, deployer); - await minService.buildMin(bootInstance, server, appPackages, instances, + await minService.buildMin(bootInstance, server, appPackages, sysPackages, instances, deployer, GBServer.globals.publicAddress); // Deployment of local applications for the first time.