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

We've seen how to create Tasks using the TaskRouter REST API and how to accept a Task Reservation using both the REST API and Assignment Callback instructions. TaskRouter also introduces new TwiML instructions that you can use to create a Task from a Twilio phone call.

## Receive an Incoming Call

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 `Program.cs` to handle incoming calls:

### Program.cs

```csharp
using System;
using System.Net;
using SimpleWebServer;
using Twilio;
using Twilio.Rest.Taskrouter.V1.Workspace;
using Twilio.Rest.Taskrouter.V1.Workspace.Task;
using Twilio.TwiML;

namespace taskroutercsharp
{
    class MainClass
    {
        // Find your Account Sid and Auth Token at twilio.com/user/account
        const string AccountSid = "{{ account_sid }}";
        const string AuthToken = "{{ auth_token }}";
        const string WorkspaceSid = "{{ workspace_sid }}";
        const string WorkflowSid = "{{ workflow_sid }}";

        public static void Main(string[] args)
        {
            // Initialize the Twilio client
            TwilioClient.Init(AccountSid, AuthToken);

            WebServer ws = new WebServer(SendResponse, "http://localhost:8080/");
            ws.Run();
            Console.WriteLine("A simple webserver. Press a key to quit.");
            Console.ReadKey();
            ws.Stop();
        }

        public static HttpListenerResponse SendResponse(HttpListenerContext ctx)
        {
            HttpListenerRequest request = ctx.Request;
            HttpListenerResponse response = ctx.Response;

            String endpoint = request.RawUrl;

            if (endpoint.EndsWith("assignment_callback"))
            {
                response.StatusCode = (int)HttpStatusCode.OK;
                response.ContentType = "application/json";
                response.StatusDescription = "{\"instruction\":\"accept\"}";
                return response;
            }
            else if (endpoint.EndsWith("create_task"))
            {
                response.StatusCode = (int)HttpStatusCode.OK;
                response.ContentType = "application/json";
                TaskResource task = TaskResource.Create(
                    WorkspaceSid,
                    attributes: "{\"selected_language\":\"es\"}",
                    workflowSid: WorkflowSid);

                response.StatusDescription = task.Attributes;
                return response;
            }
            else if (endpoint.EndsWith("accept_reservation"))
            {
                response.StatusCode = (int)HttpStatusCode.OK;
                response.ContentType = "application/json";
                var taskSid = request.QueryString["TaskSid"];
                var reservationSid = request.QueryString["ReservationSid"];
                ReservationResource reservation = ReservationResource.Update(
                    WorkspaceSid,
                    taskSid,
                    reservationSid,
                    ReservationResource.StatusEnum.Accepted);

                response.StatusDescription = "{\"reservation_status\":\"" + reservation.ReservationStatus + "\"}";
                return response;
            }
            else if (endpoint.EndsWith("incoming_call"))
            {
                response.StatusCode = (int)HttpStatusCode.OK;
                response.ContentType = "application/xml";
                var twiml = new VoiceResponse();
                twiml.Gather(new Gather(numDigits: 1, action: "enqueue_call")
                    .Say("Para Espanol oprima el uno.", language: "es" )
                    .Say("For English, please hold or press two.", language: "en"));

                response.StatusDescription = twiml.ToString();
                return response;
            }
            response.StatusCode = (int)HttpStatusCode.OK;
            return response;
        }
    }
}
```

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/csharp/twiml-create-task)
