BotState Class
- java.
lang. Object - com.
microsoft. bot. builder. BotState
- com.
Implements
public abstract class BotState
implements PropertyManager
Defines a state management object and automates the reading and writing of associated state properties to a storage layer.
Each state management object defines a scope for a storage layer. State properties are created within a state management scope, and the Bot Framework defines these scopes: ConversationState, UserState, and PrivateConversationState. You can define additional scopes for your bot.
Constructor Summary
| Constructor | Description |
|---|---|
| BotState(Storage withStorage, String withContextServiceKey) |
Initializes a new instance of the Bot |
Method Summary
| Modifier and Type | Method and Description |
|---|---|
|
State |
<T>createProperty(String name)
Creates a named state property within the scope of a Bot |
| protected java.util.concurrent.CompletableFuture<T> |
<T>getPropertyValue(TurnContext turnContext, String propertyName)
Gets the value of a property from the state cache for this Bot |
| java.util.concurrent.CompletableFuture<java.lang.Void> |
clearState(TurnContext turnContext)
Clears the state cache for this Bot |
| java.util.concurrent.CompletableFuture<java.lang.Void> |
delete(TurnContext turnContext)
Delete any state currently stored in this state scope. |
| protected java.util.concurrent.CompletableFuture<java.lang.Void> |
deletePropertyValue(TurnContext turnContext, String propertyName)
Deletes a property from the state cache for this Bot |
| com.fasterxml.jackson.databind.JsonNode |
get(TurnContext turnContext)
Gets a copy of the raw cached data for this Bot |
|
Cached |
getCachedState(TurnContext turnContext)
Gets the cached bot state instance that wraps the raw cached data for this Bot |
| abstract java.lang.String |
getStorageKey(TurnContext turnContext)
When overridden in a derived class, gets the key to use when reading and writing state to and from storage. |
| java.util.concurrent.CompletableFuture<java.lang.Void> |
load(TurnContext turnContext)
Populates the state cache for this Bot |
| java.util.concurrent.CompletableFuture<java.lang.Void> |
load(TurnContext turnContext, boolean force)
Reads in the current state object and caches it in the context object for this turn. |
| java.util.concurrent.CompletableFuture<java.lang.Void> |
saveChanges(TurnContext turnContext)
Writes the state cache for this Bot |
| java.util.concurrent.CompletableFuture<java.lang.Void> |
saveChanges(TurnContext turnContext, boolean force)
Writes the state cache for this Bot |
| protected java.util.concurrent.CompletableFuture<java.lang.Void> |
setPropertyValue(TurnContext turnContext, String propertyName, Object value)
Sets the value of a property in the state cache for this Bot |
Methods inherited from java.lang.Object
Constructor Details
BotState
public BotState(Storage withStorage, String withContextServiceKey)
Initializes a new instance of the BotState class.
Parameters:
Throws:
Method Details
<T>createProperty
public StatePropertyAccessor
Creates a named state property within the scope of a BotState and returns an accessor for the property.
Parameters:
Returns:
Throws:
<T>getPropertyValue
protected CompletableFuture
Gets the value of a property from the state cache for this BotState.
Parameters:
Returns:
clearState
public CompletableFuture
Clears the state cache for this BotState.
This method clears the state cache in the turn context. Call saveChanges(TurnContext turnContext, boolean force) to persist this change in the storage layer.
Parameters:
Returns:
delete
public CompletableFuture
Delete any state currently stored in this state scope.
Parameters:
Returns:
deletePropertyValue
protected CompletableFuture
Deletes a property from the state cache for this BotState.
Parameters:
Returns:
get
public JsonNode get(TurnContext turnContext)
Gets a copy of the raw cached data for this BotState from the turn context.
Parameters:
Returns:
getCachedState
public BotState.CachedBotState getCachedState(TurnContext turnContext)
Gets the cached bot state instance that wraps the raw cached data for this BotState from the turn context.
Parameters:
Returns:
getStorageKey
public abstract String getStorageKey(TurnContext turnContext)
When overridden in a derived class, gets the key to use when reading and writing state to and from storage.
Parameters:
Returns:
Throws:
load
public CompletableFuture
Populates the state cache for this BotState from the storage layer.
Parameters:
Returns:
load
public CompletableFuture
Reads in the current state object and caches it in the context object for this turn.
Parameters:
Returns:
saveChanges
public CompletableFuture
Writes the state cache for this BotState to the storage layer.
Parameters:
Returns:
saveChanges
public CompletableFuture
Writes the state cache for this BotState to the storage layer.
Parameters:
Returns:
setPropertyValue
protected CompletableFuture
Sets the value of a property in the state cache for this BotState.
Parameters:
Returns: