Skip to content

Commit

Permalink
fix(core): fix _findNode check
Browse files Browse the repository at this point in the history
  • Loading branch information
emirotin committed Jul 23, 2018
1 parent bdd769b commit 85795a4
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/core/botpress/src/dialog/engine.js
Expand Up @@ -423,7 +423,7 @@ bp.dialogEngine.onBeforeSessionTimeout((ctx, next) => {
this._trace('>>', 'FLOW', `"${nodeName}"`, context, null)
context = this._gotoSubflow(nodeName, context)
switchedFlow = true
} else if (/^#/.test(nodeName)) {
} else if (nodeName && nodeName[0] === '#') {
// e.g. '#success'
this._trace('<<', 'FLOW', `"${nodeName}"`, context, null)
context = this._gotoPreviousFlow(nodeName, context)
Expand Down Expand Up @@ -465,7 +465,6 @@ bp.dialogEngine.onBeforeSessionTimeout((ctx, next) => {
Current flow: ${context.currentFlow.name}
Current node: ${context.node}`
)
return this._endFlow(stateId)
}

await this._setContext(stateId, context)
Expand Down Expand Up @@ -670,10 +669,11 @@ bp.dialogEngine.onBeforeSessionTimeout((ctx, next) => {
name = _.first(chunks)
try {
args = JSON.parse(argsStr)
const actionCtx = { state: userState, s: userState, event: event, e: event }
args = _.mapValues(args, value => {
if (_.isString(value) && value.startsWith('{{') && value.endsWith('}}')) {
const key = value.substr(2, value.length - 4)
return _.get({ state: userState, s: userState, event: event, e: event }, key)
return _.get(actionCtx, key)
}
return value
})
Expand Down Expand Up @@ -744,7 +744,7 @@ bp.dialogEngine.onBeforeSessionTimeout((ctx, next) => {

const node = _.find(flow.nodes, { name: nodeName })

if (throwIfNotFound && !nodeName) {
if (throwIfNotFound && !node) {
throw new Error(`Could not find node "${nodeName}" in flow "${flow.name}"`)
}

Expand Down

0 comments on commit 85795a4

Please sign in to comment.