how to get chat history from azure table storage

允我心安 提交于 2019-12-05 19:55:16

问题


Since we are forced to drop the stateclient and move to a custom storage, in my case an azure table storage. Using my storageexplorer I can see that it already saved conversation data on my azure. How can I update my ff code to get past chat history? Before I'm using a IActivityLogger class to log a conversation, but now I'm confused on how to update it.

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);
}

Logger Class:

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;
        }

    }
}

This is how i use it (how can i update the stateclient part and use my storage on 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");
}

They gave a new tablelogger class. Unfortunately I don't know how to consume it. TableLogger.cs

来源:https://stackoverflow.com/questions/48313703/how-to-get-chat-history-from-azure-table-storage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!