TwiML App - Invoke AWS Lambda when user replies ST

2019-03-01 03:16发布

问题:

Here is my scenario: I am using Twilio to send SMSes to my clients. When user decides not to receive these SMSes they reply STOP and START to receive again. This is automatically handled by Twilio. But, i need to invoke a AWS Lambda function and update my database accordingly.

This is what i am doing till now: 1. I have created a TwiML App 2. I have added this TwilML App to my Twilio number. 3. Created a Lambda Function and API Gateway. Added the end-point in TwiML App.

Adding AWS Lambda - API Gateway to TwiML App

Adding TwiML App to my Twilio Phone Number

I am getting the SMS Logs saying that the user has sent START/STOP from his phone number, but, the Lambda function is not getting invoked.

Here is the SMS Log from Twilio:

Can someone help me understand what's going wrong? And what it means when the response is "Unsupported media type"?

回答1:

If you're using Java code for your TwiML app, have you specified the XML content type for TwiML as such:

    response.setContentType("application/xml");
    response.getWriter().print(twiml.toXML());

That could be one of a handful of causes as explained in the link from the comments.