use of com.twilio.twiml.messaging.Body 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.messaging.Body 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.messaging.Body 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.messaging.Body in project api-snippets by TwilioDevEd.
the class SmsApp method main.
public static void main(String[] args) {
get("/", (req, res) -> "Hello Web");
post("/sms", (req, res) -> {
res.type("application/xml");
Body body = new Body.Builder("The Robots are coming! Head for the hills!").build();
Message sms = new Message.Builder().body(body).build();
MessagingResponse twiml = new MessagingResponse.Builder().message(sms).build();
return twiml.toXml();
});
}
Aggregations