I really don't like any documentation I found related to the web API, so I wanted to answer this question, although it is a bit outdated.
Twilio issues an HTTP request (you can select a GET or POST verb on the Twilio website) to the endpoint that you create, and your HTTP response, if the body is formed correctly, will give an SMS response to the user. Here is a screenshot of the Twilio configuration below.
Usually I only return json from my endpoints, but for Twilio you have to return XML. Configure your routing to have routing with the extension (this allows you to configure the URL that will return the XML for the Twilio request). This is necessary because Twilio does not publish the text / xml in the Accept header. They actually have an Accept header, but it contains * / *, but will work with anything but XML:
config.Routes.MapHttpRoute( name: "DefaultApiWithExtension", routeTemplate: "xml/{controller}/{id}", defaults: new { id = RouteParameter.Optional, ext="xml" } ); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "{controller}/{id}", defaults: new { id = RouteParameter.Optional} ); config.Formatters.XmlFormatter.AddUriPathExtensionMapping("xml", "application/xml"); config.Formatters.JsonFormatter.AddUriPathExtensionMapping("json", "application/json");
Now install the TwiML nuget package using the package manager console. This will only be used for the TwilioResponse class.
Install-Package Twilio.TwiML
Add this class if you want, not required, but if you just want to put the parameters in the controller action method.
public class TwilioRequest { public string MessageSid { get; set; } public string AccountSid { get; set; } public string From { get; set; } public string To { get; set; } public string Body { get; set; } }
And then the action of your controller looks something like this:
public virtual HttpResponseMessage Get([FromUri]TwilioRequest request) { TwilioResponse tr = new TwilioResponse(); if (request.Body == "Hello World") tr.Message("Hello back!"); else tr.Message("Text 'Hello World' for a friendly message."); return Request.CreateResponse(HttpStatusCode.OK, tr.Element); }
or this if you do not want to use the TwilioRequest class that I did:
public virtual HttpResponseMessage Get(string body) { TwilioResponse tr = new TwilioResponse(); if (body == "Hello World") tr.Message("Hello back!"); else tr.Message("Text 'Hello World' for a friendly message."); return Request.CreateResponse(HttpStatusCode.OK, tr.Element); }
Finally, to test it, you will need to configure Twilio to execute the GET request to the endpoint. This is what looked like their site at the time of publication:

Note that the configuration URL has the pattern / xml / controllername. You can check this in your browser, postman or violinist before striking Twilio. The reaction body should look something like this if it works correctly:
<response> <message>Hello Back!</message> </response>
Concluding remarks:
Technically, you donβt even need a TwiML library, because it provides only a wrapper class that is serialized in XML, and you can write your own in a couple of minutes. It was also useful for me to open a port on the firewall that sent HTTP requests from Twilio directly to my machine so that I could debug Twilio.