use of com.twilio.twiml.voice.Play in project api-snippets by TwilioDevEd.
the class TwilioHandleRecordingServlet method service.
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
String recordingUrl = request.getParameter("RecordingUrl");
Say sayHello = new Say.Builder("Listen to your recorded message.").build();
Say sayGoodbye = new Say.Builder("Goodbye").build();
VoiceResponse twiml;
if (recordingUrl != null) {
Play play = new Play.Builder(recordingUrl).build();
twiml = new VoiceResponse.Builder().say(sayHello).play(play).say(sayGoodbye).build();
} else {
response.sendRedirect("/twiml");
return;
}
response.setContentType("application/xml");
try {
response.getWriter().print(twiml.toXml());
} catch (TwiMLException e) {
e.printStackTrace();
}
}
use of com.twilio.twiml.voice.Play in project api-snippets by TwilioDevEd.
the class IncomingCallServlet method doPost.
// Handle HTTP POST to /voice
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// Get the city from the incoming call (if available)
String fromCity = request.getParameter("FromCity");
if (fromCity == null) {
fromCity = "home slice";
}
// Create a TwiML builder object
VoiceResponse twiml = new VoiceResponse.Builder().say(new Say.Builder(String.format("Never gonna give you up, %s!", fromCity)).build()).play(new Play.Builder("https://demo.twilio.com/docs/classic.mp3").build()).build();
// Render TwiML as XML
response.setContentType("text/xml");
try {
response.getWriter().print(twiml.toXml());
} catch (TwiMLException e) {
e.printStackTrace();
}
}
use of com.twilio.twiml.voice.Play in project api-snippets by TwilioDevEd.
the class TwilioServlet method service.
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
// Create a TwiML response and add our friendly message.
Say say = new Say.Builder("Hello. It's me.").build();
Play play = new Play.Builder("https://deved-sample-assets-2691.twil.io/ahoyhoy.mp3").build();
VoiceResponse twiml = new VoiceResponse.Builder().say(say).play(play).build();
response.setContentType("application/xml");
try {
response.getWriter().print(twiml.toXml());
} catch (TwiMLException e) {
e.printStackTrace();
}
}
use of com.twilio.twiml.voice.Play in project twilio-java by twilio.
the class Example method main.
/**
* Example Twilio usage.
*
* @param args command line args
* @throws TwiMLException if unable to generate TwiML
*/
public static void main(String[] args) throws TwiMLException, URISyntaxException {
Twilio.init(ACCOUNT_SID, AUTH_TOKEN);
Iterable<Record> usage = Record.reader().read();
for (Record record : usage) {
System.out.println(record);
}
// Get a number
IncomingPhoneNumber number = buyNumber();
System.out.println(number.getPhoneNumber());
// Send a text message
Message message = Message.creator(ACCOUNT_SID, PHONE_NUMBER, number.getPhoneNumber(), "Hello world!").create();
System.out.println(message.getSid());
System.out.println(message.getBody());
// Make a phone call
Call call = new CallCreator(ACCOUNT_SID, PHONE_NUMBER, number.getPhoneNumber(), URI.create("https://twilio.com")).create();
System.out.println(call.getSid());
// Print all the messages
Iterable<Message> messages = Message.reader().read();
for (Message m : messages) {
System.out.println(m.getSid());
System.out.println(m.getBody());
}
// Get some calls
Iterable<Call> calls = Call.reader().pageSize(2).read();
for (Call c : calls) {
System.out.println(c.getSid());
}
Trunk trunk = new TrunkCreator().setFriendlyName("shiny trunk").setSecure(false).create();
System.out.println(trunk);
// TwiML
TwiML twiml = new VoiceResponse.Builder().say(new Say.Builder("Hello World!").build()).play(new Play.Builder().url(new URI("https://api.twilio.com/cowbell.mp3")).loop(5).build()).build();
System.out.println(twiml.toXml());
}
Aggregations