Esempio n. 1
0
        // Process an unfollow command outside a conversation
        private async void ProcessUnfollow(ConnectorClient connector, Activity activity)
        {
            if (activity.Text.ToLower().Contains(GatherQuestions.cStrUnFollow))
            {
                ValidateResult r = new ValidateResult {
                    IsValid = false, Value = GatherErrors.cStrNothingToUnfollow
                };

                if (FlightFlow.ProcessUnfollow(activity.Text, ref r))
                {
                    Activity reply = activity.CreateReply(r.Feedback);

                    await connector.Conversations.ReplyToActivityAsync(reply);
                }
            }
        }
Esempio n. 2
0
        // FormFlow main method, which is responsible for creating
        // the conversation dialog with the user and validating each
        // response
        public static IForm <TravelDetails> BuildForm()
        {
            // Once all the user responses have been gathered the
            // send a response back that the request is being
            // processed
            OnCompletionAsyncDelegate <TravelDetails> processOrder = async(context, state) =>
            {
                await context.PostAsync(GatherQuestions.cStrGatherProcessingReq);
            };

            // FormFlow object that gathers and handles user responses
            var f = new FormBuilder <TravelDetails>()
                    .Message(GatherQuestions.cStrGatherValidData)
                    .Field(nameof(OriginIata),
                           // Validates the point of origin submitted
                           validate: async(state, value) =>
            {
                return(await Task.Run(() =>
                {
                    Data.currentText = value.ToString();

                    return Controllers.FlightFlow.CheckValidateResult(
                        Controllers.FlightFlow.ValidateAirport(state, Data.currentText, false));
                }));
            })
                    .Message("{OriginIata} selected")

                    .Field(nameof(DestinationIata),
                           // Validates the point of destination submitted
                           validate: async(state, value) =>
            {
                return(await Task.Run(() =>
                {
                    Data.currentText = value.ToString();

                    return Controllers.FlightFlow.CheckValidateResult(
                        Controllers.FlightFlow.ValidateAirport(state, Data.currentText, true));
                }));
            })
                    .Message("{DestinationIata} selected")

                    .Field(nameof(OutboundDate),
                           // Validates the outbound travel date submitted
                           validate: async(state, value) =>
            {
                return(await Task.Run(() =>
                {
                    Data.currentText = value.ToString();

                    return Controllers.FlightFlow.CheckValidateResult(
                        Controllers.FlightFlow.ValidateDate(state, Data.currentText, false));
                }));
            })
                    .Message("{OutboundDate} selected")

                    .Field(nameof(InboundDate),
                           // Validates the inbound travel date submitted
                           // (or if it is a one way trip)
                           validate: async(state, value) =>
            {
                return(await Task.Run(() =>
                {
                    Data.currentText = value.ToString();

                    return Controllers.FlightFlow.CheckValidateResult(
                        Controllers.FlightFlow.ValidateDate(state, Data.currentText, true));
                }));
            })
                    .Message("{InboundDate} selected")

                    .Field(nameof(NumPassengers),
                           // Validates the number of passengers submitted for the trip
                           validate: async(state, value) =>
            {
                return(await Task.Run(() =>
                {
                    Data.currentText = value.ToString();

                    return Controllers.FlightFlow.CheckValidateResult(
                        Controllers.FlightFlow.ValidateNumPassengers(state, Data.currentText));
                }));
            })
                    .Message("{NumPassengers} selected")

                    .Field(nameof(Direct),
                           // Validates if the trip is direct or not
                           validate: async(state, value) =>
            {
                return(await Task.Run(() =>
                {
                    Data.currentText = value.ToString();

                    return Controllers.FlightFlow.CheckValidateResult(
                        Controllers.FlightFlow.ValidateDirect(state, Data.currentText));
                }));
            })
                    .Message("{Direct} selected")

                    .Field(nameof(Follow),
                           // Validates if the user has submitted the flight to be
                           // followed for price changes
                           validate: async(state, value) =>
            {
                return(await Task.Run(() =>
                {
                    Data.currentText = value.ToString();

                    ValidateResult res = Controllers.FlightFlow.CheckValidateResult(
                        Controllers.FlightFlow.ValidateFollow(state, Data.currentText));

                    FlightFlow.AssignStateToFlightData(res, state);

                    return res;
                }));
            })
                    .Message("{Follow} selected")

                    // When all the data has been gathered from the user...
                    .OnCompletion(processOrder)
                    .Build();

            return(f);
        }