private static async Task FillOutUserProfileAsync(ConversationFlow flow, UserProfile profile, ITurnContext turnContext, CancellationToken cancellationToken)
        {
            var    input = turnContext.Activity.Text?.Trim();
            string message;

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

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

            case ConversationFlow.Question.Name:
                if (ValidateName(input, out var name, out message))
                {
                    profile.Name = name;
                    await turnContext.SendActivityAsync($"Hi {profile.Name}.", null, null, cancellationToken);

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

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

                    break;
                }
Example #2
0
        private static async Task FillOutUserProfileAsync(ConversationFlow flow, UserProfile profile, ITurnContext turnContext)
        {
            string input = turnContext.Activity.Text?.Trim();
            string message;

            switch (flow.LastQuestionAsked)
            {
            case ConversationFlow.Question.None:
                await turnContext.SendActivityAsync("Welcome to NextMeal! Let's get started.");

                await turnContext.SendActivityAsync("Please enter your address:");

                flow.LastQuestionAsked = ConversationFlow.Question.Location;
                break;

            case ConversationFlow.Question.Location:
                if (ValidateString(input, out string location, out message))
                {
                    profile.Location = location;
                    await turnContext.SendActivityAsync("Do you have any dietary restrictions?");

                    await turnContext.SendActivityAsync("Enter vegetarian, vegan, gluten-free, halal, kosher, or none");

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

                    break;
                }
Example #3
0
        private static async Task FillOutUserProfileAsync(ConversationFlow flow, UserProfile profile, ITurnContext turnContext, CancellationToken cancellationToken)
        {
            var    input = turnContext.Activity.Text?.Trim();
            string message;

            switch (flow.LastQuestionAsked)
            {
            case ConversationFlow.Question.None:
                await turnContext.SendActivityAsync("Please enter event subject", null, null, cancellationToken);

                flow.LastQuestionAsked = ConversationFlow.Question.Subject;
                break;

            case ConversationFlow.Question.Subject:
                if (ValidateSubject(input, out var subject, out message))
                {
                    profile.Subject = subject;
                    await turnContext.SendActivityAsync($"Event subject is{profile.Subject}.", null, null, cancellationToken);

                    await turnContext.SendActivityAsync("Please enter event body", null, null, cancellationToken);

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

                    break;
                }
        /// <summary>The turn handler for the bot.</summary>
        /// <param name="turnContext">A <see cref="ITurnContext"/> containing all the data needed
        /// for processing this conversation turn. </param>
        /// <param name="cancellationToken">(Optional) A <see cref="CancellationToken"/> that can be used by other objects
        /// or threads to receive notice of cancellation.</param>
        /// <returns>A <see cref="Task"/> that represents the work queued to execute.</returns>
        public async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default(CancellationToken))
        {
            // Handle Message activity type, which is the main activity type for shown within a conversational interface
            // Message activities may contain text, speech, interactive cards, and binary or unknown attachments.
            // see https://aka.ms/about-bot-activity-message to learn more about the message and other activity types
            if (turnContext.Activity.Type == ActivityTypes.Message)
            {
                // Get the state properties from the turn context.
                ConversationFlow flow = await _accessors.ConversationFlowAccessor.GetAsync(turnContext, () => new ConversationFlow());

                UserProfile profile = await _accessors.UserProfileAccessor.GetAsync(turnContext, () => new UserProfile());

                await FillOutUserProfileAsync(flow, profile, turnContext);

                // Update state and save changes.
                await _accessors.ConversationFlowAccessor.SetAsync(turnContext, flow);

                await _accessors.ConversationState.SaveChangesAsync(turnContext);

                await _accessors.UserProfileAccessor.SetAsync(turnContext, profile);

                await _accessors.UserState.SaveChangesAsync(turnContext);
            }
        }