static async fillOutUserProfile()

in SDKV4-Samples/js/PromptUsersForInput/bot.js [51:118]


    static async fillOutUserProfile(flow, profile, turnContext) {
        const input = turnContext.activity.text;
        let result;
        switch (flow.lastQuestionAsked) {
            // If we're just starting off, we haven't asked the user for any information yet.
            // Ask the user for their name and update the conversation flag.
            case question.none:
                await turnContext.sendActivity("Let's get started. What is your name?");
                flow.lastQuestionAsked = question.name;
                break;

            // If we last asked for their name, record their response, confirm that we got it.
            // Ask them for their age and update the conversation flag.
            case question.name:
                result = this.validateName(input);
                if (result.success) {
                    profile.name = result.name;
                    await turnContext.sendActivity(`I have your name as ${profile.name}.`);
                    await turnContext.sendActivity('How old are you?');
                    flow.lastQuestionAsked = question.age;
                    break;
                } else {
                    // If we couldn't interpret their input, ask them for it again.
                    // Don't update the conversation flag, so that we repeat this step.
                    await turnContext.sendActivity(
                        result.message || "I'm sorry, I didn't understand that.");
                    break;
                }

            // If we last asked for their age, record their response, confirm that we got it.
            // Ask them for their date preference and update the conversation flag.
            case question.age:
                result = this.validateAge(input);
                if (result.success) {
                    profile.age = result.age;
                    await turnContext.sendActivity(`I have your age as ${profile.age}.`);
                    await turnContext.sendActivity('When is your flight?');
                    flow.lastQuestionAsked = question.date;
                    break;
                } else {
                    // If we couldn't interpret their input, ask them for it again.
                    // Don't update the conversation flag, so that we repeat this step.
                    await turnContext.sendActivity(
                        result.message || "I'm sorry, I didn't understand that.");
                    break;
                }

            // If we last asked for a date, record their response, confirm that we got it,
            // let them know the process is complete, and update the conversation flag.
            case question.date:
                result = this.validateDate(input);
                if (result.success) {
                    profile.date = result.date;
                    await turnContext.sendActivity(`Your cab ride to the airport is scheduled for ${profile.date}.`);
                    await turnContext.sendActivity(`Thanks for completing the booking ${profile.name}.`);
                    await turnContext.sendActivity('Type anything to run the bot again.');
                    flow.lastQuestionAsked = question.none;
                    profile = {};
                    break;
                } else {
                    // If we couldn't interpret their input, ask them for it again.
                    // Don't update the conversation flag, so that we repeat this step.
                    await turnContext.sendActivity(
                        result.message || "I'm sorry, I didn't understand that.");
                    break;
                }
        }
    }