由于我们被迫放弃状态客户端并转移到自定义存储空间,在我的情况下是azure table storage。使用我的storageexplorer,我可以看到它已经在我的azure上保存了对话数据。如何更新我的ff代码以获取过去的聊天记录?在我使用IActivityLogger类来记录对话之前,现在我对如何更新它感到困惑。
Global Asax Before:
protected void Application_Start()
{
var builder = new ContainerBuilder();
builder.RegisterType<Logger>().AsImplementedInterfaces().InstancePerDependency();
builder.Update(Conversation.Container);
GlobalConfiguration.Configure(WebApiConfig.Register);
}
Global Asax After:
protected void Application_Start()
{
Conversation.UpdateContainer(builder =>
{
builder.RegisterModule(new AzureModule(Assembly.GetExecutingAssembly()));
var store = new TableBotDataStore(ConfigurationManager.ConnectionStrings["StorageConnectionString"].ConnectionString);
builder.Register(c => store)
.Keyed<IBotDataStore<BotData>>(AzureModule.Key_DataStore)
.AsSelf()
.SingleInstance();
});
GlobalConfiguration.Configure(WebApiConfig.Register);
}
记录器类:
public class Logger:IActivityLogger
{
public static ConcurrentDictionary<string, List<IActivity>> Messages = new ConcurrentDictionary<string, List<IActivity>>();
public Task LogAsync(IActivity activity)
{
try
{
var list = new List<IActivity>() { activity };
Messages.AddOrUpdate(activity.Conversation.Id, list, (k, v) => { v.Add(activity); return v; });
return Task.FromResult(false);
}
catch (System.Exception)
{
throw;
}
}
}
这是我如何使用它(如何更新stateclient部分并在azure上使用我的存储?:
var reply = activity.CreateReply();
var storedActivities = new List<IActivity>();
var found = Logger.Messages.TryGetValue(activity.Conversation.Id, out storedActivities);
if (storedActivities != null)
{
foreach (var storedActivity in storedActivities)
{
reply.Text += $" <br /> <b>{storedActivity.From.Name}:</b> {storedActivity.AsMessageActivity().Text}";
}
// Get any saved values
StateClient sc = activity.GetStateClient();
BotData userData = sc.BotState.GetPrivateConversationData(
activity.ChannelId, activity.Conversation.Id, activity.From.Id);
var UserEmail = userData.GetProperty<string>("Email");
var Name = userData.GetProperty<string>("Name");
}
他们提供了一个新的tablelogger类。不幸的是我不知道如何消费它。 TableLogger.cs
答案 0 :(得分:0)
Microsoft.Azure.Cosmos.Table处于维护模式,将很快弃用。