private bool checkForEntities(luisResultContainer._Entities entities) { if (entities.contactJobTitle is null && entities.contactName is null && entities.organizationName is null && entities.projectUsages is null && entities.projectLocation is null && entities.projectCriteria is null && entities.projectDescription is null && entities.organizationOverview is null) { return(false); } return(true); }
//Responsible for resolving user language via LUIS private async Task <DialogTurnResult> intentAnswer(WaterfallStepContext stepContext, CancellationToken cancellationToken) { var luisResult = await _luisRecogniser.RecognizeAsync <luisResultContainer>(stepContext.Context, cancellationToken); luisResultContainer._Entities entities = luisResult.Entities; switch (luisResult.TopIntent().intent) { case luisResultContainer.Intent.listProjects: if (!checkForEntities(entities)) { sendMessage(stepContext, "I'm sorry, please specify a criteria for me to search for, such as" + " keywords or names.", cancellationToken); break; } searchIndex = 0; sendMessage(stepContext, "Please bare with me, I am searching for projects that match your criteria", cancellationToken); projectBundle searchResult = new projectBundle(entities); if (searchResult.getNumberOfProjects() == 0) { sendMessage(stepContext, "I'm sorry, I couldn't find any projects matching your parameters. Please try again with different keywords.", cancellationToken); break; } await displayProjects(searchResult, stepContext, cancellationToken); break; case luisResultContainer.Intent.displayMoreProjects: searchIndex += 4; if (projectResults == null) { sendMessage(stepContext, "There is no projects to show! Please search for projects first.", cancellationToken); break; } if (searchIndex >= projectResults.getNumberOfProjects()) { sendMessage(stepContext, "There are no more projects to show from this search! Here are the last 4 projects.", cancellationToken); searchIndex -= 4; } else { sendMessage(stepContext, "Here are some more results for your last search.", cancellationToken); } for (int i = 0; i < projectResults.getNumberOfProjects() - searchIndex; i++) { Project currentRecord = projectResults.getProject(i + searchIndex); var response = MessageFactory.Attachment(currentRecord.getSimplePatientCard()); await stepContext.Context.SendActivityAsync(response, cancellationToken); } break; case luisResultContainer.Intent.cancelDialog: break; default: var promptMessage = "I'm sorry, I am having trouble understanding you. What would you like me to do?"; return(await stepContext.ReplaceDialogAsync(InitialDialogId, promptMessage, cancellationToken)); } return(await stepContext.ReplaceDialogAsync(InitialDialogId, "Could I help you with anything else?", cancellationToken)); }
//Responsible for resolving user language via LUIS private async Task <DialogTurnResult> intentAnswer(WaterfallStepContext stepContext, CancellationToken cancellationToken) { var luisResult = await _luisRecogniser.RecognizeAsync <luisResultContainer>(stepContext.Context, cancellationToken); luisResultContainer._Entities entities = luisResult.Entities; switch (luisResult.TopIntent().intent) { case luisResultContainer.Intent.listProjects: if (!checkForEntities(entities)) { sendMessage(stepContext, "I'm sorry, please specify a criteria for me to search for. " + "Type in 'help' for instructions and commands on how to search for projects.", cancellationToken); break; } searchIndex = 0; sendMessage(stepContext, "Please bear with me, I am searching for projects that match your criteria", cancellationToken); projectBundle searchResult = new projectBundle(entities); if (searchResult.getNumberOfProjects() == 0) { sendMessage(stepContext, "I'm sorry, I couldn't find any projects matching your parameters. Please try again with different keywords.", cancellationToken); break; } await displayProjects(searchResult, stepContext, cancellationToken); break; case luisResultContainer.Intent.displayMoreProjects: searchIndex += 4; if (projectResults == null) { sendMessage(stepContext, "There is no projects to show! Please search for projects first.", cancellationToken); break; } if (searchIndex >= projectResults.getNumberOfProjects()) { searchIndex -= 4; sendMessage(stepContext, "There are no more projects to show from this search! Here are the last " + (projectResults.getNumberOfProjects() - searchIndex) + " projects.", cancellationToken); } else { sendMessage(stepContext, "Here are some more results for your last search.", cancellationToken); } int numberOfSearchResults = projectResults.getNumberOfProjects() - searchIndex < SEARCH_RESULT_LIMIT ? projectResults.getNumberOfProjects() - searchIndex : SEARCH_RESULT_LIMIT; for (int i = 0; i < numberOfSearchResults; i++) { Project currentRecord = projectResults.getProject(i + searchIndex); var response = MessageFactory.Attachment(currentRecord.getSimplePatientCard()); await stepContext.Context.SendActivityAsync(response, cancellationToken); } break; case luisResultContainer.Intent.help: string json = File.ReadAllText("Cards/helpCard.json"); dynamic jsonObj = JsonConvert.DeserializeObject(json); Attachment card = new Attachment() { ContentType = "application/vnd.microsoft.card.adaptive", Content = jsonObj }; await stepContext.Context.SendActivityAsync(MessageFactory.Attachment(card), cancellationToken); return(await stepContext.ReplaceDialogAsync(InitialDialogId, "Here is the help page. What can I help you with?", cancellationToken)); default: var promptMessage = "I'm sorry, I am having trouble understanding you. What would you like me to do?" + " If you are stuck, type in 'help' for instructions and commands."; return(await stepContext.ReplaceDialogAsync(InitialDialogId, promptMessage, cancellationToken)); } return(await stepContext.ReplaceDialogAsync(InitialDialogId, "Could I help you with anything else?", cancellationToken)); }