use of com.twilio.twiml.VoiceResponse 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.VoiceResponse in project api-snippets by TwilioDevEd.
the class Example method service.
public void service(final HttpServletRequest request, final HttpServletResponse response) throws IOException {
Dial dial = new Dial.Builder().queue(new Queue.Builder("Queue Demo").build()).build();
VoiceResponse voiceResponse = new VoiceResponse.Builder().dial(dial).build();
try {
response.getWriter().print(voiceResponse.toXml());
} catch (TwiMLException e) {
e.printStackTrace();
}
}
use of com.twilio.twiml.VoiceResponse 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.VoiceResponse in project twilio-java by twilio.
the class TwiMLResponseExample method main.
/**
* TwiML example usage.
*
* @param args command line args
* @throws TwiMLException if cannot generate TwiML
*/
public static void main(final String[] args) throws TwiMLException, URISyntaxException {
// Say
Say say = new Say.Builder("Hello World!").voice(Say.Voice.MAN).loop(5).build();
VoiceResponse response = new VoiceResponse.Builder().say(say).build();
System.out.println(response.toXml());
// Gather, Redirect
Gather gather = new Gather.Builder().numDigits(10).say(new Say.Builder("Press 1").build()).build();
Redirect redirect = new Redirect.Builder(new URI("https://example.com")).build();
response = new VoiceResponse.Builder().gather(gather).redirect(redirect).build();
System.out.println(response.toXml());
// Conference
Conference conference = new Conference.Builder("my room").beep(Conference.Beep.TRUE).build();
Dial dial = new Dial.Builder().callerId("+1 (555) 555-5555").action(new URI("https:///example.com")).hangupOnStar(true).conference(conference).build();
response = new VoiceResponse.Builder().dial(dial).build();
System.out.println(response.toXml());
}
use of com.twilio.twiml.VoiceResponse in project api-snippets by TwilioDevEd.
the class SendSmsDuringCall method service.
// service() responds to both GET and POST requests.
// You can also use doGet() or doPost()
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
// Create a dict of people we know.
HashMap<String, String> people = new HashMap<String, String>();
people.put("+14158675308", "Curious George");
people.put("+12349013030", "Boots");
people.put("+12348134522", "Virgil");
// if the sender is known, then greet them by name
String name = people.get(Request.getParameter("From")) != null ? people.get(Request.getParameter("From")) : "Monkey";
try {
Say say = new Say.Builder().build(String.format("Hello! %s", name));
Sms sms = new Sms.Builder().build(String.format("%s, thanks for the call!", name));
VoiceResponse twiml = new VoiceResponse.Builder().say(say).sms(sms).build();
} catch (TwiMLException e) {
e.printStackTrace();
}
response.setContentType("application/xml");
response.getWriter().print(twiml.toXml());
}
Aggregations