From c6d3086fa08b53c595c2ccffcc1020d7a45d1581 Mon Sep 17 00:00:00 2001 From: Rodrigo Rodriguez Date: Fri, 3 Apr 2020 09:46:13 -0300 Subject: [PATCH] fix(core.gbapp): Fix in deploy. --- packages/core.gbapp/services/GBDeployer.ts | 5 ++-- packages/core.gbapp/services/GBMinService.ts | 25 ++++++++++++++------ packages/whatsapp.gblib/index.ts | 9 ------- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/packages/core.gbapp/services/GBDeployer.ts b/packages/core.gbapp/services/GBDeployer.ts index a962399d..a52e229a 100644 --- a/packages/core.gbapp/services/GBDeployer.ts +++ b/packages/core.gbapp/services/GBDeployer.ts @@ -529,10 +529,11 @@ export class GBDeployer implements IGBDeployer { } folder = Path.join(e, 'dist'); if (!Fs.existsSync()) { - GBLog.info(`Compiling ${e}...`); + try { - if (process.env.GBAPP_DISABLE_COMPILE !== "true") { + GBLog.info(`process.env.GBAPP_DISABLE_COMPILE: ${process.env.GBAPP_DISABLE_COMPILE}`); + if (process.env.GBAPP_DISABLE_COMPILE !== "true" && false) { child_process.execSync(Path.join(process.env.PWD, 'node_modules/.bin/tsc'), { cwd: e }); } const m = await import(e); diff --git a/packages/core.gbapp/services/GBMinService.ts b/packages/core.gbapp/services/GBMinService.ts index 6b1f884e..4db9bb65 100644 --- a/packages/core.gbapp/services/GBMinService.ts +++ b/packages/core.gbapp/services/GBMinService.ts @@ -44,6 +44,7 @@ const removeRoute = require('express-remove-route'); const AuthenticationContext = require('adal-node').AuthenticationContext; const wash = require('washyourmouthoutwithsoap'); import { AutoSaveStateMiddleware, BotFrameworkAdapter, ConversationState, MemoryStorage, UserState } from 'botbuilder'; +import { CollectionUtil } from 'pragmatismo-io-framework'; import { ConfirmPrompt, WaterfallDialog } from 'botbuilder-dialogs'; import { GBDialogStep, @@ -65,6 +66,7 @@ import { GBConfigService } from './GBConfigService'; import { GBDeployer } from './GBDeployer'; import { SecService } from '../../security.gblib/services/SecService'; import { AnalyticsService } from '../../analytics.gblib/services/AnalyticsService'; +import { WhatsappDirectLine } from '../../whatsapp.gblib/services/WhatsappDirectLine'; /** * Minimal service layer for a bot. @@ -207,7 +209,7 @@ export class GBMinService { // this.deployer.deployPackage(min, 'packages/default.gbdialog'); // Call the loadBot context.activity for all packages. - this.invokeLoadBot(GBServer.globals.appPackages, GBServer.globals.sysPackages, min); + await this.invokeLoadBot(GBServer.globals.appPackages, GBServer.globals.sysPackages, min); // Serves individual URL for each bot conversational interface... const url = `/api/messages/${instance.botId}`; @@ -402,6 +404,16 @@ export class GBMinService { min.scriptMap = {}; min.sandBoxMap = {}; min.packages = sysPackages; + if (min.instance.whatsappServiceKey !== null ) { + min.whatsAppDirectLine = new WhatsappDirectLine( + min.botId, + min.instance.whatsappBotKey, + min.instance.whatsappServiceKey, + min.instance.whatsappServiceNumber, + min.instance.whatsappServiceUrl + ); + } + min.userProfile = conversationState.createProperty('userProfile'); const dialogState = conversationState.createProperty('dialogState'); @@ -412,12 +424,11 @@ export class GBMinService { return { min, adapter, conversationState }; } - private invokeLoadBot(appPackages: IGBPackage[], sysPackages: IGBPackage[], min: GBMinInstance) { - sysPackages.forEach(e => { + private async invokeLoadBot(appPackages: IGBPackage[], sysPackages: IGBPackage[], min: GBMinInstance) { + await CollectionUtil.asyncForEach(sysPackages, async e => { e.loadBot(min); - }, this); - - appPackages.forEach(p => { + }); + await CollectionUtil.asyncForEach(appPackages, async p => { p.sysPackages = sysPackages; p.loadBot(min); if (p.getDialogs !== undefined) { @@ -426,7 +437,7 @@ export class GBMinService { min.dialogs.add(new WaterfallDialog(dialog.id, dialog.waterfall)); }); } - }, this); + }); } /** diff --git a/packages/whatsapp.gblib/index.ts b/packages/whatsapp.gblib/index.ts index fed2ccb8..a0068126 100644 --- a/packages/whatsapp.gblib/index.ts +++ b/packages/whatsapp.gblib/index.ts @@ -49,15 +49,6 @@ export class GBWhatsappPackage implements IGBPackage { public loadBot(min: GBMinInstance): void { // Only loads engine if it is defined on services.json. - if (min.instance.whatsappServiceKey !== null ) { - min.whatsAppDirectLine = new WhatsappDirectLine( - min.botId, - min.instance.whatsappBotKey, - min.instance.whatsappServiceKey, - min.instance.whatsappServiceNumber, - min.instance.whatsappServiceUrl - ); - } } public getDialogs(min: GBMinInstance) {