如何使用SDK4.0在机器人中添加对话框

How to add a Dialog in a bot using SDK4.0

我正在尝试实现一个使用 Qna 服务和 Azure 搜索的机器人。

我正在寻求 C# QnA Maker sample github 代码的帮助。

它正在使用 BotServices.cs class,它在其构造函数中采用 QnA 服务。此 Botservice 对象正在传递给 QnABot class 构造函数。

我想使用 QnABot 的构造函数中设置的对话框,需要添加访问器。我真的不明白如何添加访问器 class 并在 startup.cs

中使用它们

我试图从其他示例中复制一些代码,但没有成功。

请帮助我向 BotServices 构造函数添加访问器,以便我可以在其中使用对话框集。

出于我的目的,我想扩展 QnA 示例。

您能告诉我们为什么要将对话设置为机器人服务 class 吗?此 class 仅用于引用外部服务,例如 QnAMaker 和 LUIS。如果要启动对话框,请在 QnABot.cs class 的 OnTurnAsync 方法中执行此操作。请记住,在此特定示例中创建的 this 方法将对用户发送的每条消息发送响应,即使他们正在通过对话框工作也是如此。您可以更改 OnTurnAsync,使对话框中的第一步是检查 QnAMaker。请参阅 enterpriseBot 示例以了解如何启动对话以及如何向子对话添加访问器。请参阅从 MainDialog.cs class 他们如何添加访问器中截取的以下内容:

protected override async Task OnStartAsync(DialogContext innerDc, CancellationToken cancellationToken = default(CancellationToken))
{
  var onboardingAccessor = _userState.CreateProperty<OnboardingState>(nameof(OnboardingState));
  var onboardingState = await onboardingAccessor.GetAsync(innerDc.Context, () => new OnboardingState());

  var view = new MainResponses();
  await view.ReplyWith(innerDc.Context, MainResponses.Intro);

  if (string.IsNullOrEmpty(onboardingState.Name))
  {
    // This is the first time the user is interacting with the bot, so gather onboarding information.
      await innerDc.BeginDialogAsync(nameof(OnboardingDialog));
  }
}