Reputation:
I am using Twilio
for sending SMS from my Java Web Application. I have a Twilio number purchased under my account. Now I am trying to process the incoming SMS to my Twilio number. All I am trying to do is to pass the message data and the sender of the message as an HTTP GET method to my application. I have found the following under my account settings:
In my application, I can add a REST service that can accept these details and save the required details to my database. But I am unable to find any example related to this. Is there any way to get the message details whenever a message is received.
Upvotes: 1
Views: 1002
Reputation: 11732
Twilio makes HTTP requests to your application just like a regular web browser. By including parameters and values in its requests, Twilio sends data to your application that you can act upon before responding.
https://www.twilio.com/docs/api/twiml/sms/twilio_request#twilio-data-passing
When Twilio receives a message for one of your Twilio numbers it makes a synchronous HTTP request to the message URL configured for that number, and expects to receive TwiML in response.
Twilio sends parameters with its request as POST parameters or URL query parameters, depending on which HTTP method you've configured. https://www.twilio.com/docs/api/twiml/sms/twilio_request#request-parameters
If you are using Spring MVC annotations, you can add an annotated parameter to your method's parameters:
@RequestMapping(
value = "/someEndPoint",
method = RequestMethod.POST,
consumes = "text/plain"
)
public String someMethod(@RequestParam("param1") String paramOne) {
//use paramOne variable here
}
Upvotes: 1