You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/v4sdk/bot-builder-howto-v4-state.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -53,7 +53,7 @@ public class UserProfile
53
53
The `TopicState` class has a flag to keep track of where we are in the conversation and uses conversation state to store it. The Prompt is initialized as "askName" to initiate the conversation. Once the bot receives response from the user, Prompt will be redefined as "askNumber" to initiate the next conversation. `UserProfile` class tracks user name and phone number and stores it in user state.
54
54
55
55
### Property accessors
56
-
The `EchoBotAccessors` class in our example is created as a singleton and passed into the `class EchoWithCounterBot : IBot` constructor through dependency injection. The `EchoBotAccessors` class constructor initializes a new instance of the `EchoBotAccessors` class. It contains the `ConversationState`, `UserState`, and associated `IStatePropertyAccessor`. The `conversationState` object stores the topic state and `userState` object that stores the user profile information. The `ConversationState` and `UserState` objects are created in the Startup.cs file. The conversation and user state objects are where we persist anything at the conversation and user scope.
56
+
The `EchoBotAccessors` class in our example is created as a singleton and passed into the `class EchoWithCounterBot : IBot` constructor through dependency injection. The `EchoBotAccessors` class contains the `ConversationState`, `UserState`, and associated `IStatePropertyAccessor`. The `conversationState` object stores the topic state and `userState` object that stores the user profile information. The `ConversationState` and `UserState` objects will be created later in the Startup.cs file. The conversation and user state objects are where we persist anything at the conversation and user scope.
57
57
58
58
Updated the constructor to include `UserState` as shown below:
The line `options.State.Add(ConversationState);` and `options.State.Add(userState);` add the conversation state and user state, respectively. Next, create and register state accesssors. Acessors created here are passed into the IBot-derived class on every turn. Modift the code to inclue user state as shown below:
100
+
The line `options.State.Add(ConversationState);` and `options.State.Add(userState);` add the conversation state and user state, respectively. Next, create and register state accesssors. Accessors created here are passed into the IBot-derived class on every turn. Modify the code to inclue user state as shown below:
101
101
```csharp
102
102
services.AddSingleton<EchoBotAccessors>(sp=>
103
103
{
@@ -116,17 +116,17 @@ Next, create the two accessors using `TopicState` and `UserProfile` and pass it
The conversation and user state are linked to a singleton via the `services.AddSingleton` code block and saved via a state store accessor in the code starting with `var accessors = new BotAccessor(conversationState, userState)`.
129
+
The conversation and user state are linked to a singleton via the `services.AddSingleton` code block and saved via a state store accessor in the code starting with `var accessors = new EchoBotAccessor(conversationState, userState)`.
130
130
131
131
### Use conversation and user state properties
132
132
In the `OnTurnAsync` handler of the `EchoWithCounterBot : IBot` class, modify the code to prompt for user name and then phone number. To track where we are in the conversation, we use the Prompt property defined in the TopicState. This property was initialized a "askName". Once we get the user name, we set it to "askNumber" and set the UserName to the name user typed in. After the phone number is received, you send a confirmation message and set the prompt to 'confirmation' because you are at the end of the conversation.
0 commit comments