Exemple #1
0
 private static async Task <DialogTurnResult> TransportStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
 {
     // WaterfallStep always finishes with the end of the Waterfall or with another dialog; here it is a Prompt Dialog.
     // Running a prompt here means the next WaterfallStep will be run when the users response is received.
     return(await stepContext.PromptAsync(nameof(ChoicePrompt),
                                          new PromptOptions
     {
         Prompt = _lgGenerator.GenerateActivity("ModeOfTransportPrompt", stepContext),
         Choices = ChoiceFactory.ToChoices(new List <string> {
             "Car", "Bus", "Bicycle"
         }),
     }, cancellationToken));
 }
        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}");
                    }
                }
            };
        }