コード例 #1
0
        private static async Task BindProfileQuestionsAsync(QuestionsFlow flow, Profile profile, ITurnContext turnContext)
        {
            string input = turnContext.Activity.Text?.Trim();
            string message;

            switch (flow.LastQuestionAsked)
            {
            case QuestionsFlow.Question.None:
                await turnContext.SendActivityAsync("Let's get started. What is your name?");

                flow.LastQuestionAsked = QuestionsFlow.Question.Name;
                break;

            case QuestionsFlow.Question.Name:
                if (RecognizeHelper.CheckName(input, out string name, out message))
                {
                    profile.Name = name;
                    await turnContext.SendActivityAsync($"Hi {profile.Name}.");

                    await turnContext.SendActivityAsync("How old are you?");

                    flow.LastQuestionAsked = QuestionsFlow.Question.Age;
                    break;
                }
                else
                {
                    await turnContext.SendActivityAsync(message ?? "I'm sorry, I didn't understand that.");

                    break;
                }
コード例 #2
0
        protected override async Task OnMessageActivityAsync(ITurnContext <IMessageActivity> turnContext, CancellationToken cancellationToken)
        {
            IStatePropertyAccessor <QuestionsFlow> conversationStateAccessors = _conversationState.CreateProperty <QuestionsFlow>(nameof(QuestionsFlow));
            QuestionsFlow flow = await conversationStateAccessors.GetAsync(turnContext, () => new QuestionsFlow());

            IStatePropertyAccessor <Profile> userStateAccessors = _userState.CreateProperty <Profile>(nameof(Profile));
            Profile profile = await userStateAccessors.GetAsync(turnContext, () => new Profile());

            await BindProfileQuestionsAsync(flow, profile, turnContext);

            // Save State changes.
            await _conversationState.SaveChangesAsync(turnContext);

            await _userState.SaveChangesAsync(turnContext);
        }