private async Task <DialogTurnResult> ResultHandlerStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken) { var crmState = await _accessors.CRMStateAccessor.GetAsync(stepContext.Context, () => new CRMState(), cancellationToken); var luisState = await _accessors.LuisStateAccessor.GetAsync(stepContext.Context, () => new LuisState(), cancellationToken); //Handling when company not found if (crmState.Company == null || string.IsNullOrEmpty(crmState.Company.Name)) { var retry = stepContext.Result.ToString().ToLower().Equals(CulturedBot.Yes) ? true : false; if (retry) { //Restarting dialog if user decides to retry crmState.ResetCompany(); await _accessors.CRMStateAccessor.SetAsync(stepContext.Context, crmState, cancellationToken); return(await stepContext.ReplaceDialogAsync(_searchCompanyDataWaterfall, cancellationToken, cancellationToken)); } else { //Ending Dialog if user decides not to retry var message = CulturedBot.AskForRequest; var activity = MessageFactory.Text(message, message, InputHints.AcceptingInput); activity.Locale = CulturedBot.Culture?.Name; await stepContext.Context.SendActivityAsync(activity, cancellationToken); crmState.ResetCompany(); luisState.ResetAll(); await _accessors.CRMStateAccessor.SetAsync(stepContext.Context, crmState, cancellationToken); await _accessors.LuisStateAccessor.SetAsync(stepContext.Context, luisState, cancellationToken); return(await stepContext.EndDialogAsync(cancellationToken : cancellationToken)); } } var wantOppornunities = luisState.Entities.Contains(ProxiCallEntities.SEARCH_OPPORTUNITIES_NAME_ENTITYNAME); var wantNumberOppornunities = luisState.Entities.Contains(ProxiCallEntities.SEARCH_NUMBER_OPPORTUNITIES_ENTITYNAME); //Searching for lead contact //Redirect to SearchLeadDataDialog if (luisState.Entities.Contains(ProxiCallEntities.SEARCH_CONTACT_ENTITYNAME)) { AddDialog(ActivatorUtilities.CreateInstance <SearchLeadDataDialog>(_serviceProvider)); crmState.Lead = crmState.Company.Contact; if (crmState.Lead != null && crmState.Lead.Company == null) { crmState.Lead = Lead.CloneWithCompany(crmState.Lead, crmState.Company); } else if (crmState.Lead == null) { var activityPrompt = MessageFactory.Text(CulturedBot.NoPointOfContactFound); activityPrompt.Locale = CulturedBot.Culture?.Name; var promptOptions = new PromptOptions { Prompt = activityPrompt }; await stepContext.PromptAsync(_retryFetchingMinimumDataFromUserPrompt, promptOptions, cancellationToken); return(await stepContext.EndDialogAsync()); } await _accessors.CRMStateAccessor.SetAsync(stepContext.Context, crmState, cancellationToken); return(await stepContext.ReplaceDialogAsync(nameof(SearchLeadDataDialog), cancellationToken : cancellationToken)); } else if (wantOppornunities || wantNumberOppornunities) { //Searching for Opportunities //Creating adapted response var textMessage = await FormatMessageWithOpportunities(stepContext); //Sending response var activity = MessageFactory.Text(textMessage, textMessage, InputHints.IgnoringInput); activity.Locale = CulturedBot.Culture?.Name; await stepContext.Context.SendActivityAsync(activity, cancellationToken); } return(await stepContext.NextAsync(cancellationToken : cancellationToken)); }