示例#1
0
        public static async Task RespondAsMultipleMessagesAsync(
            this IEnumerable <IBotResponse> responses,
            ITurnContext context,
            SurveyState surveyState,
            BotSettings botSettings,
            FeatureToggles features,
            CancellationToken cancellationToken)
        {
            foreach (IBotResponse r in responses)
            {
                if (r is ConditionalBotResponse conditionalResponse && !conditionalResponse.IsValid(surveyState))
                {
                    continue;
                }

                if (features != null && features.RealisticTypingDelay)
                {
                    await context.SendTypingActivityAsync(
                        r.Prompt,
                        botSettings.Typing.CharactersPerMinute,
                        botSettings.Typing.ThinkingTimeDelay);
                }

                await context.SendActivityAsync(r.Prompt, InputHints.IgnoringInput, cancellationToken : cancellationToken);
            }
        }
示例#2
0
        public IActionResult ProcessForm(List <int> question, List <string> answer, string submit, string save, string restore)
        {
            SurveyState state = new SurveyState();

            state.Questions = question;
            state.Answers   = answer;
            Survey survey = new Survey(state);

            if (submit != null)
            {
                Caretaker.Snapshot = null;
                survey.Submit();
                ViewBag.Message = "Survey data submitted!";
            }
            if (save != null)
            {
                Caretaker.Snapshot = survey.CreateSnapshot();
                ViewBag.Message    = "Snapshot created!";
            }

            if (restore != null)
            {
                survey.RestoreSnapshot(Caretaker.Snapshot);
                ViewBag.Message = "Survey restored!";
            }

            ViewBag.Answers = survey.GetAnswers();

            using (AppDbContext db = new AppDbContext())
            {
                List <Question> model = db.Questions.ToList();
                return(View("Index", model));
            }
        }
示例#3
0
        public SurveyTests()
        {
            var userProfileAccessor = new Mock <IStatePropertyAccessor <UserProfile> >();
            var userProfile         = new UserProfile();

            userProfileAccessor.Setup(x => x.GetAsync(It.IsAny <ITurnContext>(), It.IsAny <Func <UserProfile> >(), It.IsAny <CancellationToken>())).ReturnsAsync(userProfile);
            var surveyState = new SurveyState();

            _features = new Features {
                CollateResponses = true, RealisticTypingDelay = false
            };
            var botSettings = new BotSettings();

            _feedbackServiceMock  = new Mock <IFeedbackService>();
            _feedbackBotStateMock = new Mock <IFeedbackBotStateRepository>();
            _feedbackBotStateMock.SetupGet(x => x.UserProfile).Returns(userProfileAccessor.Object);

            var dialogFactory = new DialogFactory(new List <IComponentBuilder <ComponentDialog> >
            {
                new FreeTextDialogComponentBuilder(_feedbackBotStateMock.Object, Options.Create(_features), Options.Create(botSettings)),
                new MultipleChoiceDialogComponentBuilder(_feedbackBotStateMock.Object, Options.Create(_features), Options.Create(botSettings), _feedbackServiceMock.Object),
                new SurveyStartDialogComponentBuilder(_feedbackBotStateMock.Object, Options.Create(_features), Options.Create(botSettings)),
                new SurveyEndDialogComponentBuilder(_feedbackBotStateMock.Object, Options.Create(_features), Options.Create(botSettings), _feedbackServiceMock.Object)
            });

            _dialog = dialogFactory.Create <SurveyDialog>(new InMemoryApprenticeFeedbackSurveyV6());
        }
示例#4
0
        public static async Task Create(
            this IEnumerable <IBotResponse> responses,
            ITurnContext context,
            SurveyState surveyState,
            BotSettings botSettings,
            FeatureToggles features,
            CancellationToken cancellationToken)
        {
            var botResponses = responses as IBotResponse[] ?? responses.ToArray();

            if (botResponses.Any())
            {
                if (features.CollateResponses)
                {
                    await botResponses.RespondAsSingleMessageAsync(
                        context,
                        surveyState,
                        botSettings,
                        features,
                        cancellationToken);
                }
                else
                {
                    await botResponses.RespondAsMultipleMessagesAsync(
                        context,
                        surveyState,
                        botSettings,
                        features,
                        cancellationToken);
                }
            }
        }
