How to implement cards in a QnA question which has follow up prompts and uses them in the cards

折月煮酒 提交于 2019-12-01 11:29:42

问题


I've set up a simple QnA bot which is linked to a QnA service. Within the QnA service I have set up some questions which have follow up prompts(Dependents) e.g. how do I get to a campus, via bus, train etc. see image in link, within the Qna maker testing function you can just click a button called enable mutli-turn which provides functional buttons to inform you of what can/should be asked next via the dependents of the answer See image in link.

However when used within a channel/in the emulator nothing of the like appears see image, which is a bit odd. And obviously I want to implement such functionality in to the bot as it makes life so much easier for the users.

I am new to the whole bot thing(I started last month), so I have a browsed the internet to see what I could find but I could not see anything out side of writing the questions within the bot it self, see Microsofts documentation, which makes using QnA maker pretty much pointless.

What I think I need to do is intercept the message from QnA maker as it replies to the user, look at the Json received to find if has any dependents then run a different dialog, which gets the contextual dependents names and runs a simple for loop generating cards for each dependents, then send the message to the user with the generated cards, however I'm not sure how to intercept the Json and look for any dependents, or there is a button the I need to click within azure which just does it.


回答1:


There is this experimental sample that has been released by the Bot Framework team which demonstrates how to handle follow-up prompts.

You can download it (you will have to download the whole repo) then plug in your details to the appsettings.json file and you should be able to test it using the Bot Framework Emulator - these were the only steps that I had to perform.

The key part is this method which checks to see if the result contains any prompts and returns the response accordingly - it is called inside the FuctionDialog.

If you're only ever going to be implementing a single level of prompts i.e. you have a question which shows prompts and when you click on one of these prompts it will display an answer rather than taking you to another prompt, then it is possible to take the guts of the logic from the ProcessAsync method (checking for prompts) along with the required classes from the Models folder and the CardHelper class and get this to work in your existing application - you won't have to worry about the QnABotState because you'll only be going a single level deep so you don't need to track where you are in the series of prompts. e.g.

var query = inputActivity.Text;           
var qnaResult = await _qnaService.QueryQnAServiceAsync(query, new QnABotState());
var qnaAnswer = qnaResult[0].Answer;
var prompts = qnaResult[0].Context?.Prompts;

if (prompts == null || prompts.Length < 1)
{
    outputActivity = MessageFactory.Text(qnaAnswer);
}
else
{
    outputActivity = CardHelper.GetHeroCard(qnaAnswer, prompts);
}

await turnContext.SendActivityAsync(outputActivity);



回答2:


Could someone please advice where do we add this code mentioned above? I am a rookie, have very basic knowledge about programming. Using visual studio with C# for this. How and where do I add this code to make it work? I am also not diving too deep. Just trying to make some simple logic where a user clicks on a few follow up prompts and is taken to the required information. Would really appreciate if someone could help. Thanks

First picture shows the starting follow up prompt.

Second picture that follows the first followup prompt



来源:https://stackoverflow.com/questions/56185169/how-to-implement-cards-in-a-qna-question-which-has-follow-up-prompts-and-uses-th

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!