Track Delivery Status of Messages in C#

In this guide, we'll show you how to track the delivery status of messages you send with Programmable SMS in your ASP.NET web application. Twilio can notify you about the status of your SMS and MMS messages via a webhook and you can notify Twilio about messages you have confirmed to be delivered.

The code snippets in this guide are written using modern C# language features and require the .NET Framework version 4.5 or higher. They also make use of the Twilio C# SDK.

What is a Webhook?

Webhooks are user-defined HTTP callbacks. They are usually triggered by some event, such as receiving an SMS message or an incoming phone call. When that event occurs, Twilio makes an HTTP request (usually a POST or a GET) to the URL configured for the webhook.

To handle a webhook, you only need to build a small web application that can accept the HTTP requests. Almost all server-side programming languages offer some framework for you to do this. Examples across languages include ASP.NET MVC for C#, Servlets and Spark for Java, Express for Node.js, Django and Flask for Python, and Rails and Sinatra for Ruby. PHP has its own web app framework built in, although frameworks like Laravel, Symfony and Yii are also popular.

Whichever framework and language you choose, webhooks function the same for every Twilio application. They will make an HTTP request to a URI that you provide to Twilio. Your application performs whatever logic you feel necessary - read/write from a database, integrate with another API or perform some computation - then replies to Twilio with a TwiML response with the instructions you want Twilio to perform.

Receive Status Events in your Web Application

Statuses for which you can receive notifications include: queuedfailedsentdelivered, and undelivered. For a full description of these and other message statuses, see the API reference.

To get Twilio to call your webhook, you need to provide a URL to your application in the StatusCallback parameter of each message for which you want the status callbacks. Below is an example of how you can specify this parameter. Normally, you would use a URL in your application, but let's use RequestBin so we can debug what Twilio sends your webhook.

Loading Code Samples...
Language
SDK Version:
  • 4.x
  • 5.x
Format:
  • JSON
  • XML
// Download the twilio-csharp library from twilio.com/docs/csharp/install
using System;
using Twilio;
class Example
{
 static void Main(string[] args)
 {
    // Find your Account Sid and Auth Token at twilio.com/user/account
    string AccountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
    string AuthToken = "your_auth_token";
    var twilio = new TwilioRestClient(AccountSid, AuthToken);

    var message = twilio.SendMessage(
        "+15017250604", "+15558675309",
        "McAvoy or Stewart? These timelines can get so confusing.",
        "http://requestb.in/1234abcd"
    );
    Console.WriteLine(message.Sid);
 }
}
// Download the twilio-csharp library from twilio.com/docs/libraries/csharp
using System;
using Twilio;
using Twilio.Rest.Api.V2010.Account;
using Twilio.Types;

class Example
{
   static void Main(string[] args)
   {
        // Find your Account Sid and Auth Token at twilio.com/console
        const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        const string authToken = "your_auth_token";
        TwilioClient.Init(accountSid, authToken);

        var to = new PhoneNumber("+15017250604");
        var message = MessageResource.Create(
            to,
            from: new PhoneNumber("+15558675309"),
            body: "McAvoy or Stewart? These timelines can get so confusing.",
            statusCallback: new Uri("http://requestb.in/1234abcd"));

        Console.WriteLine(message.Sid);
   }
}
{
  "sid": "MMc781610ec0b3400c9e0cab8e757da937",
  "date_created": "Mon, 19 Oct 2015 07:07:03 +0000",
  "date_updated": "Mon, 19 Oct 2015 07:07:03 +0000",
  "date_sent": null,
  "account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  "to": "+16518675309",
  "from": "+14158141829",
  "body": "Hey Jenny! Good luck on the bar exam!",
  "status": "queued",
  "num_segments": "1",
  "num_media": "0",
  "direction": "outbound-api",
  "api_version": "2010-04-01",
  "price": null,
  "price_unit": "USD",
  "error_code": null,
  "error_message": null,
  "uri": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages/MMc781610ec0b3400c9e0cab8e757da937.json",
}
<?xml version='1.0' encoding='UTF-8'?>
<TwilioResponse>
<Message>
  <Sid>MMc781610ec0b3400c9e0cab8e757da937</Sid>
  <DateCreated>Mon, 19 Oct 2015 07:09:09 +0000</DateCreated>
  <DateUpdated>Mon, 19 Oct 2015 07:09:09 +0000</DateUpdated>
  <DateSent/>
  <AccountSid>ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</AccountSid>
  <To>+16518675309</To>
  <From>+14158141829</From>
  <Body>Hey Jenny! Good luck on the bar exam!</Body>
  <Status>queued</Status>
  <NumSegments>1</NumSegments>
  <NumMedia>0</NumMedia>
  <Direction>outbound-api</Direction>
  <ApiVersion>2010-04-01</ApiVersion>
  <Price/>
  <PriceUnit>USD</PriceUnit>
  <ErrorCode/>
  <ErrorMessage/>
  <Uri>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages/MMf1150fe5baf04104a39c3f311a053e4e.xml</Uri>
  <SubresourceUris/>
