use of com.twilio.twiml.TwiMLException in project api-snippets by TwilioDevEd.
the class MmsHelloMonkey 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 {
try {
Message sms = new Message.Builder().body(new Body("Hello, Mobile Monkey")).media(new Media("https://demo.twilio.com/owl.png")).build();
MessagingResponse twiml = new MessagingResponse.Builder().message(sms).build();
} catch (TwiMLException e) {
e.printStackTrace();
}
response.setContentType("application/xml");
response.getWriter().print(twiml.toXml());
}
use of com.twilio.twiml.TwiMLException 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.TwiMLException 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.TwiMLException 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.TwiMLException in project api-snippets by TwilioDevEd.
the class ReplyByName 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 fromNumber = request.getParameter("From");
String name = fromNumber != null && people.get(fromNumber) != null ? people.get(fromNumber) : "Monkey";
String message = String.format("%s, thanks for the message!", name);
try {
MessagingResponse twiml = new MessagingResponse.Builder().message(message).build();
} catch (TwiMLException e) {
e.printStackTrace();
}
response.setContentType("application/xml");
response.getWriter().print(twiml.toXml());
}
Aggregations