SessionState System
The SessionState system provides persistent storage for data throughout a flow execution. Think of it as a key-value store that persists for the entire duration of a flow run.
Overview
SessionState allows nodes to share data with each other. When you set a value in one node, other nodes can read it later in the execution. This is essential for building complex workflows where data needs to flow between multiple steps.
Key Concepts
- Keys: String identifiers for stored values
- Values: Can be strings, numbers, booleans, or JSON objects/arrays
- Scope: SessionState persists for the entire flow execution
- Type Detection: Values are automatically detected and stored with appropriate types
Available Functions
- SessionState.set() - Store a value in session state
- SessionState.get() - Retrieve a value from session state
- SessionState.del() - Delete a value from session state
- SessionState.has() - Check if a key exists
- SessionState.contains() - Check if a value contains a specific item
Common Use Cases
Storing User Input
-- Store a value from user input
SessionState.set("username", inputs.username)
Passing Data Between Nodes
-- Node 1: Set a value
SessionState.set("processedData", "some result")
-- Node 2: Get the value
local data = SessionState.get("processedData")
Conditional Logic Based on State
if SessionState.has("userAuthenticated") then
-- User is authenticated, proceed
end
Working with Complex Data
-- Store a JSON object
SessionState.set("userProfile", '{"name": "John", "age": 30}')
-- Later, retrieve and use it
local profile = SessionState.get("userProfile")
Best Practices
- Use Descriptive Keys: Choose clear, descriptive key names like
userEmailinstead ofdata1 - Check Before Use: Use
SessionState.has()to verify a key exists before retrieving it - Clean Up: Use
SessionState.del()to remove temporary data when no longer needed - Type Consistency: Be aware that values are stored with their detected types