配置了一个调用以下代码的 webhook URL :::
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:是否String fromNumber = request.getParameter("From");
给我发件人号码。
Q2:我也收到The constructor Body(String) is undefined"
编译错误。
Q3:我正在使用传统的 Hybris 方式将 SMS 作为邮件转发(使用 emailService),我们有 twilio 方式吗?
用代码更新
{ 请看看我正在使用的方法。使用 Spring,注解。
@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);
}
}