Skip to content

Commit

Permalink
Merge pull request #1123 from botpress/rl_wait_for_message
Browse files Browse the repository at this point in the history
fix(engine): add wait for message support
  • Loading branch information
allardy committed Nov 15, 2018
2 parents 99556be + 93758ff commit 6e098ca
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
11 changes: 8 additions & 3 deletions src/bp/core/services/dialog/instruction/factory.ts
Expand Up @@ -14,11 +14,16 @@ export class InstructionFactory {
)
}

static createOnReceive(node, flow): Instruction[] {
static createOnReceive(node, flow): Instruction[] | undefined {
const flowReceive = _.get(flow, 'catchAll.onReceive', []) || []
const nodeReceive = _.get(node, 'onReceive', []) || []

return [...flowReceive, ...nodeReceive].map(
// We return undefined instead of an empty array so we can "wait" even when the array is empty
// Used for "wait for message"
if (!node.onReceive) {
return undefined
}

return [...flowReceive, ...node.onReceive].map(
(x): Instruction => ({
type: 'on-receive',
fn: x
Expand Down
4 changes: 2 additions & 2 deletions src/bp/core/services/dialog/queue-builder.ts
Expand Up @@ -28,10 +28,10 @@ export class InstructionsQueueBuilder {
}

const onReceive = InstructionFactory.createOnReceive(this.currentNode, this.currentFlow)
if (!_.isEmpty(onReceive)) {
if (onReceive) {
this._queue.enqueue({ type: 'wait' })
this._queue.enqueue(...onReceive)
}
this._queue.enqueue(...onReceive)
}

const transition = InstructionFactory.createTransition(this.currentNode, this.currentFlow)
Expand Down

0 comments on commit 6e098ca

Please sign in to comment.