</Message>
</TwilioResponse>
Send an SMS with a StatusCallback URL

To get this code sample to run, first fill in your Account SID and Auth Token (found on the Twilio Console dashboard), replace the 'From' phone number with one of your Twilio numbers, and replace the 'To' number with your mobile number. Then, head over to RequestBin and create a new bin. Replace the StatusCallback parameter in the snippet to the URL of your new bin.

When you run the code, you should receive your text message. In addition, you should see at least one request come in to your RequestBin similar to this:

SMS StatusCallback Result in RequestBin

This request shows the MessageStatus of sent. Assuming all was successful, you should see that followed up by another request with a status of delivered (it may take a few minutes to show up).

Once you get the hang of how the StatusCallback works, you're ready to handle the callback in your own application. Below is an example of how you might do this - it is an example of logging the status for each message.

Loading Code Samples...
Language
SDK Version:
  • 4.x
  • 5.x
// In Package Manager, run:
// Install-Package Twilio.Mvc -DependencyVersion HighestMinor

using System.Diagnostics;
using System.Web.Mvc;
using Twilio.Mvc;
using Twilio.TwiML.Mvc;

public class MessageStatusController : Controller
{
    [HttpPost]
    public ActionResult Index(SmsRequest request)
    {
        // Log the message id and status
        var logMessage = "\"" + request.SmsSid + "\", " +
                         "\"" + request.MessageStatus + "\"";
        Trace.WriteLine(logMessage);
        return Content("Handled");
    }
}
// In Package Manager, run:
// Install-Package Twilio.Mvc -DependencyVersion HighestMinor

using System.Diagnostics;
using System.Web.Mvc;

public class MessageStatusController : Controller
{
    [HttpPost]
    public ActionResult Index()
    {
        // Log the message id and status
        var smsSid = Request.Form["SmsSid"];
        var messageStatus = Request.Form["MessageStatus"];
        var logMessage = $"\"{smsSid}\", \"{messageStatus}\"";

        Trace.WriteLine(logMessage);
        return Content("Handled");
    }
}
Handle a SMS StatusCallback

Getting Status Events for TwiML Generated Messages

When you reply to an incoming message with the <Message> verb, you can also provide an action attribute to specify the URL for your callback webhook. The callback can be the same as those explored in the previous sections.

<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Message action="http://requestb.in/1234abcd">This message will be tracked!</Message>
</Response>

Provide Message Delivery Feedback to Twilio

The Twilio Message Feedback API enables you to programmatically report back to Twilio critical deliverability information. Actions that indicate a message was received are then used by Twilio to identify network issues and improve the deliverability of your messages. For example, a user action could be a person entering their two-factor authentication code or clicking a unique link in a message.

NOTE: You must contact our support team to enable the Message Feedback API on your account. Requests to this endpoint will give a 404 response until you do.

Why do We Want This Feedback?

We already have many sources of data to optimize overall delivery deliverability. We use direct feedback from our carrier partners, deliverability data from some our larger customers as well as various other monitoring techniques. But nothing trumps the live collective data of our customers. For your messages, we trust what you tell us the most.

