Configured a webhook URL which calls the below code :::
String body = request.getParameter("Body");
String fromNumber = request.getParameter("From");
String message;
Message sms = new Message.Builder().body(new Body(message)).build();
// Create a TwiML response and add our friendly message.
MessagingResponse twiml = new MessagingResponse.Builder().message(sms).build();
response.setContentType("application/xml");
try {
response.getWriter().print(twiml.toXml());
return twiml.toXml();
final TwilioEmailContextDTO twilioEmailContextDTO = new TwilioEmailContextDTO();
twilioEmailContextDTO.setBody(body);
twilioEmailContextDTO.setFromNumber(fromNumber);
forwardTwilioSMSToMail(twilioEmailContextDTO);
}
Q1 : Does String fromNumber = request.getParameter("From");
give me the from number.
Q2 : Also I am getting the The constructor Body(String) is undefined"
compilation error.
Q3 : I am using conventional Hybris way to forward the SMS as a mail(using emailService), do we have a twilio way of doing it?
update with code
{ Please have a look at the method I am using. Using Spring, annotations.
@RequestMapping(value = "/twilioReply", method = RequestMethod.POST)
@ResponseBody
public void TwilioReplies(HttpServletRequest request, HttpServletResponse response) throws IOException {
String body = request.getParameter("Body");
String fromNumber = request.getParameter("From");
String messageBody = this.configurationService.getConfiguration().getString(TWILIO_REPLY);
Body smsBody = new Body.Builder(messageBody).build();
Message message = new Message.Builder().body(smsBody).build();
// Create a TwiML response and add our message.
MessagingResponse twiml = new MessagingResponse.Builder().message(message).build();
response.setContentType("application/xml");
try {
response.getWriter().print(twiml.toXml());
} catch (TwiMLException e) {
LOG.error("Exception Occured while twiml Email :",e);
}
}