10

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

CSDev
  • 3,177
  • 6
  • 19
  • 37
anonymous1110
  • 885
  • 4
  • 14
  • 28
  • 3
    This question is mixing StateClient and Logging. Should be closed as the OP created a new question more detailed and exact: https://stackoverflow.com/questions/48374471/how-to-retrieve-saved-conversation-data-in-azure-tablelogger – Nicolas R Jan 22 '18 at 12:22
  • activity.GetStateClient() will not retrieve your TableBotDataStore custom state client, but is using the default state client. See here https://stackoverflow.com/questions/46085614/how-can-i-access-bot-framework-conversationdata-outside-of-a-dialog for how to create an instance of IBotDataStore that will use your registered TableBotDataStore – Eric Dahlvang Jan 24 '18 at 06:08
  • 1
    Possible duplicate of [How to retrieve Saved Conversation Data in Azure (Tablelogger)](https://stackoverflow.com/questions/48374471/how-to-retrieve-saved-conversation-data-in-azure-tablelogger) – esqew Apr 22 '19 at 19:30

1 Answers1

0

Microsoft.Azure.Cosmos.Table as it is in maintenance mode and will be deprecated soon.

Eng Soon Cheah
  • 257
  • 1
  • 10
  • 42