By looking at both aggregate data and data specific to your account, we have a better chance at improving the delivery of your messages.

How Twilio Message Feedback Works

Submitting Message Feedback to Twilio is a three step process:

  1. When you send a message, let Twilio know that you are expecting a trackable user action by including the new ProvideFeedback=true parameter in the initial HTTP POST.
  2. Save the Message SID from the POST response. You’ll need this later.
  3. When the user takes the expected action, such as entering a PIN code, let Twilio know the message was received by sending a POST request to the Message Feedback instance subresource with Outcome=confirmed parameter. If the user does not take an action, do not POST anything.

Let's look at some code.

First, here's some code that sends a message with a unique URL, setting the ProvideFeedback parameter to true and also saving the Message SID for later recall.

Loading Code Samples...
Language
SDK Version:
  • 4.x
  • 5.x
Format:
  • JSON
  • XML
// Download the twilio-csharp library from twilio.com/docs/csharp/install
using System;
using Newtonsoft.Json;
using RestSharp;
using Twilio;

class Example
{
    static void Main(string[] args)
    {
        // Find your Account Sid and Auth Token at twilio.com/console
        string AccountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        string AuthToken = "your_auth_token";
        var twilio = new TwilioRestClient(AccountSid, AuthToken);

        // Generate a random, unique code
        var uniqueCode = "1234567890";
        
        // Normally, we would call twilio.SendMessage() to send an SMS
        // But it doesn't support passing the ProvideFeedback parameter.
        var request = new RestRequest("Accounts/" + AccountSid + "/Messages.json", Method.POST);
        request.AddParameter("From", "+15017250604");
        request.AddParameter("To", "+15558675309");
        request.AddParameter("Body", "Open to confirm: http://yourserver.com/confirm?id=" + uniqueCode);
        request.AddParameter("ProvideFeedback", true);
        var response = twilio.Execute(request);

        var message = JsonConvert.DeserializeObject<Message>(response.Content, 
            new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore });

        Console.WriteLine("We should save this to a database:");
        Console.WriteLine("Unique Code = " + uniqueCode);
        Console.WriteLine("Message SID = " + message.Sid);
    }
}
// Download the twilio-csharp library from twilio.com/docs/libraries/csharp
using System;
using Twilio;
using Twilio.Rest.Api.V2010.Account;
using Twilio.Types;

class Example
{
    static void Main(string[] args)
    {
        // Find your Account Sid and Auth Token at twilio.com/console
        const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        const string authToken = "your_auth_token";
        TwilioClient.Init(accountSid, authToken);

        // Generate a random, unique code
        const string uniqueCode = "1234567890";
        var to = new PhoneNumber("+15558675309");
        var message = MessageResource.Create(
            to,
            from: new PhoneNumber("+15017250604"),
            body: $"Open to confirm: http://yourserver.com/confirm?id={uniqueCode}",
            provideFeedback: true);

        Console.WriteLine("We should save this to a database:");
        Console.WriteLine("Unique Code = " + uniqueCode);
        Console.WriteLine("Message SID = " + message.Sid);
    }
}
{
  "sid": "MMc781610ec0b3400c9e0cab8e757da937",
  "date_created": "Mon, 19 Oct 2015 07:07:03 +0000",
  "date_updated": "Mon, 19 Oct 2015 07:07:03 +0000",
  "date_sent": null,
  "account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  "to": "+15558675309",
  "from": "+15017250604",
  "body": "Open to confirm: http://yourserver.com/confirm?id=1234567890",
  "status": "queued",
  "num_segments": "1",
  "num_media": "0",
  "direction": "outbound-api",
  "api_version": "2010-04-01",
  "price": null,
  "price_unit": "USD",
  "error_code": null,
  "error_message": null,
  "uri": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages/MMc781610ec0b3400c9e0cab8e757da937.json",
}
<?xml version='1.0' encoding='UTF-8'?>
<TwilioResponse>
<Message>
  <Sid>MMc781610ec0b3400c9e0cab8e757da937</Sid>
  <DateCreated>Mon, 19 Oct 2015 07:09:09 +0000</DateCreated>
  <DateUpdated>Mon, 19 Oct 2015 07:09:09 +0000</DateUpdated>
  <DateSent/>
  <AccountSid>ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</AccountSid>
  <To>+15558675309</To>
  <From>+15017250604</From>
  <Body>Open to confirm: http://yourserver.com/confirm?id=1234567890</Body>
  <Status>queued</Status>
  <NumSegments>1</NumSegments>
  <NumMedia>0</NumMedia>
  <Direction>outbound-api</Direction>
  <ApiVersion>2010-04-01</ApiVersion>
  <Price/>
  <PriceUnit>USD</PriceUnit>
  <ErrorCode/>
  <ErrorMessage/>
  <Uri>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages/MMf1150fe5baf04104a39c3f311a053e4e.xml</Uri>
  <SubresourceUris/>
