2

When there is a multiprompt present, instead of adding buttons to go further I would like to add them directly into my card.

I have the qnaid's of the questions, can I get the answer just with the id?

stilllearning
  • 163
  • 10
  • I haven't tried this, but I would think you could write a function to iteratively check each answer for prompts, and make another qna maker call with the appropriate information, adding the additional answer to your card content. I'm guessing you want to do this instead of combining the text in one answer is because sometimes you might only want the second answer? – billoverton Apr 23 '20 at 14:36
  • Does this answer your question? [Display Text for QnAMaker follow-on prompts](https://stackoverflow.com/questions/58203069/display-text-for-qnamaker-follow-on-prompts) – Kyle Delaney Apr 23 '20 at 19:27
  • Are you using the Bot Builder SDK? (Since there are multiple people in this thread, you will need to @ mention me if you want me to see your reply.) – Kyle Delaney Apr 23 '20 at 19:27
  • @billoverton yes that is what I want to do. My question is do I need to update the stepcontext as if the user clicked on a prompt, or could I just get the answer by the qnaId (because when a question has prompts the qnaids of those prompts are also present). Can I make a call that says just give me the answer of the question with id 524 for example. – stilllearning Apr 24 '20 at 08:26
  • @KyleDelaney Yes I'm using the Bot Builder SDK. I don't want to change the display text. I want to query the knowledge base not with a question but by qnaId. Because if there are prompts they also contain the qnaId of their question. Can I make a call that just says give me the answer of the question with id 3516. Or is there an other way to easily get the answers of the prompts. – stilllearning Apr 24 '20 at 08:30

1 Answers1

1

I think the proper way to do this is to build the qnaState from the answer, grab the text from the prompt, and then make your new query with those parameters.

So first for reference, here is the QnA maker call I'm making.

        if (qnAcontext == null) {
            qnAcontext = {
                PreviousQnaId: 0,
                PreviousUserQuery: null
            }
        }

        const qnaResult = await request({
            url: url,
            method: 'POST',
            headers: headers,
            json: {
                question: query,
                top: 3,
                context: qnAcontext
            }
        });

I have this code in a helper function that I call from my qna dialog but I think the location isn't important. You can see I've set a "default" qnAcontext. This is what you will be updating to make your prompt-based call.

From the result, you can get the prompt buttons via

        var prompts = null;
        if(qnaResult[0].context != null){
            prompts = qnaResult[0].context.prompts;
        }

I've not done this before so I'm not exactly sure where you can get the text attribute from, but I'm assuming it's at qnaResults[0].context.prompts[0].text. You'll need to take a look at the prompts object to confirm. You also need to create the new state, and grab the first part of the answer. These things can be done via

            var qnAcontext = {
                PreviousQnaId: qnaResult[0].id,
                PreviousUserQuery: activity.text
            }

            answerText = qnaResult[0].answer;

Now just make another call using the new qnAContext and the prompt text as the query. Technically, if you don't have the follow up question set as context only, you don't have to mess with the qnAcontext. You should just be able to use the prompt text as the next query and the answer should come up. If the answer is context only, you'll need to pass the qnAcontext object, though.

Edit: For a direct answer to your question about querying with qnaId directly, see the link added below by Kyle Delaney.

billoverton
  • 2,705
  • 2
  • 9
  • 32
  • 2
    I think it is actually better to query the knowledge base with the QnA ID directly like the asker was saying. https://stackoverflow.com/questions/58203069/display-text-for-qnamaker-follow-on-prompts – Kyle Delaney Apr 27 '20 at 17:48