public MainMenuHelperDialog(IStatePropertyAccessor <SelectedLanguageState> selectedLanguagePropertyAccessor, IStatePropertyAccessor <CustomWrapperPromptState> customWrapperPromptStateAccessor) : base(MainMenuHelperDialogId) { this._selectedLanguageStatePropertyAccessor = selectedLanguagePropertyAccessor; this._customWrapperPromptStatePropertyAccessor = customWrapperPromptStateAccessor; this.InitialDialogId = MainMenuHelperDialogId; List <string> _mainMenuChoices = new List <string>() { "FAQ QnAMaker", "Azure Search", "Azure Search Facets", "Adaptive Card", "Choose Language" }; ChoicePrompt cp = new ChoicePrompt("choicePrompt"); cp.Style = ListStyle.SuggestedAction; this.AddDialog(cp); this.AddDialog(new QnAMakerDialog("QnADialog")); this.AddDialog(new AzureSearchDialog("AzureSearchDialog", selectedLanguagePropertyAccessor)); this.AddDialog(new AzureSearchFacetsDialog("AzureSearchFacetsDialog")); this.AddDialog(new AdaptiveCardDialog("AdaptiveCardDialog", customWrapperPromptStateAccessor)); this.AddDialog(new ChooseLanguageDialog("ChooseLanguageDialog", selectedLanguagePropertyAccessor)); // Define the conversation flow using the waterfall model. this.AddDialog( new WaterfallDialog(this.InitialDialogId, new WaterfallStep[] { async(stepContext, ct) => { SelectedLanguageState selectedLanguage = await _selectedLanguageStatePropertyAccessor.GetAsync( stepContext.Context, () => new SelectedLanguageState() { SelectedLanguage = "en-us" }, ct); var cultureInfo = LanguageService.LanguageChoiceMap.ContainsKey(selectedLanguage.SelectedLanguage) ? new CultureInfo(LanguageService.LanguageChoiceMap[selectedLanguage.SelectedLanguage]) : new CultureInfo("en-us"); CultureInfo.CurrentUICulture = CultureInfo.CurrentCulture = cultureInfo; return(await stepContext.PromptAsync( "choicePrompt", new PromptOptions { Choices = ChoiceFactory.ToChoices(new List <string> { MainMenuHelperDialogStrings.Option1, MainMenuHelperDialogStrings.Option2, MainMenuHelperDialogStrings.Option3, MainMenuHelperDialogStrings.Option4, MainMenuHelperDialogStrings.Option5 }), Prompt = MessageFactory.Text(MainMenuHelperDialogStrings.Prompt), RetryPrompt = MessageFactory.Text(MainMenuHelperDialogStrings.RetryPrompt) }, ct ).ConfigureAwait(false)); }, async(stepContext, ct) => { var menuChoice = ((FoundChoice)stepContext.Result).Value; SelectedLanguageState selectedLanguage = await _selectedLanguageStatePropertyAccessor.GetAsync( stepContext.Context, () => new SelectedLanguageState() { SelectedLanguage = "en-us" }, ct); var cultureInfo = LanguageService.LanguageChoiceMap.ContainsKey(selectedLanguage.SelectedLanguage) ? new CultureInfo(LanguageService.LanguageChoiceMap[selectedLanguage.SelectedLanguage]) : new CultureInfo("en-us"); CultureInfo.CurrentUICulture = CultureInfo.CurrentCulture = cultureInfo; if (menuChoice == MainMenuHelperDialogStrings.Option1) { return(await stepContext.BeginDialogAsync("QnADialog")); } else if (menuChoice == MainMenuHelperDialogStrings.Option2) { return(await stepContext.BeginDialogAsync("AzureSearchDialog")); } else if (menuChoice == MainMenuHelperDialogStrings.Option3) { return(await stepContext.BeginDialogAsync("AzureSearchFacetsDialog")); } else if (menuChoice == MainMenuHelperDialogStrings.Option4) { return(await stepContext.BeginDialogAsync("AdaptiveCardDialog")); } else if (menuChoice == MainMenuHelperDialogStrings.Option5) { return(await stepContext.BeginDialogAsync("ChooseLanguageDialog")); } else { } return(await stepContext.NextAsync().ConfigureAwait(false)); }, async(stepContext, ct) => { return(await stepContext.ReplaceDialogAsync(MainMenuHelperDialogId).ConfigureAwait(false)); } } ) ); }
public ChooseLanguageDialog(string dialogId, IStatePropertyAccessor <SelectedLanguageState> selectedLanguageStatePropertyAccessor) : base(dialogId) { _selectedLanguageStatePropertyAccessor = selectedLanguageStatePropertyAccessor ?? throw new ArgumentNullException(nameof(selectedLanguageStatePropertyAccessor)); // ID of the child dialog that should be started anytime the component is started. this.InitialDialogId = dialogId; this.AddDialog(new ChoicePrompt("chooseLanguagePrompt")); // Define the conversation flow using the waterfall model. this.AddDialog( new WaterfallDialog(dialogId, new WaterfallStep[] { async(stepContext, ct) => { SelectedLanguageState selectedLanguage = await _selectedLanguageStatePropertyAccessor.GetAsync( stepContext.Context, () => new SelectedLanguageState() { SelectedLanguage = "en-us" }, ct); List <string> _langageChoices = new List <string> { ChooseLanguageDialogStrings.Option1, ChooseLanguageDialogStrings.Option2 }; return(await stepContext.PromptAsync( "chooseLanguagePrompt", new PromptOptions { Choices = ChoiceFactory.ToChoices(_langageChoices), Prompt = MessageFactory.Text(ChooseLanguageDialogStrings.Prompt), RetryPrompt = MessageFactory.Text(ChooseLanguageDialogStrings.RetryPrompt) }, ct ).ConfigureAwait(false)); }, async(stepContext, ct) => { var userAnswer = ((FoundChoice)stepContext.Result).Value; var cultureInfo = LanguageService.LanguageChoiceMap.ContainsKey(userAnswer) ? new CultureInfo(LanguageService.LanguageChoiceMap[userAnswer]) : new CultureInfo("en-us"); CultureInfo.CurrentUICulture = CultureInfo.CurrentCulture = cultureInfo; stepContext.Context.Activity.Locale = cultureInfo.Name; await _selectedLanguageStatePropertyAccessor.SetAsync( stepContext.Context, new SelectedLanguageState { SelectedLanguage = userAnswer, }, ct); await stepContext.Context.SendActivityAsync(ChooseLanguageDialogStrings.Step2); return(await stepContext.NextAsync().ConfigureAwait(false)); } } ) ); }