Hi I am working on Microsoft Bot Framework and in that I am working QnAMaker with including LUIS application.
Here my question is when I am working QnAMaker its providing the Exact answer and when I am adding the LUIS service I am getting the Exact answer in debugging and when I am providing the reply to the user by using await context.PostAsync(answer);
its by default going to the exception section and its showing exception is like below.
Object reference is not set be instance of object.
Here I can't understand where is the null is occurred because of I am getting the data from QnAMaker.
In the below I am sharing the code what I have write for getting the response to user form QnAMaker after the LUIS identify the Intents and Entities
private async Task toGetTheResponsefromQnAMakerAsync(IDialogContext context, Activity activity)
{
var messagetext = (activity.Text).ToLower();
var knowledgebaseId = ConfigurationManager.AppSettings["KnowledgeBaseId"];
//Use subscription key assigned to you.
var qnamakerSubscriptionKey = ConfigurationManager.AppSettings["QnAmakerSubscriptionKey"];
var client = new HttpClient();
var queryString = HttpUtility.ParseQueryString(string.Empty);
// Request headers
client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", qnamakerSubscriptionKey);
var uri = "https://westus.api.cognitive.microsoft.com/qnamaker/v2.0/knowledgebases/subscription-id/generateAnswer?" + queryString;
HttpResponseMessage response;
// Request body
byte[] byteData = Encoding.UTF8.GetBytes($"{{\"question\": \"{messagetext}\"}}");
using (var content = new ByteArrayContent(byteData))
{
content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
response = await client.PostAsync(uri, content);
}
try
{
if (response.IsSuccessStatusCode)
{
var responseContent = response.Content.ReadAsStringAsync().Result;
var QnAMakerResponse = JsonConvert.DeserializeObject<RootObject>(responseContent);
if (QnAMakerResponse.answers != null)
{
foreach (var item in QnAMakerResponse.answers)
// return our QnAMakerResponse to the user
answer = item.answer.ToString();
await context.PostAsync(answer);
}
}
}
catch (Exception e)
{
}
}