---
"@context": https://schema.org
"@type": TechArticle
"@id": https://www.twilio.com/docs/taskrouter/quickstart/ruby/twiml-create-task#article
headline: "Create Tasks from Phone Calls using TwiML: Create a TaskRouter Task using <Enqueue>"
description: Create a TaskRouter Task from an incoming phone call using the TwiML <Enqueue> verb in Ruby, routing callers to a TaskQueue by their selected language.
url: https://www.twilio.com/docs/taskrouter/quickstart/ruby/twiml-create-task
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: Create a TaskRouter Task using \<Enqueue>

In the previous step we received a call to a Twilio phone number and prompted the caller to select a preferred language. This step handles that input. Create a new endpoint called 'enqueue\_call' and add the following code.

```ruby title="server.rb"
require 'rubygems'
require 'twilio-ruby'
require 'sinatra'
require 'json'

set :port, 8080

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

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

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

post '/enqueue_call' do
  digit_pressed = params[:Digits]
  if digit_pressed == 1
    language = "es"
  else
    language = "en"
  end

  attributes = '{"selected_language":"'+language+'"}'

  Twilio::TwiML::VoiceResponse.new do |r|
    r.enqueue workflowSid: workflow_sid do |e|
      e.task attributes
    end
  end.to_s
end
```

Now call your Twilio phone number. When prompted, press one for Spanish. You should hear Twilio's default \<Queue> hold music. Congratulations! You just added yourself to the 'Customer Care Requests - Spanish' Task Queue based on your selected language. To clarify how exactly this happened, look more closely at what is returned from `enqueue_call` to Twilio when our caller presses one:

```xml title="enqueue_call - TwiML Output"
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Enqueue workflowSid="WW0123401234...">
<Task>{"selected_language": "es"}</Task>
</Enqueue>
</Response>
```

Just like when we created a Task using the TaskRouter REST API (via curl), a Task has been created with an attribute field `selected_language` of value "es". This instructs the Workflow to add the Task to the 'Customer Care Requests - Spanish' TaskQueue based on the Routing Configurations we defined when we set up our Workflow. TaskRouter then starts monitoring for an available Worker to handle the Task.

Looking in the TaskRouter web portal, you will see the newly created Task in the Tasks section, and if you make an eligible Worker available, you should see them assigned to handle the Task. However, we still need a way to bridge the caller to the Worker when the Worker becomes available.

In the next section, we'll use a special Assignment Instruction to easily dequeue the call and route it to an eligible Worker - our good friend Alice. For now, you can hang up the call on hold.

[Next: Dequeue a Call to a Worker >>](/docs/taskrouter/quickstart/ruby/twiml-dequeue-call)
