https://discord.gg/botpress logo
How to persist workflow variables to conversation ...
# šŸ¤help
h
Hi everyone šŸ‘‹ I’m using Botpress Cloud and have a specific problem regarding state variables, hope you can help. Use case: I have autonomous nodes (AI-driven conversation flows) where I collect user data: contact_email, company_name, client_type, loss_usd, etc. At the end of the conversation (via Timeout or Conversation End) I need to send these collected variables to a CRM system (HubSpot) via an ā€œAfter Conversation Endā€ hook. What I have now: All variables are currently stored in workflow.* scope inside the autonomous node. I’ve tried writing a hook in After Turn End to copy workflow → conversation using event.setState({...}), but those variables are still not visible in conversation when the Conversation End hook fires. I want minimal manual flow transitions: the autonomous node should collect data and then automatically transition to end, with no extra user input. Question: What is the best supported way in Botpress Cloud to transfer workflow-scope variables into the conversation scope so that they are accessible in the ā€œAfter Conversation Endā€ hook for CRM sync? Any guidance, examples or snippets would be greatly appreciated. Thanks in advance!
w
1. The [After Conversation End](https://www.botpress.com/docs/learn/reference/hooks#after-conversation-end) executes after the conversation has explicitly ended (transitioned to an End Node) > The Conversation End Workflow only executes before the conversation ends explicitly—that is, when a Workflow transitions to an End Node. > Since Autonomous Nodes don’t transition to an End Node when the user ends the conversation, they won’t transition to the Conversation End Workflow by default. 2. The [Timeout Workflow](https://www.botpress.com/docs/learn/reference/workflows#timeout) executes after a period of prolonged inactivity from the user 3. The [Conversation End Workflow](https://www.botpress.com/docs/learn/reference/workflows#conversation-end) executes right before the conversation ends explicitly. 4. AN doesn't save in the workflow; it has internal memory unless you prompt it to save in workflow variables. 5. if you want values in [conversation scope](https://www.botpress.com/docs/learn/reference/variables/scopes/conversation) you don't need to use workflow scope - I suggest using a [schema](https://www.botpress.com/docs/learn/reference/schemas) with the variables you want to save; this way, you have a customized object that helps AN too
h
Thank you so much for the clarification! I haven’t used schemas yet, but this looks like the perfect solution for persisting variables from autonomous nodes into the conversation scope. I’ll study this approach in detail and try implementing it for our HubSpot CRM integration. Really appreciate your advice - that was super helpful!šŸ™šŸ»
w
Happy to help you
In schemas, you can set a description field that is very useful for AN to understand what the variable is.
h
Another small question šŸ™‚ I’ve created a schema (CrmLead) with conversation scope and defined all my lead fields. Now I’m not sure how it actually gets triggered. Should I explicitly tell my Autonomous Node in its prompt to use this schema (like ā€˜save data into CrmLead schema fields’), or do I still need to create a hook/action to persist those values manually? What’s the recommended way for an Autonomous Node to write into a schema — purely via prompt instruction, or via a technical trigger?
w
Usually, I create [workflows with one or more input variable](https://www.botpress.com/docs/learn/reference/variables/pass-between-workflows#from-a-parent-workflow-to-a-sub-workflow) with schema type and use them as transitions out of AN. With this solution, the workflow transition card shows all the schema's variables, and you can set whether you want AN to fill them automatically (the description attributes on schema variables are important). If AN doesn't fill all the variables, I use an instruction prompt on the workflow card to explain.
A very usefull chatbot example/template is this https://botpress.com/docs/learn/guides/advanced/kitchen-sink-advanced-starter-template look custom End workflow šŸ˜‰
2 Views