我目前正在将我的机器人框架 v3 迁移到 v4。
有没有办法在 SQL 数据库上存储机器人状态?
我在这里看到了关于 Bot State 的文档:
但它只能保存在 CosmoDB 或 Azure 存储上。在 bot 框架 v4 上没有关于在 SQL 中保存状态的可用文档
在我的机器人框架 v3 中,我有以下代码将机器人状态保存到 SQL 数据库:
var store = new SqlBotDataStore(ConfigurationManager.ConnectionStrings["statedb"].ConnectionString);
Conversation.UpdateContainer(
builder =>
{
builder.Register(c => store)
.Keyed<IBotDataStore<BotData>>(AzureModule.Key_DataStore)
.AsSelf()
.SingleInstance();
builder.Register(c => new CachingBotDataStore(store,
CachingBotDataStoreConsistencyPolicy
.ETagBasedConsistency))
.As<IBotDataStore<BotData>>()
.AsSelf()
.InstancePerLifetimeScope();
builder.RegisterModule(new ReflectionSurrogateModule());
builder.RegisterModule<GlobalMessageHandlersBotModule>();
});
我希望bot框架v4有类似的功能
Bot Framework 社区为 Bot Builder V4 提供了 EntityFramework 存储。可以在此处找到源代码,该库可用作 nuget 包Bot.Builder.Community.Storage.EntityFramework
它的使用方式与其他 V4IStorage
提供程序相同:
var entityFrameworkStorage = new EntityFrameworkStorage(Config["SqlConnectionString"]);
services.AddSingleton<IStorage>(dataStore);
services.AddSingleton<UserState>();
services.AddSingleton<ConversationState>();
更多信息可以在这里找到:
https://docs.microsoft.com/en-us/azure/bot-service/bot-builder-concept-state
https://docs.microsoft.com/en-us/azure/bot-service/bot-builder-howto-v4-state
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句