public AdapterWithErrorHandler(ICredentialProvider credentialProvider, ILogger <BotFrameworkHttpAdapter> logger, ConversationState conversationState = null)
            : base(credentialProvider)
        {
            Dictionary <string, string> lgFilesPerLocale = new Dictionary <string, string>()
            {
                { "", Path.Combine(".", "Resources", "AdapterWithErrorHandler.lg") },
                { "fr", Path.Combine(".", "Resources", "AdapterWithErrorHandler.fr-fr.lg") }
            };

            _lgManager  = new MultiLingualTemplateEngine(lgFilesPerLocale);
            OnTurnError = async(turnContext, exception) =>
            {
                // Log any leaked exception from the application.
                logger.LogError($"Exception caught : {exception.Message}");

                // Send a catch-all apology to the user.
                await turnContext.SendActivityAsync(_lgManager.GenerateActivity("SomethingWentWrong", exception, turnContext));

                if (conversationState != null)
                {
                    try
                    {
                        // Delete the conversationState for the current conversation to prevent the
                        // bot from getting stuck in a error-loop caused by being in a bad state.
                        // ConversationState should be thought of as similar to "cookie-state" in a Web pages.
                        await conversationState.DeleteAsync(turnContext);
                    }
                    catch (Exception e)
                    {
                        logger.LogError($"Exception caught on attempting to Delete ConversationState : {e.Message}");
                    }
                }
            };
        }
Exemple #2
0
        public UserProfileDialog(UserState userState)
            : base(nameof(UserProfileDialog))
        {
            _userProfileAccessor = userState.CreateProperty <UserProfile>("UserProfile");
            // combine path for cross platform support
            Dictionary <string, string> lgFilesPerLocale = new Dictionary <string, string>()
            {
                { "", Path.Combine(".", "Resources", "UserProfileDialog.lg") },
                { "fr", Path.Combine(".", "Resources", "UserProfileDialog.fr-fr.lg") }
            };

            _lgGenerator = new MultiLingualTemplateEngine(lgFilesPerLocale);

            // This array defines how the Waterfall will execute.
            var waterfallSteps = new WaterfallStep[]
            {
                TransportStepAsync,
                NameStepAsync,
                NameConfirmStepAsync,
                AgeStepAsync,
                ConfirmStepAsync,
                SummaryStepAsync,
            };

            // Add named dialogs to the DialogSet. These names are saved in the dialog state.
            AddDialog(new WaterfallDialog(nameof(WaterfallDialog), waterfallSteps));
            AddDialog(new TextPrompt(nameof(TextPrompt)));
            AddDialog(new NumberPrompt <int>(nameof(NumberPrompt <int>), AgePromptValidatorAsync));
            AddDialog(new ChoicePrompt(nameof(ChoicePrompt)));
            AddDialog(new ConfirmPrompt(nameof(ConfirmPrompt)));

            // The initial child Dialog to run.
            InitialDialogId = nameof(WaterfallDialog);
        }