示例#5
0
        /// <inheritdoc />
        public DialogSet BuildBranchingDialog(
            DialogSet dialogs,
            string dialogName,
            string prompt,
            IDialogStep positiveBranch,
            IDialogStep negativeBranch)
        {
            dialogs.Add(
                dialogName,
                new WaterfallStep[]
            {
                async(dc, args, next) =>
                {
                    await dc.Context.AddRealisticTypingDelay(prompt, this.TypingSpeed, this.TypingDelay);
                    await dc.Prompt(
                        "confirmationPrompt",
                        prompt,
                        FormHelper.ConfirmationPromptOptions);
                },
                async(dc, args, next) =>
                {
                    SurveyState state   = dc.Context.GetConversationState <SurveyState>();
                    UserState userState = dc.Context.GetUserState <UserState>();

                    bool positive =
                        args["Value"] is FoundChoice response && response.Value == "yes";
                    IDialogStep activeBranch;

                    if (positive)
                    {
                        state.SurveyScore++;
                        activeBranch = positiveBranch;
                    }
                    else
                    {
                        state.SurveyScore--;
                        activeBranch = negativeBranch;
                    }

                    this.logger.LogDebug(
                        $"{userState.UserName} has a survey score of {state.SurveyScore} which has triggered the {(positive ? "positive" : "negative")} conversation tree");

                    await dc.End(dc.ActiveDialog.State);
                    foreach (var r in activeBranch.Responses)
                    {
                        await dc.Context.SendActivity(
                            r,
                            inputHint: InputHints.IgnoringInput);
                        await dc.Context.AddRealisticTypingDelay(r, this.TypingSpeed, this.TypingDelay);
                    }

                    await dc.Begin(activeBranch.DialogTarget);
                },
                async(dc, args, next) => { await dc.End(); }
            });
示例#6
0
        public static string ToSurveyStatusDisplayText(this SurveyState status)
        {
            var text = Enum.GetName(typeof(SurveyState), status);

            switch (status)
            {
            case SurveyState.InProgress:
                text = "In Progress";
                break;

            case SurveyState.NotStarted:
                text = "Not Started";
                break;
            }

            return(text);
        }
        public Survey GetById(int id)
        {
            var currentState = new SurveyState {
                Id = 1, Name = "Created"
            };
            var currentCustomer = new Customer {
                Id = MockRandom.Random().Next(100), Name = "Customer 1"
            };

            return(new Survey
            {
                Id = id,
                SurveyTemplateId = MockRandom.Random().Next(100),
                SurveyState = currentState,
                Customer = currentCustomer,
                UserId = MockRandom.Random().Next(100).ToString()
            });
        }
示例#8
0
        public static async Task RespondAsSingleMessageAsync(
            this IEnumerable <IBotResponse> responses,
            ITurnContext context,
            SurveyState surveyState,
            BotSettings botSettings,
            FeatureToggles features,
            CancellationToken cancellationToken)
        {
            var sb = new StringBuilder();

            foreach (var r in responses)
            {
                if (r is ConditionalBotResponse conditionalResponse && !conditionalResponse.IsValid(surveyState))
                {
                    continue;
                }

                sb.AppendLine(r.Prompt);
            }

            var response = sb.ToString();

            if (features != null && features.RealisticTypingDelay)
            {
                await context.SendTypingActivityAsync(
                    response,
                    botSettings.Typing.CharactersPerMinute,
                    botSettings.Typing.ThinkingTimeDelay);
            }

            var activity = new Activity()
            {
                Id        = context.Activity.Id,
                Type      = ActivityTypes.Message,
                InputHint = InputHints.IgnoringInput,
                Text      = response
            };

            await context.SendActivityAsync(activity, cancellationToken : cancellationToken);
        }
        public List <Survey> GetByUserId(string userId)
        {
            var result       = new List <Survey>();
            var currentState = new SurveyState {
                Id = 1, Name = "Created"
            };
            var currentCustomer = new Customer {
                Id = MockRandom.Random().Next(100), Name = "Customer 1"
            };

            result.Add(new Survey
            {
                Id = MockRandom.Random().Next(100),
                SurveyTemplateId = MockRandom.Random().Next(100),
                SurveyState      = currentState,
                Customer         = currentCustomer,
                UserId           = userId
            });
            result.Add(new Survey
            {
                Id = MockRandom.Random().Next(100),
                SurveyTemplateId = MockRandom.Random().Next(100),
                SurveyState      = currentState,
                Customer         = currentCustomer,
                UserId           = userId
            });
            result.Add(new Survey
            {
                Id = MockRandom.Random().Next(100),
                SurveyTemplateId = MockRandom.Random().Next(100),
                SurveyState      = currentState,
                Customer         = currentCustomer,
                UserId           = userId
            });
            return(result);
        }
        public override bool IsValid(SurveyState state)
        {
            var lastResponse = state.Responses.LastOrDefault();

            return(lastResponse != null && lastResponse.IsPositive);
        }
 public bool Delete(SurveyState element)
 {
     throw new NotImplementedException();
 }
 public abstract bool IsValid(SurveyState state);
 public override bool IsValid(SurveyState state)
 {
     return(this.Predicate.Invoke(state));
 }