Overview
TheStringState attribute and keeper provide string-based state management for chat sessions. Use named states to create more readable and maintainable conversation flows with descriptive state names.
StringStateAttribute
Apply this attribute to handlers to filter by string state values.Constructors
Associates the handler with a specific string state using the default sender ID resolver.Parameters:
myState(string): The specific state name to match
Associates the handler with a special state mode using the default sender ID resolver.Parameters:
specialState(SpecialState): Special state mode (NoState,AnyState)
Associates the handler with a specific state using a custom key resolver.Parameters:
myState(string): The specific state name to matchkeyResolver(IStateKeyResolver<long>): Custom key resolver for state management
Associates the handler with a special state mode using a custom key resolver.Parameters:
specialState(SpecialState): Special state modekeyResolver(IStateKeyResolver<long>): Custom key resolver
Properties
Gets the default state value, which is an empty string (
string.Empty).StringStateKeeper
Manages string state storage and transitions.Methods
Sets the string state for the specified update.Parameters:
keySource(Update): The update to use as a key sourcenewState(string): The new state name
Gets the current string state for the specified update.Parameters:
keySource(Update): The update to use as a key source
Attempts to get the state for the specified update.Parameters:
keySource(Update): The update to use as a key sourcestate(out string?): The state name if found
true if state exists; otherwise falseChecks whether a state exists for the specified update.Parameters:
keySource(Update): The update to use as a key source
true if state exists; otherwise falseCreates a new state for the specified update using the default value (empty string).Parameters:
keySource(Update): The update to use as a key source
Deletes the state for the specified update.Parameters:
keySource(Update): The update to use as a key source
Extension Methods
Convenience methods available onIHandlerContainer:
String states do not support automatic forward/backward navigation. You must explicitly set state values using
SetStringState().Usage Example
Advanced Example: Non-Linear Flow
Key Features
- Descriptive Names: Use meaningful state names for better code readability
- Flexible Flows: Easy to implement non-linear conversation flows
- Explicit Transitions: Full control over state changes
- No Automatic Navigation: Must explicitly set each state transition
When to Use String States
Use String States when:- You need descriptive, self-documenting state names
- Your conversation flow is non-linear (branches, loops)
- States don’t follow a sequential order
- You want maximum flexibility in state transitions
- You have a simple linear flow
- States follow a sequential order
- You want automatic increment/decrement
See Also
- NumericState - For sequential state management
- EnumState - For type-safe state management
- State Keepers - Base state keeper architecture