How to keep the conversation in a flow after 'jumpto' it?

I have an incoming hook event to jump to a flow (the start node of the flow is a single choice skill). When I click on the button of the single choice, the bot doesn’t continue the current flow, it returns to the main flow. Can anyone help me?

Your hook code would be quite helpful here.

1 Like

I created a custom module to send messages to a group users. in the module I send incoming events and catch them on incoming hook.

Add next to jumpto function await bp.dialog.processEvent(sessionId, event) // Continue processing
this will process conversation
please refer this link for more information https://botpress.com/reference/modules/botpress_sdk.dialog.html#processevent

1 Like

It does not work in my case. It always returns to the main flow.

Try to add this flag in starting of your hooks @Nghia_Nguyen

event.setFlag(bp.IO.WellKnownFlags.SKIP_DIALOG_ENGINE, true)
event.setFlag(bp.IO.WellKnownFlags.FORCE_PERSIST_STATE, true)

and after processEvent enable the SKIP_DIALOG_ENGINE

event.setFlag(bp.IO.WellKnownFlags.SKIP_DIALOG_ENGINE, false)

1 Like
function hook(bp: typeof sdk, event: sdk.IO.IncomingEvent) {
  /** Your code starts below */
  event.setFlag(bp.IO.WellKnownFlags.SKIP_DIALOG_ENGINE, true)
  event.setFlag(bp.IO.WellKnownFlags.FORCE_PERSIST_STATE, true)
  const jumpToFlow = async () => {
    try {
      if (event.type === 'rescan_with_token') {
        await jumpToRescanFlow()
      } else if (event.type === 'expired_token') {
        await jumpToRescanFlowRequireLogin()
      }
    } catch (e) {
      console.error('Error jumpToFlow quiz', e)
    }
  }

  const jumpToRescanFlow = async () => {
    const sessionId = bp.dialog.createId(event)
    await bp.dialog.jumpTo(sessionId, event, `RescanCalendar.flow.json`, 'choice-start')
    await bp.dialog.processEvent(sessionId, event)
    event.setFlag(bp.IO.WellKnownFlags.SKIP_DIALOG_ENGINE, false)
  }

  const jumpToRescanFlowRequireLogin = async () => {
    const sessionId = bp.dialog.createId(event)
    await bp.dialog.jumpTo(sessionId, event, `RescanCalendarRequireLogin.flow.json`, 'entry')
    await bp.dialog.processEvent(sessionId, event)
    event.setFlag(bp.IO.WellKnownFlags.SKIP_DIALOG_ENGINE, false)
  }

  return jumpToFlow()

  /** Your code ends here */
}

Is it right? Can you help me to put the right code? Sorry for my bad.

Yes. It’s right. Try it

1 Like

Hi @Nghia_Nguyen,

Whether it’s working has expected?

1 Like

Sorry for response lately. I tried it but it still does not work. :frowning: . It always returns to the main flow.

Whether are you using botpress nlu and qna or custom qna and nlu?

Then change your hook code to this and try

function hook(bp: typeof sdk, event: sdk.IO.IncomingEvent) {
/** Your code starts below */
event.setFlag(bp.IO.WellKnownFlags.SKIP_DIALOG_ENGINE, true)
event.setFlag(bp.IO.WellKnownFlags.FORCE_PERSIST_STATE, true)
const jumpToFlow = async () => {
try {
if (event.type === ‘rescan_with_token’) {
await jumpToRescanFlow()
} else if (event.type === ‘expired_token’) {
await jumpToRescanFlowRequireLogin()
}
} catch (e) {
console.error(‘Error jumpToFlow quiz’, e)
}
}

const jumpToRescanFlow = async () => {
const sessionId = bp.dialog.createId(event)
await bp.dialog.jumpTo(sessionId, event, RescanCalendar.flow.json, ‘choice-start’)
await bp.dialog.processEvent(sessionId, event)
}

const jumpToRescanFlowRequireLogin = async () => {
const sessionId = bp.dialog.createId(event)
await bp.dialog.jumpTo(sessionId, event, RescanCalendarRequireLogin.flow.json, ‘entry’)
await bp.dialog.processEvent(sessionId, event)
}

return jumpToFlow()

/** Your code ends here */
}

1 Like

Thank you so much but it not working in my case again. Can I create a flag in the temporary of the event then check if on the main flow to transit to the node I want?

okay. Flag cannot be created in temporary in event

1 Like

If I use the flags on the top of the hook event, the bot will execute all the next nodes in the flow it jumped to then ending flow.

If you use the flag SKIP_DIALOG_ENGINE. It will jump to your custom flow but It will not process the next node. Before the next node is called you need to enable the SKIP_DIALOG_ENGINE. Use FORCE_PERSIST_STATE to get flow details in event.context.

1 Like

Can you explain to me what is the mean of “FORCE_PERSIST_STATE” flag?

In the event there sessions like the user, temp, and context. In context objects, it basically stores in the current flow and node details. If you set SKIP_DIALOG_ENGINE is true and FORCE_PERSIST_STATE is false. Then you will unable to get current flow and node details in event.state.context.
But if you set SKIP_DIALOG_ENGINE is true and FORCE_PERSIST_STATE is true, then you can find the state.event.context with flow and node details

For details check the botpress sdk. Click here