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);
}