use of com.twilio.twiml.TwiMLException 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());
}
use of com.twilio.twiml.TwiMLException in project api-snippets by TwilioDevEd.
the class SmsHelloMonkey 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")).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 VoiceServlet method doPost.
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
// Create a TwiML response and add our friendly message.
TwiML twiml = new VoiceResponse.Builder().gather(new Gather.Builder().numDigits(1).say(new Say.Builder("For sales, press 1. For support, press 2.").build()).build()).redirect(new Redirect.Builder().url("/voice").build()).build();
response.setContentType("application/xml");
try {
response.getWriter().print(twiml.toXml());
} catch (TwiMLException e) {
throw new RuntimeException(e);
}
}
use of com.twilio.twiml.TwiMLException in project api-snippets by TwilioDevEd.
the class TrackingSmsConversations method service.
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
HttpSession session = request.getSession(true);
Integer sessionCounter = (Integer) session.getAttribute("counter");
Integer counter = sessionCounter != null ? sessionCounter : new Integer(0);
/* Increment the counter by one, and store the count in the session. */
int count = counter.intValue();
count++;
session.setAttribute("counter", new Integer(count));
// 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");
String toNumber = request.getParameter("To");
String fromNumber = request.getParameter("From");
String name = fromNumber != null && people.get(fromNumber) != null ? people.get(fromNumber) : "Monkey";
String message = String.format("%s has messaged %s %d times.", name, toNumber, String.valueOf(count));
try {
// Create a TwiML response and add our friendly message.
Message sms = new Message.Builder().body(new Body(message)).build();
MessagingResponse twimlResponse = new MessagingResponse.Builder().message(sms).build();
} catch (TwiMLException e) {
e.printStackTrace();
}
response.setContentType("application/xml");
response.getWriter().print(twimlResponse.toXml());
}
use of com.twilio.twiml.TwiMLException 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();
}
}
Aggregations