I'm following the Azure EchoBot Tutorial for adding states and I was running into an issue running the bot in the Bot Framework Emulator. (The bot can connect. The EchoBot without any modifications will run fine) This is what I added to the ConfigureServices Function in my Startup.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
// Create the Bot Framework Adapter.
services.AddSingleton<IBotFrameworkHttpAdapter, AdapterWithErrorHandler>();
//// Create the User state
services.AddSingleton<UserState>();
//// Create the Conversation State
services.AddSingleton<ConversationState>();
// Create the bot as a transient. In this case the ASP Controller is expecting an IBot.
services.AddTransient<IBot, EchoBot>();
}
This is what I added to EchoBot.cs
private readonly BotState _userState;
private readonly BotState _conversationState;
public EchoBot (ConversationState conversationState, UserState userState)
{
_conversationState = conversationState;
_userState = userState;
}
protected override async Task OnMessageActivityAsync(ITurnContext<IMessageActivity> turnContext, CancellationToken cancellationToken)
{
var conversationStateAccessors = _conversationState.CreateProperty<ConversationFlow>(nameof(ConversationFlow));
var flow = await conversationStateAccessors.GetAsync(turnContext, () => new ConversationFlow());
var userStateAccessors = _userState.CreateProperty<UserProfile>("User");
var profile = await userStateAccessors.GetAsync(turnContext, () => new UserProfile());
await _conversationState.SaveChangesAsync(turnContext);
await _userState.SaveChangesAsync(turnContext);
await turnContext.SendActivityAsync(MessageFactory.Text($"Echo: {turnContext.Activity.Text}"), cancellationToken);
}
The error I'm getting in the emulator is just POST 500 directline.conversationUpdate and this is a screenshot of the error I'm getting from the bot console:
Thanks! If there's any clarification needed, I'll do my best to update it.