---
"@context": https://schema.org
"@type": TechArticle
"@id": https://www.twilio.com/docs/taskrouter/quickstart/python/twiml-receive-call#article
headline: "Create Tasks from Phone Calls using TwiML: Receive an Incoming Call"
description: Configure a Twilio phone number and Python Flask endpoint to receive an incoming call and create a TaskRouter Task using TwiML in the Python Quickstart.
url: https://www.twilio.com/docs/taskrouter/quickstart/python/twiml-receive-call
inLanguage: en
dateModified: 2026-08-14T23:05:46.000Z
author:
  "@type": Organization
  name: Twilio Developer Education Team
publisher:
  "@type": Organization
  name: Twilio
---

# Create Tasks from Phone Calls using TwiML: Receive an Incoming Call

You can create a TaskRouter Task directly from a Twilio phone call using TwiML instructions. So far in this Quickstart, you've created Tasks using the TaskRouter REST API and accepted Task Reservations using both the REST API and Assignment Callback instructions.

To receive an incoming phone call, we first need a Twilio phone number. In this example we'll use a US toll-free number, but you can use a Voice capable number from any country.

Before purchasing or setting up the phone number, we need to add on to our `run.py` to handle incoming calls:

## run.py

```python
# -*- coding: latin-1 -*-

from flask import Flask, request, Response
from twilio.rest import Client
from twilio.twiml.voice_response import VoiceResponse

app = Flask(__name__)

# Find your Account SID at twilio.com/console
# Provision API Keys at twilio.com/console/runtime/api-keys
account_sid = "{{ account_sid }}"
api_key = "{{ api_key }}"
api_secret = "{{ api_secret }}"
workspace_sid = "{{ workspace_sid }}"
workflow_sid = "{{ workflow_sid }}"

client = Client(api_key, api_secret, account_sid)

@app.route("/assignment_callback", methods=['GET', 'POST'])
def assignment_callback():
    """Respond to assignment callbacks with an acceptance and 200 response"""

     ret = '{"instruction": "accept"}'
    resp = Response(response=ret, status=200, mimetype='application/json')
    return resp

@app.route("/create_task", methods=['GET', 'POST'])
def create_task():
    """Creating a Task"""
    task = client.workspaces(workspace_sid) \
                 .tasks.create(workflow_sid=workflow_sid,
                               attributes='{"selected_language":"es"}')

    print(task.attributes)
    resp = Response({}, status=200, mimetype='application/json')
    return resp

@app.route("/accept_reservation", methods=['GET', 'POST'])
def accept_reservation(task_sid, reservation_sid):
    """Accepting a Reservation"""
    task_sid = request.args.get('task_sid')
    reservation_sid = request.args.get('reservation_sid')

    reservation = client.workspaces(workspace_sid) \
                        .tasks(task_sid) \
                        .reservations(reservation_sid) \
                        .update(reservation_status='accepted')

    print(reservation.reservation_status)
    print(reservation.worker_name)

    resp = Response({}, status=200, mimetype='application/json')
    return resp

@app.route("/incoming_call", methods=['GET', 'POST'])
def incoming_call():
    """Respond to incoming requests."""

    resp = VoiceResponse()
    with resp.gather(numDigits=1, action="/enqueue_call", method="POST", timeout=5) as g:
        g.say("Para Español oprime el uno.", language='es')
        g.say("For English, please hold or press two.", language='en')

    return str(resp)

if __name__ == "__main__":
    app.run(debug=True)
```

You can use the [Buy Numbers](https://console.twilio.com/?frameUrl=%2Fconsole%2Fphone-numbers%2Fsearch) section of the Twilio Voice and Messaging web portal to purchase a new phone number, or use an existing Twilio phone number. Open the phone number details page and point the Voice Request URL at your new endpoint:

![TaskRouter Quickstart showing phone number properties and request URLs for voice and messaging.](https://docs-resources.prod.twilio.com/6a0de916bec885f256d33e8883f001eab45b017ff0e2bbe6615c10e0a0e53a13.png)

Using any phone, call the Twilio number. You will be prompted to press one for Spanish or two for English. However, when you press a digit, you'll hear an error message. That's because our `<Gather>` verb is pointing to another endpoint, `enqueue_call`, which we haven't implemented yet. In the next step we'll add the required endpoint and use it to create a new Task based on the language selected by the caller.

[Next: Create a Task using Enqueue »](/docs/taskrouter/quickstart/python/twiml-create-task)
