我想用简单的文字回复twilio短信,同时将短信转发给某些emailId

时间:2018-05-15 14:12:53

标签: twilio twilio-api twiml twilio-functions twilio-twiml

配置了一个调用以下代码的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"编译错误。

第三季:我使用传统的Hybris方式将短信作为邮件转发(使用emailService),我们有两种方式吗?

使用代码更新

{请看看我正在使用的方法。使用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);  
    }
} 

1 个答案:

答案 0 :(得分:2)

Twilio开发者传道者在这里。

A1:From参数是Twilio为发送消息的号码发送的参数。是的,request.getParameter("From")应该是那个数字。

A2:Body也已构建,如this example in the documentation

Body body = new Body.Builder("Store Location: 123 Easy St.").build();
Message message = new Message.Builder().body(body).build();

A3:Twilio对您如何在自己的服务器上发送电子邮件没有任何意见。如果这对你有用,那就去吧!