Search in sources :

Example 1 with Sms

use of com.twilio.twiml.voice.Sms 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());
}
Also used : VoiceResponse(com.twilio.twiml.VoiceResponse) Sms(com.twilio.twiml.voice.Sms) Say(com.twilio.twiml.voice.Say) TwiMLException(com.twilio.twiml.TwiMLException)

Aggregations

TwiMLException (com.twilio.twiml.TwiMLException)1 VoiceResponse (com.twilio.twiml.VoiceResponse)1 Say (com.twilio.twiml.voice.Say)1 Sms (com.twilio.twiml.voice.Sms)1