</Message>
</TwilioResponse>
Send an SMS for which to provide Feedback

Next, here's the code we might run when the user clicks the unique URL. Based on the unique URL, we know the Message SID and can report back to Twilio that the message was successfully delivered.

Loading Code Samples...
Language
SDK Version:
  • 4.x
  • 5.x
Format:
  • JSON
  • XML
// Download the twilio-csharp library from twilio.com/docs/csharp/install
using System.Web.Mvc;
using RestSharp;
using Twilio;

public class ConfirmController : Controller
{
    // GET: Confirm
    public ActionResult Index(string id)
    {
        // Lookup variable `id` in a database to find messageSid
        var messageSid = "SMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";

        // Find your Account Sid and Auth Token at twilio.com/console
        string AccountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        string AuthToken = "your_auth_token";
        var twilio = new TwilioRestClient(AccountSid, AuthToken);

        // Send Feedback to Twilio
        var request = new RestRequest("Accounts/" + AccountSid + 
            "/Messages/" + messageSid + "/Feedback.json", Method.POST);
        request.AddParameter("Outcome", "confirmed");
        twilio.Execute(request);

        // Handle remaining request normally
        return View();
    }
}
// Download the twilio-csharp library from twilio.com/docs/libraries/csharp
using System.Web.Mvc;
using Twilio.Rest.Api.V2010.Account.Message;
using Twilio;

public class ConfirmController : Controller
{
    // GET: Confirm
    public ActionResult Index()
    {
        // Lookup variable `id` in a database to find messageSid
        const string messageSid = "SMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";

        // Find your Account Sid and Auth Token at twilio.com/console
        const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        const string authToken = "your_auth_token";
        TwilioClient.Init(accountSid, authToken);

        // Send Feedback to Twilio
        FeedbackResource.Create(messageSid,
                                outcome: FeedbackResource.OutcomeEnum.Confirmed);

        // Handle remaining request normally
        return View();
    }
}
{
	"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
	"message_sid": "SM6d4d807e10f24d83a1ab01da10ccc0f5",
	"outcome": "confirmed",
	"date_created": "Fri, 02 Sep 2016 18:19:59 +0000",
	"date_updated": "Fri, 02 Sep 2016 18:42:40 +0000",
	"uri": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/SMS/Messages/SM6d4d807e10f24d83a1ab01da10ccc0f5/Feedback.json"
}
<?xml version='1.0' encoding='UTF-8'?>
<TwilioResponse>
  <Feedback>
    <AccountSid>ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</AccountSid>
    <MessageSid>SM6d4d807e10f24d83a1ab01da10ccc0f5</MessageSid>
    <Outcome>confirmed</Outcome>
    <DateCreated>Fri, 02 Sep 2016 18:19:59 +0000</DateCreated>
    <DateUpdated>Fri, 02 Sep 2016 18:46:58 +0000</DateUpdated>
    <Uri>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/SMS/Messages/SM6d4d807e10f24d83a1ab01da10ccc0f5/Feedback</Uri>
  </Feedback>
</TwilioResponse>
Send Delivery Confirmation Feedback

