Voice TwiML Java Quickstart


The goal of this quickstart is to understand how Twilio lets you control phone calls using the Twilio Markup Language (TwiML).

Twilio Markup Language

Twilio Markup Language (TwiML) defines a simple set of instructions for letting your PHP/Java/Ruby/C#/Python web application control live phone calls. New TwiML instructions are fetched by Twilio from your server at the start of each phone call and then again each time there is input from the phone. Whenever the phone connected to Twilio performs an action such as a key press, Twilio makes a request to your server asking your application for a new set of TwiML instructions.

For example, when someone calls your Twilio-powered phone number, Twilio looks up the voice URL of the web application you've previously configured for that phone number and makes a request to the server, providing information about who called and asking the web server what to do on that call. Your web app can then respond with a set of TwiML instructions that begin an interactive dialog between Twilio and your web server.

How Twilio Interacts with Your Application

When a new phone call starts or there is a user input e.g., a key press or a Dial ends, Twilio makes an HTTP GET or POST to your web server (as specified by your app). If you use HTTP POST, Twilio passes parameters as form-encoded variables in the body of the POST. If you use HTTP GET, parameters are passed in the URL query string.

Let's look at a real example.

This tutorial assumes you have a Java development environment with a Web server capable of running Java servlets, and the twilio-java helper library. Please see our post on setting up your environment if you need help installing those programs.

Next: <Say> a greeting »

Need some help?

We all do sometimes; code is hard. Get help now from our support team, or lean on the wisdom of the crowd browsing the Twilio tag on Stack Overflow.