Are you sure you want to delete this access key?
A stateless sample bot tracking context of a conversation using a custom storage provider.
The minimum prerequisites to run this sample are:
The Bot Framework provides several ways of persisting data relative to a user or conversation. Behind the scenes the Bot Framework uses the Bot State Service for tracking context of a conversation. This allows the creation of stateless Bot web services so that they can be scaled.
There might be times when a custom storage wants to be used. Reasons for wanting this could be many, however the most common ones are:
This bot is based on the State bot, with the addition that it uses a custom storage for tracking the context of a conversation. In this case, we are storing the bot state in DocumentDB by using the DocumentDbBotDataStore
provided in the BotBuilder SDK Azure Extensions NuGet package.
Check out the creation and registration in the Autofac container of the DocumentDbBotDataStore
in the Global.asax.cs
. By default the DocumentDbBotDataStore
will be created using the endpoint and auth key of the Azure DocumentDB Emulator. These settings are stored in the Web.config
and can be edited to use your DocumentDB database.
Also, checkout the registration of the AzureModule
, used to bundle up a set of required components
protected void Application_Start()
{
Uri docDbServiceEndpoint = new Uri(ConfigurationManager.AppSettings["DocumentDbServiceEndpoint"]);
string docDbEmulatorKey = ConfigurationManager.AppSettings["DocumentDbAuthKey"];
var builder = new ContainerBuilder();
builder.RegisterModule(new AzureModule(Assembly.GetExecutingAssembly()));
var store = new DocumentDbBotDataStore(docDbServiceEndpoint, docDbEmulatorKey);
builder.Register(c => store)
.Keyed<IBotDataStore<BotData>>(AzureModule.Key_DataStore)
.AsSelf()
.SingleInstance();
builder.Update(Conversation.Container);
GlobalConfiguration.Configure(WebApiConfig.Register);
}
The sample itself will behave exactly as the State bot with the difference that the bot state is being stored in DocumentDB.
After running the sample, go to the Azure DocumentDB Emulator Data Explorer to check the documents that were stored in DocumentDB. Different Documents are created depending on the bot store type being used.
The samples uses the three bot store types (UserData, ConversationData and PrivateConversationData), so three documents will appear in the DocumentDB collection.
Each of the documents contains the information related to the bot store type:
UserData | ConversationData | PrivateConversationData |
---|---|---|
To get more information about how to get started in Bot Builder for .NET and State please review the following resources:
Press p or to see the previous file or, n or to see the next file
Are you sure you want to delete this access key?
Are you sure you want to delete this access key?