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