Java
Switch branches/tags
twilio-java-sdk-video-beta-4.5.1 twilio-java-sdk-beta-5.2.1 twilio-java-sdk-7.0.0-rc-11 twilio-java-sdk-7.0.0-rc-10 twilio-java-sdk-7.0.0-rc-9 twilio-java-sdk-7.0.0-rc-8 twilio-java-sdk-7.0.0-rc-7 twilio-java-sdk-7.0.0-rc-6 twilio-java-sdk-7.0.0-rc-5 twilio-java-sdk-7.0.0-rc-4 twilio-java-sdk-7.0.0-rc-3 twilio-java-sdk-7.0.0-rc-2 twilio-java-sdk-7.0.0-rc-1 twilio-java-sdk-7.0.0-rc-0 twilio-java-sdk-6.3.0 twilio-java-sdk-6.2.0-edge twilio-java-sdk-6.1.0-edge twilio-java-sdk-6.0.1-edge twilio-java-sdk-6.0.0-edge twilio-java-sdk-5.12.0 twilio-java-sdk-5.11.0 twilio-java-sdk-5.10.1 twilio-java-sdk-5.10.0 twilio-java-sdk-5.9.0 twilio-java-sdk-5.8.0 twilio-java-sdk-5.7.1 twilio-java-sdk-5.7.0 twilio-java-sdk-5.6.0 twilio-java-sdk-5.5.1 twilio-java-sdk-5.5.0 twilio-java-sdk-5.4.0 twilio-java-sdk-5.4.0-edge twilio-java-sdk-5.3.1-edge twilio-java-sdk-5.3.0 twilio-java-sdk-5.3.0-edge twilio-java-sdk-5.2.1 twilio-java-sdk-5.2.1-edge twilio-java-sdk-5.2.0 twilio-java-sdk-5.1.0 twilio-java-sdk-5.0.0 twilio-java-sdk-4.5.0 twilio-java-sdk-4.4.5 twilio-java-sdk-4.4.4 twilio-java-sdk-4.4.3 twilio-java-sdk-4.4.2 twilio-java-sdk-4.4.1 twilio-java-sdk-4.4.0 twilio-java-sdk-4.3.0 twilio-java-sdk-4.2.0 twilio-java-sdk-4.1.0 twilio-java-sdk-4.0.2 twilio-java-sdk-4.0.1 twilio-java-sdk-4.0.0 twilio-java-sdk-3.8.0 twilio-java-sdk-3.7.2 twilio-java-sdk-3.7.1 twilio-java-sdk-3.7.0 twilio-java-sdk-3.6.2 twilio-java-sdk-3.6.1 twilio-java-sdk-3.6.0 twilio-java-sdk-3.5.0 twilio-java-sdk-3.4.6 twilio-java-sdk-3.4.5 twilio-java-sdk-3.4.4 twilio-java-sdk-3.4.3 twilio-java-sdk-3.4.2 twilio-java-sdk-3.4.1 twilio-java-sdk-3.4.0 twilio-java-sdk-3.3.16 twilio-java-sdk-3.3.15 twilio-java-sdk-3.3.14 twilio-java-sdk-3.3.13 twilio-java-sdk-3.3.12 twilio-java-sdk-3.3.11 twilio-java-sdk-3.3.10 twilio-7.14.0 twilio-7.13.1 twilio-7.12.0 twilio-7.12.0-alpha-1 twilio-7.11.0 twilio-7.11.0-alpha-1 twilio-7.10.1-alpha-1 twilio-7.10.0 twilio-7.9.1 twilio-7.9.1-alpha-1 twilio-7.9.0 twilio-7.9.0-alpha-2 twilio-7.9.0-alpha-1 twilio-7.8.2 twilio-7.8.1 twilio-7.8.1-alpha1 twilio-7.8.0 twilio-7.8.0-alpha-1 twilio-7.7.2-alpha1 twilio-7.7.1 twilio-7.7.1-alpha-1 twilio-7.7.0 twilio-7.7.0-alpha1 twilio-7.6.0 twilio-7.6.0-alpha-1
Nothing to show

README.md

twilio-java

Build Status Maven Central

Recent Update

As of release 7.14.0, Beta and Developer Preview products are now exposed via the main twilio-java artifact. Releases of the alpha branch have been discontinued.

If you were using the alpha release line, you should be able to switch back to the normal release line without issue.

If you were using the normal release line, you should now see several new product lines that were historically hidden from you due to their Beta or Developer Preview status. Such products are explicitly documented as Beta/Developer Preview both in the Twilio docs and console, as well as through in-line code documentation here in the library.

Installing

twilio-java uses Maven. At present the jars are available from a public maven repository.

Use the following dependency in your project to grab via Maven:

   <dependency>
      <groupId>com.twilio.sdk</groupId>
      <artifactId>twilio</artifactId>
      <version>7.X.X</version>
      <scope>compile</scope>
   </dependency>

or Gradle:

compile "com.twilio.sdk:twilio:7.X.X"

If you want to compile it yourself, here's how:

$ git clone git@github.com:twilio/twilio-java
$ cd twilio-java
$ mvn install       # Requires maven, download from http://maven.apache.org/download.html

Quickstart

Send a SMS

String accountSid = "ACXXXXXX"; // Your Account SID from www.twilio.com/user/account
String authToken = "XXXXXXXX"; // Your Auth Token from www.twilio.com/user/account

Twilio.init(accountSid, authToken);

Message message = Message.creator(
    new PhoneNumber("+15558881234"),  // To number
    new PhoneNumber("+15559994321"),  // From number
    "Hello world!"                    // SMS body
).create();

System.out.println(message.getSid());

Make a call

String accountSid = "ACXXXXXX"; // Your Account SID from www.twilio.com/user/account
String authToken = "XXXXXXXX"; // Your Auth Token from www.twilio.com/user/account

Twilio.init(accountSid, authToken);

Call call = Call.creator(
    new PhoneNumber("+15558881234"),  // To number
    new PhoneNumber("+15559994321"),  // From number

    // Read TwiML at this URL when a call connects (hold music)
    new URI("http://twimlets.com/holdmusic?Bucket=com.twilio.music.ambient")
).create();

System.out.println(call.getSid());

Generating TwiML

To control phone calls, your application needs to output TwiML. TwiML in twilio-java now use the builder pattern!

TwiML twiml = new VoiceResponse.Builder()
    .say(new Say.Builder("Hello World!").build())
    .play(new Play.Builder("https://api.twilio.com/cowbell.mp3").loop(5).build())
    .build();

That will output XML that looks like this:

<Response>
    <Say>Hello World!</Say>
    <Play loop="5">https://api.twilio.com/cowbell.mp3</Play>
</Response>

Documentation

The documentation for the Twilio API can be found here.

Getting help

If you need help installing or using the library, please contact Twilio Support at help@twilio.com first. Twilio's Support staff are well-versed in all of the Twilio Helper Libraries, and usually reply within 24 hours.

If you've instead found a bug in the library or would like new features added, go ahead and open issues or pull requests against this repo!