I am working with bot framework v4. Is there any way to get ITurncontext in startup.cs to set up the transcriptlogger middleware for saving the bot state.
Below given the sample solution i have tried
IStorage userDataStore = new
Microsoft.Bot.Builder.Azure.AzureBlobStorage
(Configuration["AzureTableStorageConnectionString"],
Configuration["AzureBlobStorageContainerName"]);
var userstate = new UserState(userDataStore);
var myPropertyAccessor = userstate.CreateProperty<UserProfile>(nameof(UserProfile));
services.AddSingleton<IStatePropertyAccessor<UserProfile>>(myPropertyAccessor);
var logger = new TranscriptLogger(Configuration);
services.AddTransient<ITranscriptLogger, TranscriptLogger>();
services.AddBot<DialogAndWelcomeBot<Dialog>>(options =>
{
options.CredentialProvider = new ConfigurationCredentialProvider(Configuration);
options.Middleware.Add(new TranscriptLoggerMiddleware(logger));
});
Implementation of TranscriptLogger :-
public class TranscriptLogger : ITranscriptLogger
{
public IConfiguration _configuration;
public TranscriptLogger(IConfiguration configuration)
{
_configuration = configuration;
}
public async Task LogActivityAsync(IActivity activity)
{
var isMessage = activity.AsMessageActivity() != null ? true : false;
if (isMessage && !string.IsNullOrEmpty(activity.AsMessageActivity().Text))
{
// saving conversation data
}
}
}
I really appreciate any help :)