text: How to Use Twilio for Voice and SMS Capabilities in Java
  This guide demonstrates how to perform common programming tasks with the Twilio API service on Azure. The scenarios covered include making a phone call and sending a Short Message Service (SMS) message. For more information on Twilio and using voice and SMS in your applications, see the Next Steps section.
  What is Twilio?
  Twilio is a telephony web-service API that lets you use your existing web languages and skills to build voice and SMS applications. Twilio is a third-party service (not an.
  Twilio Pricing and Special Offers
  Information about Twilio pricing is available at Twilio Pricing. Azure customers receive a special offer: a free credit of 1000 texts or 1000 inbound minutes. To sign up for this offer or get more information, please visit.
  Concepts).
  Twilio Verbs
  The API makes use of Twilio verbs; for example, the <Say> verb instructs Twilio to audibly deliver a message on a call.
  The following is a list of Twilio verbs.
  - <Dial>: Connects the caller to another phone.
  - <Gather>: Collects numeric digits entered on the telephone keypad.
  - <Hangup>: Ends a call.
  - <Play>: Plays an audio file.
  - <Pause>: Waits silently for a specified number of seconds.
  - <Record>: Records the caller's voice.
  Create a Java Application
  - Obtain the Twilio JAR and add it to your Java build path and your WAR deployment assembly. At, you can download the GitHub sources and create your own JAR, or download a pre-built JAR (with or without dependencies).
  - Ensure your JDK's cacerts keystore contains the Equifax Secure Certificate Authority certificate with MD5 fingerprint 67:CB:9D:C0:13:24:8A:82:9B:B2:17:1E:D1:1B:EC:D4 (the serial number is 35:DE:F4:CF and the SHA1 fingerprint is D2:32:09:AD:23:D3:14:23:21:74:E4:0D:7F:9D:62:13:97:86:63:3A). This is the certificate authority (CA) certificate for the service, which is called when you use Twilio APIs. For information about ensuring your JDK's cacerts keystore contains the correct CA certificate, see Adding a Certificate to the Java CA Certificate Store.
  Detailed instructions for using the Twilio client library for Java are available at How to Make a Phone Call Using Twilio in a Java Application on Azure.
  Configure Your Application to Use Twilio Libraries
  Within your code, you can add import statements at the top of your source files for the Twilio packages or classes you want to use in your application.
  For Java source files:
  import com.twilio.*; import com.twilio.sdk.*; import com.twilio.sdk.resource.factory.*; import com.twilio.sdk.resource.instance.*;
  For Java Server Page (JSP) source files:
  import="com.twilio.*" import="com.twilio.sdk.*" import="com.twilio.sdk.resource.factory.*" import="com.twilio.sdk.resource.instance.*"
  Depending on which Twilio packages or classes you want to use, your import statements may be different.
  How to: Make an outgoing call
  The following shows how to make an outgoing call using the CallFactory CallFactory. Account account = client.getAccount(); // Use the Twilio-provided site for the TwiML response. String Url=""; Url = Url + "?Message%5B0%5D=Hello%20World"; // Place the call From, To and URL values into a hash map. HashMap<String, String> params = new HashMap<String, String>(); params.put("From", "NNNNNNNNNN"); // Use your own value for the second parameter. params.put("To", "NNNNNNNNNN"); // Use your own value for the second parameter. params.put("Url", Url); // Create an instance of the CallFactory class. CallFactory callFactory = account.getCallFactory(); // Make the call. Call call = callFactory.create(params);
  For more information about the parameters passed in to the CallFactory.create method, see.
  As mentioned, this code uses a Twilio-provided site to return the TwiML response. You could instead use your own site to provide the TwiML response; for more information, see How to Provide TwiML Responses in a Java Application on Azure.
  How to: Send an SMS message
  The following shows how to send an SMS message using the SmsFactory class. The From number, 4155992671, is provided by Twilio for trial accounts to send SMS messages. The To number must be verified SmsFactory. Account account = client.getAccount(); // Send an SMS message. MessageFactory messageFactory = account.getMessageFactory(); List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair("To", "+14159352345")); // Replace with a valid phone number for your account. params.add(new BasicNameValuePair("From", "+14158141829")); // Replace with a valid phone number for your account. params.add(new BasicNameValuePair("Body", "Where's Wallace?")); Message sms = messageFactory.create(params);
  For more information about the parameters passed in to the SmsFactory.create method, see.
  How to: Provide TwiML Responses from your own Website
  When your application initiates a call to the Twilio API, for example via the CallFactory.create method, Twilio will send your request to a URL that is expected to return a TwiML response. The example above uses the Twilio-provided URL. (While TwiML is designed for use by Web services, you can view the TwiML in your browser. For example, click to see an empty <Response> element; as another example, click in a JSP page.
  The following JSP page results in a TwiML response that says Hello World on the call.
  <%@ page contentType="text/xml" %> <Response> <Say>Hello World</Say> </Response>
  The following JSP page results in a TwiML response that says some text, has several pauses, and says information about the Twilio API version and the Azure role name.
  <%@ page contentType="text/xml" %> <Response> <Say>Hello from Azure</Say> <Pause></Pause> <Say>The Twilio API version is <%= request.getParameter("ApiVersion") %>.</Say> <Say>The Azure role name is <%= System.getenv("RoleName") %>.</Say> <Pause></Pause> <Say>Good bye.</Say> </Response>
  The ApiVersion parameter is available in Twilio voice requests (not SMS requests). To see the available request parameters for Twilio voice and SMS requests, see and, respectively. The RoleName environment variable is available as part of an Azure deployment. (If you want to add custom environment variables so they could be picked up from System.getenv, see the environment variables section at Miscellaneous Role Configuration Settings.)
  Once you have your JSP page set up to provide TwiML responses, use the URL of the JSP page as the URL passed into the CallFactory.create method. For example, if you have a Web application named MyTwiML deployed to an Azure hosted service, and the name of the JSP page is mytwiml.jsp, the URL can be passed to CallFactory.create as shown in the following:
  // Place the call From, To and URL values into a hash map. HashMap<String, String> params = new HashMap<String, String>(); params.put("From", "NNNNNNNNNN"); params.put("To", "NNNNNNNNNN"); params.put("Url", "http://<your_hosted_service>.cloudapp.net/MyTwiML/mytwiml.jsp"); CallFactory callFactory = account.getCallFactory(); Call call = callFactory.create(params);
  Another option for responding with TwiML is via the TwiMLResponse class, which is available in the com.twilio.sdk.verbs package.: