https://discord.gg/botpress logo
Execute Workflow from an Execute Code Card
# 👀feature-requests
t
The title says it all. If this isn't a feature that is possible then can someone please tell me why? To my understand it is possible when run local but just not in the cloud? C'mon fam.
w
when , in your code, you need to execute a workflow, you can just fill a variable workflow.run_wk = true and then use a transition card and if this variable is true you transition to this workflow
t
True that, then just set it false in the next flow to reuse
Just thought it would be nice to just say, execute('workflow_name') in the code and be done with it
f
We still need this for the hooks
w
100%
w
my 2 cents: * A bot can have more than one workflow with the same name, so you need to know the workflow ID. Alternatively, the studio should deny the use of the same name * We need to pass values if workflow has input variables, but workflow has different number of variables of different types * Why don't have an arguments to go to a specif node of workflow?
Copy code
ts
/* node should be null or empty string '' */
function myFunction(workflow: string, node: string, ...params: { [key: string]: any }[]): void {
    // Function implementation here
}
// Usage example
processWorkflow('MyWorkflow', 'StartNode', { key1: 'value1' }, { key2: 42, key3: true });
t
YES
l
Note: this feature would introduce a lot of issues: 1. running a workflow from inside a code block would imply stopping execution of any further code in this code card. Moreover -- any nodes that follow it. 2. Workflows in botpress are not run on their own, but are connected to other flows and have input and output variables. If you just run workflow without that being specified, does it mean that the bot should stop after the workflow is executed? If not, where do you define what it should do next? In short, it's a whole bag of worms, that does not occur with expression routing.
w
Sorry, but that is exactly what we want to do: stop the execution and go to the workflow or node without setting a variable in the execute card and checking it, and then continue the flow from there. My function has input arguments
l
Oh, I see. So the idea would be to run a particular workflow instance placed in a particular node? This does sound convenient. Interesting to see what are the performance/safety implications: now when the conversation flow is defined via ui and is represented in the bot's json structure, the BP backend can run checks, observe and prevent recursion etc. But if the flow is to be made arbitrarily dynamic from code cards, it seems that it would make it much harder to track. But those are speculations on my end. Curious what the Botpress Team has to say 🙂
w
You are right; it can be a bit more complex to see the flow because it’s not the UI. However, in some cases, it may be simpler for a developer to define logic in a single execution card rather than adding many transition cards with expressions or workflows. The developer should know exactly what he wants to do. A non-developer may design the entire flow and workflow, while a developer can add logic that a non-developer cannot implement in the UI.
5 Views