0

I am trying to implement a bot which uses Qna services and Azure search.

I am taking help of the C# QnA Maker sample github code.

It is using a BotServices.cs class which is taking a QnA service in its constructor. This Botservice object is being passed to the QnABot class constructor.

I want to use Dialog set in QnABot's constructor which need accessors to be added. I really didn't understand how to add accessor class and use them in the startup.cs

I tried to copy some code from other samples but didn't work.

Please help me to add an accessor to the BotServices constructor so that I can use dialog sets inside of it.

I would like to extend the QnA sample for my purpose.

Vivek Jain
  • 71
  • 1
  • 11

1 Answers1

1

Can you tell us why you want to pass a dialog set tot the botservices class? this class is only used to reference external services such as QnAMaker and LUIS. If you want to start a Dialog, do so in the OnTurnAsync method of the QnABot.cs class. keep in mind that the this method as it is created in this specific sample will send a response on every message the user sends even if they are working through a dialog. You could change the OnTurnAsync in such a way that the first step in the dialog is to check the QnAMaker. See the enterpriseBot sample to see how to start a dialog as well as adding an accessor to a child Dialog. see the following snipped from the MainDialog.cs class how they added the accessor:

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));
  }
}
MarkMoose
  • 91
  • 6
  • I follow [this](https://learn.microsoft.com/en-us/azure/bot-service/bot-builder-dialog-manage-conversation-flow?view=azure-bot-service-4.0&tabs=csharp) tutorial to add the dialog and they say that "Create the dialog set within the bot's constructor, adding the prompts and the waterfall dialog to the set." so I am not able to follow it and add one more parameter in the QnAbot' constructor – Vivek Jain Nov 19 '18 at 09:01
  • I am not trying to modify the botservice class constructor but the QnABot's constructor where I want to add dialogs to the dialogset. – Vivek Jain Nov 19 '18 at 09:07
  • 1
    ahh okey, I think I understand what you are trying to do. you want to add a botAccessor to the QnABot constructer like so: public QnABot(BotServices services, QnABotAccessor accessor){} In order to do this, also add the accessor to the bot by updating the ConfigureServices method in the StartUp.cs as mentioned in the tutorial. like so: services.AddSingleton(sp =>{// YOUR CODE HERE}); tehn you can just follow the tutorial – MarkMoose Nov 19 '18 at 09:58
  • okey. Thanks. I will try to follow. in case, I face some issues, will post it here again – Vivek Jain Nov 19 '18 at 12:12