Examples of Trackable User Actions 

Examples of user actions include:

  •      A user receives a passcode via SMS and enters it into a web site or app
  •      A user enters a temporary password.
  •      A user replies to a message with a call or SMS.
  •      A user clicks on a unique link contained in the message.

Once a user takes an action, you know for certain that they received the message. This information is submitted to Twilio, and we take care of the rest.

 

David Prothero
Paul Kamp
Ricky Robinett
Andrew Baker

Need some help?

We all do sometimes; code is hard. Get help now from our support team, or lean on the wisdom of the crowd browsing the Twilio tag on Stack Overflow.

1 / 1
Loading Code Samples...
SDK Version:
  • 4.x
  • 5.x
Format:
  • JSON
  • XML
// Download the twilio-csharp library from twilio.com/docs/csharp/install
using System;
using Twilio;
class Example
{
 static void Main(string[] args)
 {
    // Find your Account Sid and Auth Token at twilio.com/user/account
    string AccountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
    string AuthToken = "your_auth_token";
    var twilio = new TwilioRestClient(AccountSid, AuthToken);

    var message = twilio.SendMessage(
        "+15017250604", "+15558675309",
        "McAvoy or Stewart? These timelines can get so confusing.",
        "http://requestb.in/1234abcd"
    );
    Console.WriteLine(message.Sid);
 }
}
// Download the twilio-csharp library from twilio.com/docs/libraries/csharp
using System;
using Twilio;
using Twilio.Rest.Api.V2010.Account;
using Twilio.Types;

class Example
{
   static void Main(string[] args)
   {
        // Find your Account Sid and Auth Token at twilio.com/console
        const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        const string authToken = "your_auth_token";
        TwilioClient.Init(accountSid, authToken);

        var to = new PhoneNumber("+15017250604");
        var message = MessageResource.Create(
            to,
            from: new PhoneNumber("+15558675309"),
            body: "McAvoy or Stewart? These timelines can get so confusing.",
            statusCallback: new Uri("http://requestb.in/1234abcd"));

        Console.WriteLine(message.Sid);
   }
}
{
  "sid": "MMc781610ec0b3400c9e0cab8e757da937",
  "date_created": "Mon, 19 Oct 2015 07:07:03 +0000",
  "date_updated": "Mon, 19 Oct 2015 07:07:03 +0000",
  "date_sent": null,
  "account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  "to": "+16518675309",
  "from": "+14158141829",
  "body": "Hey Jenny! Good luck on the bar exam!",
  "status": "queued",
  "num_segments": "1",
  "num_media": "0",
  "direction": "outbound-api",
  "api_version": "2010-04-01",
  "price": null,
  "price_unit": "USD",
  "error_code": null,
  "error_message": null,
  "uri": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages/MMc781610ec0b3400c9e0cab8e757da937.json",
}
<?xml version='1.0' encoding='UTF-8'?>
<TwilioResponse>
<Message>
  <Sid>MMc781610ec0b3400c9e0cab8e757da937</Sid>
  <DateCreated>Mon, 19 Oct 2015 07:09:09 +0000</DateCreated>
  <DateUpdated>Mon, 19 Oct 2015 07:09:09 +0000</DateUpdated>
  <DateSent/>
  <AccountSid>ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</AccountSid>
  <To>+16518675309</To>
  <From>+14158141829</From>
  <Body>Hey Jenny! Good luck on the bar exam!</Body>
  <Status>queued</Status>
  <NumSegments>1</NumSegments>
  <NumMedia>0</NumMedia>
  <Direction>outbound-api</Direction>
  <ApiVersion>2010-04-01</ApiVersion>
  <Price/>
  <PriceUnit>USD</PriceUnit>
  <ErrorCode/>
  <ErrorMessage/>
  <Uri>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages/MMf1150fe5baf04104a39c3f311a053e4e.xml</Uri>
  <SubresourceUris/>
</Message>
</TwilioResponse>
SDK Version:
  • 4.x
  • 5.x
