Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [3.73.14]
## [3.74.0]

### Fixed

- snapshots now can have a prop called deployedConfiguration and that will be merged into configuration

## [3.73.15]

### Fixed

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wingbot",
"version": "3.73.15",
"version": "3.74.0",
"description": "Enterprise Messaging Bot Conversation Engine",
"main": "index.js",
"type": "commonjs",
Expand Down
27 changes: 24 additions & 3 deletions src/BuildRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,12 @@ class BuildRouter extends Router {
if (!snapshot) {
snapshot = await this.loadBot();
}
this.buildWithSnapshot(snapshot.blocks);
this.buildWithSnapshot(
snapshot.blocks,
undefined,
undefined,
snapshot.deployedConfiguration
);
} catch (e) {
if (this._configTs > 0 && !snapshot) {
// mute
Expand Down Expand Up @@ -437,7 +442,12 @@ class BuildRouter extends Router {
// wait for running request
await Promise.all(this._runningReqs);

this.buildWithSnapshot(snapshot.blocks, snapshot.timestamp, snapshot.lastmod);
this.buildWithSnapshot(
snapshot.blocks,
snapshot.timestamp,
snapshot.lastmod,
snapshot.deployedConfiguration
);
} catch (e) {
await configStorage.invalidateConfig();
throw e;
Expand Down Expand Up @@ -528,9 +538,20 @@ class BuildRouter extends Router {
blocks.forEach((b) => this._validateBlock(b, action));
}

buildWithSnapshot (blocks, setConfigTimestamp = Number.MAX_SAFE_INTEGER, lastmod = '-') {
buildWithSnapshot (blocks, setConfigTimestamp = Number.MAX_SAFE_INTEGER, lastmod = '-', deployedConfiguration = null) {
this._validateBlocks(blocks);

if (deployedConfiguration && typeof deployedConfiguration === 'object') {
if (this._configuration instanceof Promise) {
this._configuration = this._configuration
.then((c) => Object.assign(c || /** @type {C} */ ({}), deployedConfiguration));
} else {
const cfg = this._configuration || /** @type {C} */ ({});
Object.assign(cfg, deployedConfiguration);
this._configuration = cfg;
}
}

Object.assign(this._resolvedContext, {
blocks,
nestedBlocksByStaticId: null
Expand Down
7 changes: 6 additions & 1 deletion src/graphApi/validateBotApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ const apiAuthorizer = require('./apiAuthorizer');
*/
async function validate (bot, validationRequestBody, postBackTest = null, textTest = null) {
try {
bot.buildWithSnapshot(validationRequestBody.blocks, Number.MAX_SAFE_INTEGER);
bot.buildWithSnapshot(
validationRequestBody.blocks,
Number.MAX_SAFE_INTEGER,
undefined,
validationRequestBody.deployedConfiguration
);
} catch (e) {
const error = `Bot build failed: ${e.message}`;
// eslint-disable-next-line no-console
Expand Down
141 changes: 141 additions & 0 deletions test/buildRouterConfiguration.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,145 @@ describe('<buildRouterConfiguration>', () => {

});

describe('deployedConfiguration', () => {

it('should merge deployedConfiguration into c variables', async () => {
const blocks = [
{
isRoot: true,
blockName: 'Root',
staticBlockId: 'root-block',
routes: [
{
id: 1,
path: 'start',
isEntryPoint: true,
isFallback: false,
resolvers: [
{
type: 'botbuild.message',
params: {
text: [
'Hello {{c.brandEmail}}'
],
replies: []
}
}
]
}
]
}
];

const rootBlock = blocks.find((b) => b.isRoot);
// @ts-ignore
const bot = new BuildRouter(rootBlock, new Plugins(), {
blocks,
configuration: {}
});

bot.buildWithSnapshot(blocks, undefined, undefined, {
brandEmail: 'test@example.com'
});

const tester = new Tester(bot);

await tester.postBack('start');

tester.any().contains('Hello test@example.com');
});

it('should merge deployedConfiguration with existing configuration', async () => {
const blocks = [
{
isRoot: true,
blockName: 'Root',
staticBlockId: 'root-block',
routes: [
{
id: 1,
path: 'start',
isEntryPoint: true,
isFallback: false,
resolvers: [
{
type: 'botbuild.message',
params: {
text: [
'{{c.existing}} {{c.brandEmail}}'
],
replies: []
}
}
]
}
]
}
];

const rootBlock = blocks.find((b) => b.isRoot);
// @ts-ignore
const bot = new BuildRouter(rootBlock, new Plugins(), {
blocks,
configuration: { existing: 'keep' }
});

bot.buildWithSnapshot(blocks, undefined, undefined, {
brandEmail: 'hello@brand.com'
});

const tester = new Tester(bot);

await tester.postBack('start');

tester.any().contains('keep hello@brand.com');
});

it('should work without deployedConfiguration', async () => {
const blocks = [
{
isRoot: true,
blockName: 'Root',
staticBlockId: 'root-block',
routes: [
{
id: 1,
path: 'start',
isEntryPoint: true,
isFallback: false,
resolvers: [
{
type: 'botbuild.message',
params: {
text: [
'Hello world'
],
replies: []
}
}
]
}
]
}
];

const rootBlock = blocks.find((b) => b.isRoot);
// @ts-ignore
const bot = new BuildRouter(rootBlock, new Plugins(), {
blocks,
configuration: { foo: 'bar' }
});

bot.buildWithSnapshot(blocks);

const tester = new Tester(bot);

await tester.postBack('start');

tester.any().contains('Hello world');
assert.equal(/** @type {any} */ (bot.configuration).foo, 'bar');
});

});

});
Loading