【发布时间】:2019-08-29 00:21:12
【问题描述】:
我想开始主动对话。我尝试修改这个主动消息示例https://github.com/microsoft/BotBuilder-Samples/tree/master/samples/csharp_dotnetcore/16.proactive-messages
我已经更改了这个示例:
private async Task BotCallback(ITurnContext turnContext, CancellationToken)
{
_dialog.RunAsync(turnContext, _conversationState<DialogState>("DialogState"), cancellationToken);
try
{
await _conversationState.SaveChangesAsync(turnContext, true, cancellationToken);
}
catch(Exception ex)
{
_logger.LogError($"{nameof(_conversationState)}, {ex.Message}");
}
}
对话框开始了,但是当机器人从用户那里得到下一条消息时,它不能继续这个对话框并抛出以下异常:
Microsoft.Bot.Builder.Integration.AspNet.Core.BotFrameworkHttpAdapter:错误:>异常捕获:DialogContext.ContinueDialogAsync():无法继续>对话框。找不到 ID 为“LearnDialog”的对话框。”。
我使用 DI 通过构造函数注入对话框
构造函数:
public NotifiController(IBotFrameworkHttpAdapter adapter, IStorage storage, LearnDialog dialog, ConversationState conversationState)
{
_adapter = (BotFrameworkHttpAdapter)adapter ?? throw new ArgumentNullException(nameof(adapter));
_storage = storage ?? throw new ArgumentNullException(nameof(storage));
_dialog = dialog ?? throw new ArgumentNullException(nameof(dialog));
}
Startup.cs:
public void ConfigureServices(IServiceCollection services)
{ services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
// Create the Bot Framework Adapter with error handling enabled.
services.AddSingleton<IBotFrameworkHttpAdapter, AdapterWithErrorHandler>();
services.AddSingleton<IStorage, MemoryStorage>();
services.AddSingleton < UserState>();
services.AddSingleton<ConversationState>();
services.AddSingleton<MainDialog>();
services.AddSingleton<LearnDialog>();
services.AddTransient<IBot, DialogBot<MainDialog>();
}
【问题讨论】:
-
你能说明你是如何在那里添加
_dialog的吗?还有你的机器人的OnMessageActivityAsync发生了怎样的变化(如果发生了变化?)? -
我没有更改 OnMessageActivityAsync 保护覆盖异步任务 OnMessageActivityAsync(ITurnContext
turnContext, CancellationToken cancelToken) { await Dialog.RunAsync(turnContext, ConversationState.CreateProperty ("DialogState"), cancelToken) ; }
标签: c# botframework