// In Package Manager, run:
// Install-Package Twilio.Mvc -DependencyVersion HighestMinor

using System.Diagnostics;
using System.Web.Mvc;
using Twilio.Mvc;
using Twilio.TwiML.Mvc;

public class MessageStatusController : Controller
{
    [HttpPost]
    public ActionResult Index(SmsRequest request)
    {
        // Log the message id and status
        var logMessage = "\"" + request.SmsSid + "\", " +
                         "\"" + request.MessageStatus + "\"";
        Trace.WriteLine(logMessage);
        return Content("Handled");
    }
}
// In Package Manager, run:
// Install-Package Twilio.Mvc -DependencyVersion HighestMinor

using System.Diagnostics;
using System.Web.Mvc;

public class MessageStatusController : Controller
{
    [HttpPost]
    public ActionResult Index()
    {
        // Log the message id and status
        var smsSid = Request.Form["SmsSid"];
        var messageStatus = Request.Form["MessageStatus"];
        var logMessage = $"\"{smsSid}\", \"{messageStatus}\"";

        Trace.WriteLine(logMessage);
        return Content("Handled");
    }
}
SDK Version:
  • 4.x
  • 5.x
Format:
  • JSON
  • XML
// Download the twilio-csharp library from twilio.com/docs/csharp/install
using System;
using Newtonsoft.Json;
using RestSharp;
using Twilio;

class Example
{
    static void Main(string[] args)
    {
        // Find your Account Sid and Auth Token at twilio.com/console
        string AccountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        string AuthToken = "your_auth_token";
        var twilio = new TwilioRestClient(AccountSid, AuthToken);

        // Generate a random, unique code
        var uniqueCode = "1234567890";
        
        // Normally, we would call twilio.SendMessage() to send an SMS
        // But it doesn't support passing the ProvideFeedback parameter.
        var request = new RestRequest("Accounts/" + AccountSid + "/Messages.json", Method.POST);
        request.AddParameter("From", "+15017250604");
        request.AddParameter("To", "+15558675309");
        request.AddParameter("Body", "Open to confirm: http://yourserver.com/confirm?id=" + uniqueCode);
        request.AddParameter("ProvideFeedback", true);
        var response = twilio.Execute(request);

        var message = JsonConvert.DeserializeObject<Message>(response.Content, 
            new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore });

        Console.WriteLine("We should save this to a database:");
        Console.WriteLine("Unique Code = " + uniqueCode);
        Console.WriteLine("Message SID = " + message.Sid);
    }
}
// Download the twilio-csharp library from twilio.com/docs/libraries/csharp
using System;
using Twilio;
using Twilio.Rest.Api.V2010.Account;
using Twilio.Types;

class Example
{
    static void Main(string[] args)
    {
        // Find your Account Sid and Auth Token at twilio.com/console
        const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        const string authToken = "your_auth_token";
        TwilioClient.Init(accountSid, authToken);

        // Generate a random, unique code
        const string uniqueCode = "1234567890";
        var to = new PhoneNumber("+15558675309");
        var message = MessageResource.Create(
            to,
            from: new PhoneNumber("+15017250604"),
            body: $"Open to confirm: http://yourserver.com/confirm?id={uniqueCode}",
            provideFeedback: true);

        Console.WriteLine("We should save this to a database:");
        Console.WriteLine("Unique Code = " + uniqueCode);
        Console.WriteLine("Message SID = " + message.Sid);
    }
}
{
  "sid": "MMc781610ec0b3400c9e0cab8e757da937",
  "date_created": "Mon, 19 Oct 2015 07:07:03 +0000",
  "date_updated": "Mon, 19 Oct 2015 07:07:03 +0000",
  "date_sent": null,
  "account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  "to": "+15558675309",
  "from": "+15017250604",
  "body": "Open to confirm: http://yourserver.com/confirm?id=1234567890",
  "status": "queued",
  "num_segments": "1",
  "num_media": "0",
  "direction": "outbound-api",
  "api_version": "2010-04-01",
  "price": null,
  "price_unit": "USD",
  "error_code": null,
  "error_message": null,
  "uri": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages/MMc781610ec0b3400c9e0cab8e757da937.json",
}
<?xml version='1.0' encoding='UTF-8'?>
<TwilioResponse>
<Message>
  <Sid>MMc781610ec0b3400c9e0cab8e757da937</Sid>
  <DateCreated>Mon, 19 Oct 2015 07:09:09 +0000</DateCreated>
  <DateUpdated>Mon, 19 Oct 2015 07:09:09 +0000</DateUpdated>
  <DateSent/>
  <AccountSid>ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</AccountSid>
  <To>+15558675309</To>
  <From>+15017250604</From>
  <Body>Open to confirm: http://yourserver.com/confirm?id=1234567890</Body>
  <Status>queued</Status>
  <NumSegments>1</NumSegments>
  <NumMedia>0</NumMedia>
  <Direction>outbound-api</Direction>
  <ApiVersion>2010-04-01</ApiVersion>
  <Price/>
  <PriceUnit>USD</PriceUnit>
  <ErrorCode/>
  <ErrorMessage/>
  <Uri>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages/MMf1150fe5baf04104a39c3f311a053e4e.xml</Uri>
  <SubresourceUris/>
