Search code examples
c#asp.net-mvctwiliotwilio-api

How to handle my sms statuscallback in twilio using .net mvc?


this is my api url call from my application:

statusCallback: new Uri("http://xx.xx.xx.xx:xx/api/SMSAPI"/>

this is what i tried in my API:

    [HttpPost]
    public void Post([FromBody]string value)
    {
        string MessageStatus="From Body: " + value;
        //return statusText;
        printLog(MessageStatus);

    }

where printLog() writes data in log file. but the problem is it prints only "From Body:" so how to get all values from twilio

Also it gives error 500 in twilio console... image


Solution

  • Twilio evangelist here.

    Twilio passes parameters as form encoded values, so you can specify the names of those individual parameters as your method parameters to let ASP.NET automatically map them:

    public void Post([FromBody]string To, [FromBody]string From, [FromBody]string Body)
    

    Or you can use the twilio-aspnet Nuget package to map them all into a single strongly typed object:

    public void Post(SmsRequest request)