0

I use some waterfall steps before I want to use QnA for getting an answer.

 WaterfallStep[] steps = new WaterfallStep[]
    {
        MenuStepAsync,
        QnAAsync,
     };

Then when I want to call the QnA service, It needs a Turncontext object but in the waterfallstep dialog, I dont have access of the TurnContext.

  private static async Task<DialogTurnResult> QnAAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
           var response = _services.QnAServices[QnAMakerKey].GetAnswersAsync(turnContext);
            return await stepContext.PromptAsync("name", new PromptOptions { Prompt = MessageFactory.Text("Please enter your name.") }, cancellationToken);
        }
    await

I am using C#. I did this in nodejs, but C# is a bit tricky. The following gives an error that stepContext cannot be converted to the Iturncontext. I understand this but not sure how can make it available to "GetAnswersAsync":

_services.QnAServices[QnAMakerKey].GetAnswersAsync(turnContext);

Thanks in the advace for your help.

Vivek Jain
  • 71
  • 1
  • 11

2 Answers2

0

stepContext.Context is nothing but the Turn context. It has solved my problem.

Vivek Jain
  • 71
  • 1
  • 11
0

Adding a sample code here for everybody.

    private async Task<DialogTurnResult> InitialStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
    {
        var results = await _botServices.QnAMaker.GetAnswersAsync(stepContext.Context);
        if (results.Any())
        {
            await stepContext.Context.SendActivityAsync(MessageFactory.Text(results.First().Answer), cancellationToken);
        }
        else
        {
            await stepContext.Context.SendActivityAsync(MessageFactory.Text("Sorry, could not find an answer in the Q and A system."), cancellationToken);
        }
        return await stepContext.NextAsync(null, cancellationToken);
    }
Crismogram
  • 906
  • 15
  • 27