</Message>
</TwilioResponse>
SDK Version:
  • 4.x
  • 5.x
Format:
  • JSON
  • XML
// Download the twilio-csharp library from twilio.com/docs/csharp/install
using System.Web.Mvc;
using RestSharp;
using Twilio;

public class ConfirmController : Controller
{
    // GET: Confirm
    public ActionResult Index(string id)
    {
        // Lookup variable `id` in a database to find messageSid
        var messageSid = "SMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";

        // Find your Account Sid and Auth Token at twilio.com/console
        string AccountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        string AuthToken = "your_auth_token";
        var twilio = new TwilioRestClient(AccountSid, AuthToken);

        // Send Feedback to Twilio
        var request = new RestRequest("Accounts/" + AccountSid + 
            "/Messages/" + messageSid + "/Feedback.json", Method.POST);
        request.AddParameter("Outcome", "confirmed");
        twilio.Execute(request);

        // Handle remaining request normally
        return View();
    }
}
// Download the twilio-csharp library from twilio.com/docs/libraries/csharp
using System.Web.Mvc;
using Twilio.Rest.Api.V2010.Account.Message;
using Twilio;

public class ConfirmController : Controller
{
    // GET: Confirm
    public ActionResult Index()
    {
        // Lookup variable `id` in a database to find messageSid
        const string messageSid = "SMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";

        // Find your Account Sid and Auth Token at twilio.com/console
        const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        const string authToken = "your_auth_token";
        TwilioClient.Init(accountSid, authToken);

        // Send Feedback to Twilio
        FeedbackResource.Create(messageSid,
                                outcome: FeedbackResource.OutcomeEnum.Confirmed);

        // Handle remaining request normally
        return View();
    }
}
{
	"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
	"message_sid": "SM6d4d807e10f24d83a1ab01da10ccc0f5",
	"outcome": "confirmed",
	"date_created": "Fri, 02 Sep 2016 18:19:59 +0000",
	"date_updated": "Fri, 02 Sep 2016 18:42:40 +0000",
	"uri": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/SMS/Messages/SM6d4d807e10f24d83a1ab01da10ccc0f5/Feedback.json"
}
<?xml version='1.0' encoding='UTF-8'?>
<TwilioResponse>
  <Feedback>
    <AccountSid>ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</AccountSid>
    <MessageSid>SM6d4d807e10f24d83a1ab01da10ccc0f5</MessageSid>
    <Outcome>confirmed</Outcome>
    <DateCreated>Fri, 02 Sep 2016 18:19:59 +0000</DateCreated>
    <DateUpdated>Fri, 02 Sep 2016 18:46:58 +0000</DateUpdated>
    <Uri>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/SMS/Messages/SM6d4d807e10f24d83a1ab01da10ccc0f5/Feedback</Uri>
  </Feedback>
</TwilioResponse>