Make sure these checkboxes are checked before raising an issue, thank you!
8.9For our use case, we need to be able to direct users to a certain flow at a certain point in time, depending on a variety of other conditions.
We have found the jumpTo method, but the documentation states that simply jumping to a flow will not continue processing.
The example recipe is using a call to processMessage to continue processing the new flow.
As for us this needs to happen outside of the context of a bp.hear call, it means that we don't have access to an event object, and as such cannot make the call to processMessage.
We've tried to create a mock event object and pass that along, but BotPress relies on some of the data on the event object to contain class instances with methods etc. so that didn't work.
We are aware of sendToUser but we don't want to send a single message, but rather send the first message in the flow.
Questions:
processMessage?event object for a specific user so that we can then use that in processMessage?Essentially we just need to be able to direct a conversation to start from a specific node in a specific flow, at a time of our choosing, and for BotPress to start processing that node.
An extra parameter in the jumpTo call to indicate that processing should start immediately would be ideal if this is possible.
@adamreisnz , just curious, what is the usecase for calling jumpTo outside bp.hear?
@epaminond
For our use case, we need to be able to direct users to a certain flow at a certain point in time, depending on a variety of other conditions.
This means that the flow switch needs to happen not after a users talks to the bot, but maybe at 9am the next week when they've gone through a certain previous flow.
The bot needs to be able to send the user messages at a certain time, and depending on a variety of conditions. Not just simple messages with sendToUser, but actually starting a flow and sending the first message in the flow.
You should probably take a look at the botpress scheduler module. I am using it in the way you describe. You can just pass a jumpTo in the action param of the scheduler and set a time when the action should be sent.
https://github.com/botpress/botpress/tree/master/modules/scheduler
We've looked at the botpress scheduler module, but at first glance it suffered from the same limitations; it can only send one-off messages from what I could see, and not actually jump to a flow and begin with the first message of the flow.
I'll gladly be proven wrong though :)
Yes, does anyone have code for what @adamreisnz is asking for. I need help with this also. How do I call jumpTo inside the scheduler action? The jumpTo takes a lot of parameters that aren't available inside the action of the scheduler. Please help!! Thanks!
@Aqually please help, thanks!!
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
@adamreisnz did you figure this out? I have a similar need in #1300 were I wrote a function to be used as an action, but it only process the one msg not the whole flow.
Best to check with @mhjb
@Haythamamin here's how we do it:
function jumpTo(bp, id, flow){
bp.dialogEngine.jumpTo(
id,
flow.target,
'dispatch',
{resetState:true}).catch(error => {
console.error('Error: ', error);
});
flow.content.forEach((text) => {
setTimeout(() => {
bp.renderers.sendToUser(id, text);
}, 2000);
})
}
We first subscribe the users to the flow (which doesn't send them anything), then a couple of seconds later send them a bit of content, like "Ready to keep going?". When the user responds to the content, it's handled by the flow subscribed to.
@mhjb , You use this as an action? So in the GUI user pass parameters and the function executes?
we trigger it daily, with Heroku Scheduler running a script specified in package.json, that adds a one-off task to Botpress Scheduler:
const request = require('request-promise')
const [,, arg] = process.argv
const url = `${botUrl}/api/botpress-scheduler/schedules`
const headers = {
'Content-Type': 'application/json'
}
const now = Date()
const body = {
id: `dispatch-${now}`,
enabled: true,
schedule_type: "once",
schedule: now,
action: arg && arg.toLowerCase() === 'friday' ? "bp.dispatch.friday(bp)" : "bp.dispatch.all(bp)"
}
request
.put({
url: url,
body: JSON.stringify(body, null, 4),
headers: headers
})
.catch(console.error)
@epaminond This can be closed as well!
Most helpful comment
Best to check with @mhjb