public ReservationConfirmationTopic(Reservation reservation) : base()
        {
            this.SubTopics.Add(CONFIRMATION_PROMPT, (object[] args) =>
            {
                var confirmationPrompt = new Prompt <string>();

                confirmationPrompt.Set
                .OnPrompt((context, lastTurnReason) =>
                {
                    var recapactivity = ReservationView.ReservationRecapCard(context, reservation);
                    context.SendActivity(recapactivity);

                    var activity = ReservationView.CreatedYesNoCard();
                    context.SendActivity(activity);
                })
                .Validator(new ReservationConfirmationValidator())
                .MaxTurns(2)
                .OnSuccess((context, value) =>
                {
                    this.ClearActiveTopic();
                    this.State.confirmation.confirmationState = value;
                    this.OnTurn(context);
                })
                .OnFailure((context, reason) =>
                {
                    this.ClearActiveTopic();
                    if (reason != null && reason == "toomanyattemps")
                    {
                        context.SendActivity("I'm sorry I'm having issues understanding you.");
                    }
                    this.OnFailure(context, reason);
                });
                return(confirmationPrompt);
            });
        }
Exemple #2
0
        public AddReservationTopic() : base()
        {
            this.SubTopics.Add(STARTDATE_PROMPT, (object[] args) =>
            {
                var startdatePrompt = new Prompt <DateTime>();

                startdatePrompt.Set
                .OnPrompt((context, lastTurnReason) =>
                {
                    if (lastTurnReason != null && lastTurnReason == "novaliddatetime")
                    {
                        context.SendActivity("insert a valid date");
                    }

                    context.SendActivity("What's your check in date?");
                })
                .Validator(new ReservationStartDateValidator())
                .MaxTurns(2)
                .OnSuccess((context, value) =>
                {
                    this.ClearActiveTopic();
                    this.State.reservation.StartDay = value;
                    this.OnTurn(context);
                })
                .OnFailure((context, reason) =>
                {
                    this.ClearActiveTopic();
                    if (reason != null && reason == "toomanyattemps")
                    {
                        context.SendActivity("I'm sorry I'm having issues understanding you.");
                    }
                    this.OnFailure(context, reason);
                });
                return(startdatePrompt);
            });

            this.SubTopics.Add(LOCATION_PROMPT, (object[] args) =>
            {
                var locationPrompt = new Prompt <string>();

                locationPrompt.Set
                .OnPrompt((context, lastTurnReason) =>
                {
                    context.SendActivity("Where you want to go?");
                })
                .Validator(new ReservationLocationValidator())
                .MaxTurns(2)
                .OnSuccess((context, value) =>
                {
                    this.ClearActiveTopic();
                    this.State.reservation.Location = value;
                    this.OnTurn(context);
                })
                .OnFailure((context, reason) =>
                {
                    this.ClearActiveTopic();
                    if (reason != null && reason == "toomanyattemps")
                    {
                        context.SendActivity("I'm sorry I'm having issues understanding you.");
                    }
                    this.OnFailure(context, reason);
                });
                return(locationPrompt);
            });

            this.SubTopics.Add(PEOPLENUMBER_PROMPT, (object[] args) =>
            {
                var peoplenumberPrompt = new Prompt <int>();

                peoplenumberPrompt.Set
                .OnPrompt((context, lastTurnReason) =>
                {
                    context.SendActivity("How many people?");
                })
                .Validator(new ReservationNumberValidator())
                .MaxTurns(2)
                .OnSuccess((context, value) =>
                {
                    this.ClearActiveTopic();
                    this.State.reservation.PeopleNumber = value;
                    this.OnTurn(context);
                })
                .OnFailure((context, reason) =>
                {
                    this.ClearActiveTopic();
                    if (reason != null && reason == "toomanyattemps")
                    {
                        context.SendActivity("I'm sorry I'm having issues understanding you.");
                    }
                    this.OnFailure(context, reason);
                });
                return(peoplenumberPrompt);
            });

            this.SubTopics.Add(DURATION_PROMPT, (object[] args) =>
            {
                var durationPrompt = new Prompt <int>();

                durationPrompt.Set
                .OnPrompt((context, lastTurnReason) =>
                {
                    context.SendActivity("How many days do you want to stay?");
                })
                .Validator(new ReservationNumberValidator())
                .MaxTurns(2)
                .OnSuccess((context, value) =>
                {
                    this.ClearActiveTopic();
                    this.State.reservation.Duration = value;
                    this.OnTurn(context);
                })
                .OnFailure((context, reason) =>
                {
                    this.ClearActiveTopic();
                    if (reason != null && reason == "toomanyattemps")
                    {
                        context.SendActivity("I'm sorry I'm having issues understanding you.");
                    }
                    this.OnFailure(context, reason);
                });
                return(durationPrompt);
            });

            this.SubTopics.Add(CONFIRMATION_PROMPT, (object[] args) =>
            {
                var confirmationPrompt = new ReservationConfirmationTopic(this.State.reservation);

                confirmationPrompt.Set
                .OnSuccess((ctx, confirmation) =>
                {
                    if (confirmation.confirmationState == "yes")
                    {
                        this.ClearActiveTopic();
                        this.State.reservation.Confirmed = "yes";
                        this.OnTurn(ctx);
                    }
                    else
                    {
                        this.ClearActiveTopic();
                        this.State.reservation.Confirmed = "no";
                        this.OnTurn(ctx);
                    }
                })
                .OnFailure((context, reason) =>
                {
                    this.ClearActiveTopic();
                    if (reason != null && reason == "toomanyattemps")
                    {
                        context.SendActivity("I'm sorry I'm having issues understanding you.");
                    }
                    this.OnFailure(context, reason);
                });

                return(confirmationPrompt);
            });

            this.SubTopics.Add(EDIT_PROMPT, (object[] args) =>
            {
                var editPrompt = new Prompt <string>();

                editPrompt.Set
                .OnPrompt((context, lastTurnReason) =>
                {
                    var actions = new Dictionary <string, string>();
                    actions.Add("startdate", "Change Start Date");
                    actions.Add("location", "Change Location");
                    actions.Add("duration", "Change Duration");
                    actions.Add("peoplenumber", "Change People Number");
                    actions.Add("confirmreservation", "Confirm Reservation");

                    var activity = ReservationView.CreateEditReservationHeroCard(actions);
                    // Send the activity as a reply to the user.
                    context.SendActivity(activity);
                })
                .Validator(new ReservationEditValidator())
                .MaxTurns(2)
                .OnSuccess((context, value) =>
                {
                    this.ClearActiveTopic();

                    switch (value)
                    {
                    case "location":
                        this.State.reservation.Location = null;
                        break;

                    case "startdate":
                        this.State.reservation.StartDay = default;
                        break;

                    case "duration":
                        this.State.reservation.Duration = 0;
                        break;

                    case "peoplenumber":
                        this.State.reservation.PeopleNumber = 0;
                        break;

                    case "confirmreservation":
                        this.State.reservation.Confirmed = "yes";
                        break;

                    default:
                        break;
                    }
                    this.OnTurn(context);
                })
                .OnFailure((context, reason) =>
                {
                    this.ClearActiveTopic();
                    if (reason != null && reason == "toomanyattemps")
                    {
                        context.SendActivity("I'm sorry I'm having issues understanding you.");
                    }
                    this.OnFailure(context, reason);
                });
                return(editPrompt);
            });