public CancelTrip(ILoggerRepository <SqlLoggerRepository> sqlLoggerRepository, StateBotAccessors accessors, IConfiguration config)
     : base(nameof(CancelTrip))
 {
     _accessors           = accessors;
     _config              = config;
     _sqlLoggerRepository = sqlLoggerRepository;
 }
Example #2
0
 public NoneHandle(ILoggerRepository <SqlLoggerRepository> sqlLoggerRepository, StateBotAccessors accessors, IConfiguration config)
     : base(nameof(NoneHandle))
 {
     _accessors           = accessors;
     _config              = config;
     _sqlLoggerRepository = sqlLoggerRepository;
 }
Example #3
0
 public ViewOTP(ILoggerRepository <SqlLoggerRepository> sqlLoggerRepository, StateBotAccessors accessors, IConfiguration config)
     : base(nameof(ViewOTP))
 {
     _accessors           = accessors;
     _config              = config;
     _sqlLoggerRepository = sqlLoggerRepository;
 }
 public QnAHandlerDialog(ILoggerRepository <SqlLoggerRepository> sqlLoggerRepository, StateBotAccessors accessors, IConfiguration configuration)
     : base(nameof(QnAHandlerDialog))
 {
     _sqlLoggerRepository = sqlLoggerRepository;
     _accessors           = accessors;
     _configuration       = configuration ?? throw new ArgumentNullException(nameof(configuration));
 }
 public LuisHandlerDialog(ILoggerRepository <SqlLoggerRepository> sqlLoggerRepository, StateBotAccessors accessors, IConfiguration config)
     : base(nameof(LuisHandlerDialog))
 {
     _accessors           = accessors;
     _config              = config;
     _sqlLoggerRepository = sqlLoggerRepository;
     AddDialog(new GetAdhocRequestDetails(_sqlLoggerRepository, _accessors, _config));
     AddDialog(new ViewRoute(_sqlLoggerRepository, _accessors, _config));
     AddDialog(new ViewOTP(_sqlLoggerRepository, _accessors, _config));
     AddDialog(new ViewSchedule(_sqlLoggerRepository, _accessors, _config));
     AddDialog(new CancelTrip(_sqlLoggerRepository, _accessors, _config));
     AddDialog(new AdhocStatus(_sqlLoggerRepository, _accessors, _config));
     AddDialog(new NoneHandle(_sqlLoggerRepository, _accessors, _config));
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="ViewContactDialogue"/> class.
        /// </summary>
        /// <param name="botServices">Connected services used in processing.</param>
        /// <param name="statePropertyAccessor">The <see cref="StateBotAccessors"/> for storing properties at user-scope.</param>
        /// <param name="loggerFactory">The <see cref="ILoggerFactory"/> that enables logging and tracing.</param>
        public ViewContactsDialogue(StateBotAccessors statePropertyAccessor, ILoggerFactory loggerFactory)
            : base(nameof(ViewContactsDialogue))
        {
            StatePropertyAccessor = statePropertyAccessor;

            // Add control flow dialogs
            var waterfallSteps = new WaterfallStep[]
            {
                DisplayContactsAsync,
                DialogueComplete
            };

            AddDialog(new WaterfallDialog(ViewContactDialogId, waterfallSteps));
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ViewContactDialogue"/> class.
        /// </summary>
        /// <param name="botServices">Connected services used in processing.</param>
        /// <param name="statePropertyAccessor">The <see cref="StateBotAccessors"/> for storing properties at user-scope.</param>
        /// <param name="loggerFactory">The <see cref="ILoggerFactory"/> that enables logging and tracing.</param>
        public DeleteContactDialogue(StateBotAccessors statePropertyAccessor, ILoggerFactory loggerFactory)
            : base(nameof(DeleteContactDialogue))
        {
            StatePropertyAccessor = statePropertyAccessor;

            // Add control flow dialogs
            var waterfallSteps = new WaterfallStep[]
            {
                PromptForContactDeletionAsync,
                PromptConfirmDeletionAsync,
                DialogueComplete
            };

            AddDialog(new WaterfallDialog(DeleteContactDialogId, waterfallSteps));
            AddDialog(new TextPrompt(IdPrompt));
            AddDialog(new ConfirmPrompt(confirmPrompt));
        }
Example #8
0
        // private readonly IDataBaseService _databaseService;

        public RootDialog(ILuisService luisService, StateBotAccessors accessors, IQnAMakerAIService qnaMakerAIService)
        {
            _luisService       = luisService;
            _qnaMakerAIService = qnaMakerAIService;
            // _databaseService = databaseService;

            var waterfallSteps = new WaterfallStep[]
            {
                InitialProcess,
                FinalProcess
            };

            //AddDialog(new QualificationDialog(_databaseService));
            //AddDialog(new TextPrompt(nameof(TextPrompt)));
            AddDialog(new WaterfallDialog(nameof(WaterfallDialog), waterfallSteps));
            InitialDialogId = nameof(WaterfallDialog);
        }
Example #9
0
        public ConversationUserStateExampleDialog(StateBotAccessors accessor, string id) : base(id)
        {
            InitialDialogId = Id;

            Accessors = accessor ?? throw new ArgumentNullException(nameof(accessor));
            // Define the prompts used in this conversation flow.
            AddDialog(new TextPrompt(NamePrompt));
            AddDialog(new ChoicePrompt(RatingPrompt));

            // Define the conversation flow using a waterfall model.
            WaterfallStep[] waterfallSteps = new WaterfallStep[]
            {
                NameStepAsync,
                RatingStepAsync,
                FinalStepAsync
            };
            AddDialog(new WaterfallDialog(Id, waterfallSteps));
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="AddContactDialogue"/> class.
        /// </summary>
        /// <param name="botServices">Connected services used in processing.</param>
        /// <param name="statePropertyAccessor">The <see cref="StateBotAccessors"/> for storing properties at user-scope.</param>
        /// <param name="loggerFactory">The <see cref="ILoggerFactory"/> that enables logging and tracing.</param>
        public AddContactDialogue(StateBotAccessors statePropertyAccessor, ILoggerFactory loggerFactory)
            : base(nameof(AddContactDialogue))
        {
            StatePropertyAccessor = statePropertyAccessor;

            // Add control flow dialogs
            var waterfallSteps = new WaterfallStep[]
            {
                InitializeStateStepAsync,
                PromptForIdStepAsync,
                PromptForNameStepAsync,
                PromptForAgeStepAsync,
                DialogueComplete
            };

            AddDialog(new WaterfallDialog(AddContactDialogId, waterfallSteps));
            AddDialog(new TextPrompt(IdPrompt));
            AddDialog(new TextPrompt(NamePrompt));
            AddDialog(new TextPrompt(AgePrompt));
        }
        public WPBotFlowDialog(StateBotAccessors accessors, ILoggerRepository <SqlLoggerRepository> sqlLoggerRepository, IConfiguration configuration)
            : base(nameof(WPBotFlowDialog))

        {
            _accessors           = accessors;
            _sqlLoggerRepository = sqlLoggerRepository;

            WaterfallStep[] waterfallSteps = new WaterfallStep[]
            {
                SalutationHandlerAsync,
                LuisHandlerAsync,
                QnAHandler,
                GetUserConfirmation,
                ProcessUserChoice,
            };

            AddDialog(new WaterfallDialog(nameof(WPBotFlowDialog), waterfallSteps));
            AddDialog(new SalutationHandlerDialog(_sqlLoggerRepository));
            AddDialog(new LuisHandlerDialog(_sqlLoggerRepository, _accessors, configuration));
            AddDialog(new QnAHandlerDialog(sqlLoggerRepository, _accessors, configuration));
            AddDialog(new TextPrompt(ResponseTemplate.UserConfirmCard));
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="CoreBot"/> class.
        /// <param name="botServices">Bot services.</param>
        /// <param name="accessors">Bot State Accessors.</param>
        /// </summary>
        public ContactAssistantBot(StateBotAccessors accessors, BotServices services, UserState userState, ConversationState conversationState, ILoggerFactory loggerFactory)
        {
            _accessors = accessors ?? throw new System.ArgumentNullException(nameof(accessors));

            _services          = services ?? throw new ArgumentNullException(nameof(services));
            _userState         = userState ?? throw new ArgumentNullException(nameof(userState));
            _conversationState = conversationState ?? throw new ArgumentNullException(nameof(conversationState));

            _greetingStateAccessor = _userState.CreateProperty <GreetingState>(nameof(GreetingState));
            _dialogStateAccessor   = _conversationState.CreateProperty <DialogState>(nameof(DialogState));

            // Verify LUIS configuration.
            if (!_services.LuisServices.ContainsKey(LuisConfiguration))
            {
                throw new InvalidOperationException($"The bot configuration does not contain a service type of `luis` with the id `{LuisConfiguration}`.");
            }

            Dialogs = new DialogSet(_dialogStateAccessor);
            Dialogs.Add(new GreetingDialog(_greetingStateAccessor, loggerFactory));
            Dialogs.Add(new AddContactDialogue(_accessors, loggerFactory));
            Dialogs.Add(new ViewContactsDialogue(_accessors, loggerFactory));
            Dialogs.Add(new DeleteContactDialogue(_accessors, loggerFactory));
        }
Example #13
0
        public void ConfigureServices(IServiceCollection services)
        {
            var secretKey   = Configuration.GetSection("botFileSecret")?.Value;
            var botFilePath = Configuration.GetSection("botFilePath")?.Value;

            if (!File.Exists(botFilePath))
            {
                throw new FileNotFoundException($"The .bot configuration file was not found. botFilePath: {botFilePath}");
            }

            // Loads .bot configuration file and adds a singleton that your Bot can access through dependency injection.
            BotConfiguration botConfig = null;

            try
            {
                botConfig = BotConfiguration.Load(botFilePath, secretKey);
            }
            catch
            {
                var msg = @"Error reading bot file. Please ensure you have valid botFilePath and botFileSecret set for your environment.
                            - You can find the botFilePath and botFileSecret in the Azure App Service application settings.
                            - If you are running this bot locally, consider adding a appsettings.json file with botFilePath and botFileSecret.
                            - See https://aka.ms/about-bot-file to learn more about .bot file its use and bot configuration.
                            ";
                throw new InvalidOperationException(msg);
            }

            services.AddSingleton(sp => botConfig ?? throw new InvalidOperationException($"The .bot configuration file could not be loaded. botFilePath: {botFilePath}"));

            // Add BotServices singleton.
            // Create the connected services from .bot file.
            services.AddSingleton(sp => new BotServices(botConfig));

            // Retrieve current endpoint.
            var environment = _isProduction ? "production" : "development";
            var service     = botConfig.Services.FirstOrDefault(s => s.Type == "endpoint" && s.Name == environment);

            if (service == null && _isProduction)
            {
                // Attempt to load development environment
                service = botConfig.Services.Where(s => s.Type == "endpoint" && s.Name == "development").FirstOrDefault();
            }

            if (!(service is EndpointService endpointService))
            {
                throw new InvalidOperationException($"The .bot file does not contain an endpoint with name '{environment}'.");
            }

            // Memory Storage is for local bot debugging only. When the bot
            // is restarted, everything stored in memory will be gone.
            IStorage dataStore = new MemoryStorage();

            // For production bots use the Azure Blob or
            // Azure CosmosDB storage providers. For the Azure
            // based storage providers, add the Microsoft.Bot.Builder.Azure
            // Nuget package to your solution. That package is found at:
            // https://www.nuget.org/packages/Microsoft.Bot.Builder.Azure/
            // Un-comment the following lines to use Azure Blob Storage
            // // Storage configuration name or ID from the .bot file.
            // const string StorageConfigurationId = "<STORAGE-NAME-OR-ID-FROM-BOT-FILE>";
            // var blobConfig = botConfig.FindServiceByNameOrId(StorageConfigurationId);
            // if (!(blobConfig is BlobStorageService blobStorageConfig))
            // {
            //    throw new InvalidOperationException($"The .bot file does not contain an blob storage with name '{StorageConfigurationId}'.");
            // }
            // // Default container name.
            // const string DefaultBotContainer = "<DEFAULT-CONTAINER>";
            // var storageContainer = string.IsNullOrWhiteSpace(blobStorageConfig.Container) ? DefaultBotContainer : blobStorageConfig.Container;
            // IStorage dataStore = new Microsoft.Bot.Builder.Azure.AzureBlobStorage(blobStorageConfig.ConnectionString, storageContainer);

            // Create and add conversation state.
            var conversationState = new ConversationState(dataStore);

            services.AddSingleton(conversationState);

            var userState = new UserState(dataStore);

            services.AddSingleton(userState);

            services.AddBot <ContactAssistantBot>(options =>
            {
                options.CredentialProvider = new SimpleCredentialProvider(endpointService.AppId, endpointService.AppPassword);

                // Catches any errors that occur during a conversation turn and logs them to currently
                // configured ILogger.
                ILogger logger = _loggerFactory.CreateLogger <ContactAssistantBot>();

                options.OnTurnError = async(context, exception) =>
                {
                    logger.LogError($"Exception caught : {exception}");
                    await context.SendActivityAsync("Sorry, it looks like something went wrong.");
                };
            });

            services.AddSingleton <StateBotAccessors>(sp =>
            {
                // Create the custom state accessor.
                var accessors = new StateBotAccessors(conversationState, userState)
                {
                    ContactAccessor     = conversationState.CreateProperty <Contact>(StateBotAccessors.ContactAccessorName),
                    ContactListAccessor = conversationState.CreateProperty <ContactList>(StateBotAccessors.ContactListAccessorName)
                };
                return(accessors);
            });
        }