# 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 `server.rb` to handle incoming calls:

server.rb

```ruby
require 'rubygems'
require 'twilio-ruby'
require 'sinatra'
require 'json'

set :port, 8080

# Get your Account Sid and Auth Token from twilio.com/user/account
account_sid = 'AC99ba7b61fbdb6c039698505dea5f044c'
auth_token = '{{ auth_token }}'
workspace_sid = '{{ workspace_sid }}'
workflow_sid = '{{ workflow_sid }}'

client = Twilio::REST::Client.new(account_sid, auth_token)

post '/assignment_callback' do
  # Respond to assignment callbacks with accept instruction
  content_type :json
  {"instruction": "accept"}.to_json
end

get '/create-task' do
  # Create a task
  task = client.taskrouter.workspaces(workspace_sid)
                            .tasks
                            .create(
                                attributes: {
                                      'selected_language' => 'es'
                            }.to_json,
                                workflow_sid: workflow_sid
                            )
  task.attributes
end

get '/accept_reservation' do
  # Accept a Reservation
  task_sid = params[:task_sid]
  reservation_sid = params[:reservation_sid]

  reservation = client.taskrouter.workspaces(workspace_sid)
                        .tasks(task_sid)
                        .reservations(reservation_sid)
                        .update(reservation_status: 'accepted')
  reservation.worker_name
end

get '/incoming_call' do
  Twilio::TwiML::VoiceResponse.new do |r|
    r.gather(action: '/enqueue_call', method: 'POST', timeout: 5, num_digits: 1) do |gather|
      gather.say(message: 'Para Español oprime el uno.', language: 'es')
      gather.say(message: 'For English, please hold or press two.', language: 'en')
    end
  end.to_s
end
```

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:

![Voice call webhook settings with ngrok URL for incoming calls.](https://docs-resources.prod.twilio.com/9ba7a235d4a76e8ec29f7df3bbf37910e173fbe199dd02bb5f3a23f042210571.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/ruby/twiml-create-task)
