def update_conduct_interview_task():
    task_name = "conduct_interview"
    assistant = Client(ACCOUNT_SID,
                       AUTH_TOKEN).autopilot.assistants(ASSISTANT_SID)
    task = assistant.tasks(sid=task_name)

    speech_actions = {
        "actions": [{
            "say":
            "Hello there. Let's get started with your interview."
        }, {
            "redirect": {
                "uri": "{}/api/build_session".format(API_BASE)
            }
        }]
    }

    task = task.update(actions=speech_actions)

    print("Conduct Interview Task SID:", task.sid)
def update_start_interview_practice_task():
    task_name = "start_interview_practice"
    assistant = Client(ACCOUNT_SID,
                       AUTH_TOKEN).autopilot.assistants(ASSISTANT_SID)
    task = assistant.tasks(sid=task_name)

    # Get all categories
    app = create_app()
    with app.app_context():
        categories = Category.query.all()

    categories_list = [
        c.category.title() + ': ' + c.description for c in categories
    ]

    category_selection_question = "\n\nWhat kind of interview would you like to practice? You can choose from the following list. \n\n - {}".format(
        '\n - '.join(categories_list))

    speech_actions = {
        "actions": [{
            "say": "Hello there! Let's get some practice in. "
        }, {
            "collect": {
                "name":
                "category_selection",
                "questions": [{
                    "question": category_selection_question,
                    "name": "category",
                    "validate": {
                        "allowed_values": {
                            "list": [c.category for c in categories]
                        },
                        "on_failure": {
                            "messages": [{
                                "say":
                                "That's not a valid interview question type."
                            }]
                        }
                    }
                }, {
                    "question": "How many questions do you want?",
                    "name": "limit",
                    "type": "Twilio.NUMBER"
                }, {
                    "question":
                    "Great! I'll call you in a few so that we can practice. When you're ready, text back saying 'Ready'",
                    "name": "ready",
                    "validate": {
                        "allowed_values": {
                            "list": ["Ready", "I'm Ready"]
                        },
                        "on_failure": {
                            "messages": [{
                                "say":
                                "No worries. Let me know when you're ready."
                            }]
                        }
                    }
                }],
                "on_complete": {
                    "redirect": {
                        "uri": "{}/api/call".format(API_BASE),
                        "method": "POST"
                    }
                }
            }
        }]
    }

    task = task.update(actions=speech_actions)

    samples = task.samples.list(limit=100)

    # Train phrases
    phrases = [
        "Interview", "I want to practice an interview.", "Practice interview"
    ]

    # Only add new phrases
    samples_text = [sample.tagged_text for sample in samples]

    new_phrases = set(phrases).difference(set(samples_text))
    for phrase in new_phrases:
        sample = task.samples.create(language='en-us', tagged_text=phrase)

    # Remove any deleted phrases
    removed_samples = [
        sample for sample in samples if sample.tagged_text not in phrases
    ]
    for sample in removed_samples:
        task.samples(sample.sid).delete()

    print("Interview Task SID:", task.sid)