Exemplo n.º 1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var configurationBuilder = new ConfigurationBuilder()
                                       .SetBasePath(Env.ContentRootPath)
                                       .AddJsonFile("appsettings.json");

            var configuration = configurationBuilder.Build();

            IStorage storage           = new MemoryStorage();
            var      conversationState = new ConversationState(storage);

            services.AddSingleton(conversationState);

            services.AddBot <TableReservationBot>((options) =>
            {
                options.CredentialProvider = new ConfigurationCredentialProvider(configuration);
            });

            services.AddSingleton <TableReservationAccessors>(sp =>
            {
                var accessors = new TableReservationAccessors(conversationState)
                {
                    ConversationDialogState = conversationState.CreateProperty <DialogState>("DialogState"),
                    TableReservationState   = conversationState.CreateProperty <TableReservation>("TableReservationState")
                };

                return(accessors);
            });


            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
        }
        public TableReservationBot(TableReservationAccessors accessors)
        {
            _accessors = accessors;


            _dialogs = new DialogSet(_accessors.ConversationDialogState);

            var waterfallSteps = new WaterfallStep[]
            {
                NameStepAsync,
                NameConfirmStepAsync,
                OccupantStepAsync,
                DateOfReservationStepAsync,
                TimeOfReservationStepAsync,
                ConfirmRservationStepAsync
            };

            _dialogs.Add(new WaterfallDialog("details", waterfallSteps));
            _dialogs.Add(new TextPrompt("name"));
            _dialogs.Add(new NumberPrompt <int>("occupants", OccupantValidationAsync));
            _dialogs.Add(new DateTimePrompt("reservationDate"));
            _dialogs.Add(new DateTimePrompt("reservationTime"));
            _dialogs.Add(new ChoicePrompt("confirmReservation"));
        }