1

I have a direct line bot connected to QnaMaker and testing the new prompt feature on how to respond to the user, below sample Qna from QnaMaker

1) 
q) How to get New York Printer details(QnAID: 13)
a) details are below NY73889-B0

2)
q) How to get Dallas printer details (QnAID: 14)
a) details are below DL093883-B1

3)
q) printer location 
a) please chose from the 2 options below
   Dallas(QnAID: 13)  New York(QnAID: 14)    (Prompts)
4)
q)Dallas
a) Dallas is a beautiful city

5)
q)New York
a) City of lights

The issue: the user asks a question "printer location" and gets the response with a prompt New York and Dallas. Then when the user select one of the location say Dallas, ideally it should respond with the answer

2) q) How to get Dallas printer details (QnAID: 14) a) details are below DL093883-B1 since we have the prompt connected to the question 4 and we use the old state which has the selected option QnaID for dallas.. but instead it gives the answer below since it only matches with the dallas prompt text responded by user without considering the old State, any help is appreciated

4) q)Dallas a) Dallas is a beautiful city

protected override async Task<(object newState, IEnumerable<Activity> output, object result)> ProcessAsync(object oldState, Activity inputActivity)
{
    Activity outputActivity = null;
    QnABotState newState = null;
    var query = inputActivity.Text; ;


    //Step 4) We Build the json based on the value selected user so we make a call to the Qna Maker using the response from the user on the button click and the previous state
    //here we check if there was a prompt  from the previous question and update the state to send to the bot for response based on the option selected
    if (((QnAPrompting.Models.QnABotState)oldState) != null)
    {
        for (int i = 0; i < ((QnABotState)oldState).PreviousPromptValues.Length; i++)
        {
            if (((QnABotState)oldState).PreviousPromptValues[i].DisplayText == query)
            {
                ((QnABotState)oldState).qnaId = ((QnABotState)oldState).PreviousPromptValues[i].QnaId;
                ((QnABotState)oldState).question = query;
            }
        }
    } //Step5). when we get the response from the user after the choosing an option from the prompt, it queries the qnamaker and filters based on the old state as well
    //Step1). we get the prompts based on the question asked for the first time the old state is empty
    var qnaResult = await _qnaService.QueryQnAServiceAsync(query, (QnABotState)oldState);
    var qnaAnswer = qnaResult[0].Answer;
    var prompts = qnaResult[0].Context?.Prompts;

    if (prompts == null || prompts.Length < 1)
    {

        if (((QnAPrompting.Models.QnABotState)oldState) != null)
        {
            if (((QnAPrompting.Models.QnABotState)oldState).IsPreviousPrompt)
            {
                string method = "/knowledgebases/{0}/{1}/qna/";
                var method_with_id = String.Format(method, "KBID", "prod");
                var uri = "https://westus.api.cognitive.microsoft.com" + "/qnamaker/v4.0" + method_with_id;
                Console.WriteLine("Calling " + uri + ".");
                var response = await Get(uri);
            }
        }
        outputActivity = MessageFactory.Text(qnaAnswer);
    }
    else //Step 2.)prompt parameters are stored in the state
    {

        ContextValues ctx = new ContextValues();
        ctx.PreviousQnaId = qnaResult[0].Id;
        ctx.PreviousUserQuery = query;
        //store here in azure table
        newState = new QnABotState
        {
            question = string.Empty,
            top=10,
            userId = "Default",
            context = ctx,
            PreviousPromptValues = prompts,
        };

        outputActivity = CardHelper.GetHeroCard(qnaAnswer, prompts);
    }
    //Step 3) Prompt is displayed to the user
    return (newState, new Activity[] { outputActivity }, null);
}
SandeshR
  • 203
  • 2
  • 11
  • If you're basing your code off of a sample (like [this](https://github.com/microsoft/BotBuilder-Samples/tree/master/experimental/qnamaker-prompting/csharp_dotnetcore) perhaps) then that's a good thing to link to in your question because that will help us answer it – Kyle Delaney Oct 18 '19 at 20:21
  • 1
    In any case, we're going to need more information. You've clearly modified `QnABotState` so you must have modified `QueryQnAServiceAsync` in order to consume it but you've left out that code. The problem might also be that you're not actually saving the state correctly but you've left out that code as well. You might be interested in [this](https://stackoverflow.com/questions/58203069/display-text-for-qnamaker-follow-on-prompts/58209972#58209972) and [this](https://stackoverflow.com/questions/58120273/botmaker-resolve-qnamaker-followup-questions/58193169#58193169), though they use the Node SDK – Kyle Delaney Oct 18 '19 at 21:43
  • 1
    I have experienced the same issue with the QnA Prompts experimental sample. The prompt response is not respecting context and is just matching the prompt text with an answer (which in your case, you have a separate question answered by the prompt input). Haven't figured out a solution yet... – billoverton Oct 21 '19 at 17:39
  • @spStacker - Are you still working on this? (Because there are multiple people commenting, you have to tag us if you want us to see your responses.) – Kyle Delaney Oct 21 '19 at 20:37
  • @KyleDelaney it was QueryQnAServiceAsync thank you for the response.. its working now...sorry for the delayed response – SandeshR Oct 22 '19 at 01:55
  • @spStacker - Do you want to post that as an answer so you can accept it? – Kyle Delaney Oct 22 '19 at 18:05

1 Answers1

0

I redownloaded the code from the source here . with only modifications to the bot settings I ran the code and it worked as expected. As Kyle pointed out the issue was I modified the QueryQnAServiceAsync and that caused the issue. Now it's working as expected.

SandeshR
  • 203
  • 2
  • 11