diff --git a/CHANGELOG.md b/CHANGELOG.md index 88f6393b..ac7ea92f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,70 +1,3 @@ -## [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 78e028b6..da8fc217 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "botserver", - "version": "1.3.7", + "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 bb28c303..73b06546 100644 --- a/packages/core.gbapp/services/GBCoreService.ts +++ b/packages/core.gbapp/services/GBCoreService.ts @@ -305,11 +305,15 @@ STORAGE_SYNC=true const instance = instances[0]; if (process.env.NODE_ENV === 'development') { GBLog.info(`Updating bot endpoint to local reverse proxy (ngrok)...`); - await installationDeployer.updateBotProxy( - instance.botId, - instance.botId, - `${proxyAddress}/api/messages/${instance.botId}` - ); + try { + await installationDeployer.updateBotProxy( + instance.botId, + instance.botId, + `${proxyAddress}/api/messages/${instance.botId}` + ); + } catch (error) { + throw new Error(`Error updating bot proxy with proxy address${error.message}.`); + } } } catch (error) { if (error.parent === undefined) { @@ -356,7 +360,7 @@ STORAGE_SYNC=true // NOTE: if there is any code before this line a semicolon // will be necessary before this line. // Loads all system packages. - + const sysPackages: IGBPackage[] = []; [ GBAdminPackage, GBAnalyticsPackage, @@ -367,9 +371,15 @@ STORAGE_SYNC=true GBWhatsappPackage ].forEach(e => { GBLog.info(`Loading sys package: ${e.name}...`); + const p = Object.create(e.prototype) as IGBPackage; + if (e.name === 'GBWhatsappPackage') { + sysPackages.push(p); + } p.loadPackage(core, core.sequelize); }); + + return sysPackages; } public ensureAdminIsSecured() { diff --git a/packages/core.gbapp/services/GBMinService.ts b/packages/core.gbapp/services/GBMinService.ts index 7d48a084..271f21f4 100644 --- a/packages/core.gbapp/services/GBMinService.ts +++ b/packages/core.gbapp/services/GBMinService.ts @@ -36,15 +36,12 @@ 'use strict'; -const { DialogSet, TextPrompt } = require('botbuilder-dialogs'); import urlJoin = require('url-join'); +const { DialogSet, TextPrompt } = require('botbuilder-dialogs'); const express = require('express'); - const request = require('request-promise-native'); const AuthenticationContext = require('adal-node').AuthenticationContext; - import { AutoSaveStateMiddleware, BotFrameworkAdapter, ConversationState, MemoryStorage, UserState } from 'botbuilder'; - import { ConfirmPrompt, WaterfallDialog } from 'botbuilder-dialogs'; import { GBDialogStep, @@ -57,6 +54,8 @@ import { IGBPackage } from 'botlib'; +import { MicrosoftAppCredentials } from 'botframework-connector'; +import { GBServer } from '../../../src/app'; import { GBAnalyticsPackage } from '../../analytics.gblib'; import { GBCorePackage } from '../../core.gbapp'; import { GBCustomerSatisfactionPackage } from '../../customer-satisfaction.gbapp'; @@ -66,8 +65,8 @@ import { GBSecurityPackage } from '../../security.gblib'; import { GBWhatsappPackage } from '../../whatsapp.gblib'; import { Messages } from '../strings'; import { GBAdminPackage } from './../../admin.gbapp/index'; -import { GBDeployer } from './GBDeployer'; import { GBConfigService } from './GBConfigService'; +import { GBDeployer } from './GBDeployer'; /** * Minimal service layer for a bot. @@ -319,12 +318,16 @@ export class GBMinService { appId: instance.marketplaceId, appPassword: instance.marketplacePassword }); - const storage = new MemoryStorage(); + const conversationState = new ConversationState(storage); const userState = new UserState(storage); adapter.use(new AutoSaveStateMiddleware(conversationState, userState)); + MicrosoftAppCredentials.trustServiceUrl('https://directline.botframework.com', + new Date(new Date().setFullYear(new Date().getFullYear() + 10))); + + // The minimal bot is built here. const min = new GBMinInstance(); @@ -338,6 +341,7 @@ export class GBMinService { min.cbMap = {}; min.scriptMap = {}; min.sandBoxMap = {}; + min.packages = GBServer.globals.sysPackages[0]; // HACK: Whatsapp now. min.userProfile = conversationState.createProperty('userProfile'); const dialogState = conversationState.createProperty('dialogState'); @@ -401,6 +405,7 @@ export class GBMinService { step.context.activity.locale = 'pt-BR'; try { + const user = await min.userProfile.get(context, {}); if (!user.loaded) { @@ -423,14 +428,11 @@ export class GBMinService { ); if (context.activity.type === 'conversationUpdate' && context.activity.membersAdded.length > 0) { const member = context.activity.membersAdded[0]; - if (member.name === 'GeneralBots') { + if (member.name === min.instance.title) { GBLog.info(`Bot added to conversation, starting chat...`); appPackages.forEach(e => { e.onNewSession(min, step); }); - // Processes the root dialog. - - await step.beginDialog('/'); } else { GBLog.info(`Member added to conversation: ${member.name}`); } diff --git a/packages/whatsapp.gblib/index.ts b/packages/whatsapp.gblib/index.ts index 80c268e8..c1722da9 100644 --- a/packages/whatsapp.gblib/index.ts +++ b/packages/whatsapp.gblib/index.ts @@ -57,8 +57,7 @@ export class GBWhatsappPackage implements IGBPackage { min.instance.whatsappBotKey, min.instance.whatsappServiceKey, min.instance.whatsappServiceNumber, - min.instance.whatsappServiceUrl, - min.instance.botId + min.instance.whatsappServiceUrl ); } } diff --git a/packages/whatsapp.gblib/services/WhatsappDirectLine.ts b/packages/whatsapp.gblib/services/WhatsappDirectLine.ts index 442bebf4..e6509b6a 100644 --- a/packages/whatsapp.gblib/services/WhatsappDirectLine.ts +++ b/packages/whatsapp.gblib/services/WhatsappDirectLine.ts @@ -67,7 +67,7 @@ export class WhatsappDirectLine extends GBService { const result = request.post(options); GBLog.info(result); } catch (error) { - GBLog.error(`Error initializing 3rd party Whatsapp provider(1) ${error}`); + GBLog.error(`Error initializing 3rd party Whatsapp provider(1) ${error.message}`); } }); } @@ -92,7 +92,7 @@ export class WhatsappDirectLine extends GBService { .then(response => { return response.obj.conversationId; }).catch(err => { - GBLog.error(`Error calling Conversations_StartConversation on Whatsapp channel ${err}`); + GBLog.error(`Error calling Conversations_StartConversation on Whatsapp channel ${err.data}`); }) .then(generatedConversationId => { @@ -102,14 +102,14 @@ export class WhatsappDirectLine extends GBService { this.pollMessages(client, generatedConversationId, from, fromName); }) .catch(err => { - GBLog.error(`Error starting conversation ${err}`); + GBLog.error(`Error starting conversation ${err.data}`); }); } else { this.inputMessage(client, conversationId, text, from, fromName); } res.end(); }).catch(err => { - GBLog.error(`Error initializing DirectLine for Whatsapp channel ${err}`); + GBLog.error(`Error initializing DirectLine for Whatsapp channel ${err.data}`); }); } @@ -128,7 +128,7 @@ export class WhatsappDirectLine extends GBService { replyToId: from } }).catch(err => { - GBLog.error(`GBWhatsapp: Error receiving message: ${err}.`); + GBLog.error(`GBWhatsapp: Error receiving message: ${err.data}.`); }); } @@ -147,13 +147,13 @@ export class WhatsappDirectLine extends GBService { return response.obj.activities; }) .catch(err => { - GBLog.error(`Error calling Conversations_GetActivities on Whatsapp channel ${err}`); + GBLog.error(`Error calling Conversations_GetActivities on Whatsapp channel ${err.data}`); }) .then(activities => { this.printMessages(activities, conversationId, from, fromName); }) .catch(err => { - GBLog.error(`Error calling printMessages on Whatsapp channel ${err}`); + GBLog.error(`Error calling printMessages on Whatsapp channel ${err.data}`); }); }, this.pollInterval); @@ -225,7 +225,7 @@ export class WhatsappDirectLine extends GBService { const result = request.post(options); GBLog.info(result); } catch (error) { - GBLog.error(`Error sending message to Whatsapp provider ${error}`); + GBLog.error(`Error sending message to Whatsapp provider ${error.message}`); } } } diff --git a/src/app.ts b/src/app.ts index 6485ccc1..62e52352 100644 --- a/src/app.ts +++ b/src/app.ts @@ -57,6 +57,7 @@ const appPackages: IGBPackage[] = []; export class RootData { public publicAddress: string; public server: any; + sysPackages: any; } /** @@ -122,7 +123,7 @@ export class GBServer { // Deploys system and user packages. GBLog.info(`Deploying packages...`); - core.loadSysPackages(core); + GBServer.globals.sysPackages = core.loadSysPackages(core); await core.checkStorage(azureDeployer); await deployer.deployPackages(core, server, appPackages);