Twilio 7.7.0

twilio-csharp

Test Quality Gate Status NuGet Learn with TwilioQuest

Twilio REST API and TwiML Libraries for .NET

Twilio provides a HTTP-based API for sending and receiving phone calls and text messages. Learn more on twilio.com.

More documentation for this library can be found here.

Versions

twilio-csharp uses a modified version of Semantic Versioning for all changes. See this document for details.

Migrate from earlier versions

See the migration guide here. Also, if you were using the Twilio.Mvc package, that has been replaced by the Twilio.AspNet.Mvc package which is compatible with this version of the library.

TLS 1.2 Requirements

New accounts and subaccounts are now required to use TLS 1.2 when accessing the REST API. "Upgrade Required" errors indicate that TLS 1.0/1.1 is being used. With .NET, you can enable TLS 1.2 using this setting:

System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

Supported .NET versions

This library supports .NET applications that utilize .NET6+.

Installation

The best and easiest way to add the Twilio libraries to your .NET project is to use the NuGet package manager.

With Visual Studio IDE

From within Visual Studio, you can use the NuGet GUI to search for and install the Twilio NuGet package. Or, as a shortcut, simply type the following command into the Package Manager Console:

Install-Package Twilio

With .NET Core Command Line Tools

If you are building with the .NET Core command line tools, then you can run the following command from within your project directory:

dotnet add package Twilio

Sample usage

The examples below show how to have your application initiate and outbound phone call and send an SMS message using the Twilio .NET helper library:

TwilioClient.Init("ACCOUNT_SID", "AUTH_TOKEN");

var call = CallResource.Create(
    new PhoneNumber("+11234567890"),
    from: new PhoneNumber("+10987654321"),
    url: new Uri("https://my.twiml.here")
);
Console.WriteLine(call.Sid);

var message = MessageResource.Create(
    new PhoneNumber("+11234567890"),
    from: new PhoneNumber("+10987654321"),
    body: "Hello World!"
);
Console.WriteLine(message.Sid);

OAuth Feature for Twilio APIs

We are introducing Client Credentials Flow-based OAuth 2.0 authentication. This feature is currently in beta and its implementation is subject to change.

API examples here

Organisation API examples here

Specify Region and/or Edge

To take advantage of Twilio's Global Infrastructure, specify the target Region and/or Edge for the client:

TwilioClient.SetRegion("au1");
TwilioClient.SetEdge("sydney");

This will result in the hostname transforming from api.twilio.com to api.sydney.au1.twilio.com. Use appropriate client depending on the type of authentication used

Enable debug logging

There are two ways to enable debug logging in the default HTTP client. You can create an environment variable called TWILIO_LOG_LEVEL and set it to debug or you can set the LogLevel variable on the client as debug:

TwilioClient.SetLogLevel("debug");

Handle exceptions

For an example on how to handle exceptions in this helper library, please see the Twilio documentation.

Generate TwiML

To control phone calls, your application needs to output TwiML.

// TwiML classes can be created as standalone elements
var gather = new Gather(numDigits: 1, action: new Uri("hello-monkey-handle-key.cshtml"), method: HttpMethod.Post)
    .Say("To speak to a real monkey, press 1. Press 2 to record your own monkey howl. Press any other key to start over.");

// Attributes can be set directly on the object
gather.Timeout = 100;
gather.MaxSpeechTime = 200

// Arbitrary attributes can be set by calling set/getOption
var dial = new Dial().SetOption("myAttribute", 200)
                     .SetOption("newAttribute", false);

// Or can be created and attached to a response directly using helper methods
var response = new VoiceResponse()
    .Say("Hello Monkey")
    .Play(new Uri("http://demo.twilio.com/hellomonkey/monkey.mp3"))
    .Append(gather)
    .Append(dial);

// Serialize the TwiML objects to XML string
Console.WriteLine(response);

/*
<?xml version="1.0" encoding="utf-8"?>
<Response>
  <Say>Hello Monkey</Say>
  <Play>http://demo.twilio.com/hellomonkey/monkey.mp3</Play>
  <Gather numDigits="1" action="hello-monkey-handle-key.cshtml" method="POST" timeout="100" maxSpeechTime="200">
    <Say>To speak to a real monkey, press 1. Press 2 to record your own monkey howl. Press any other key to start over.</Say>
  </Gather>
  <Dial myAttribute="200" newAttribute="false"></Dial>
</Response>
*/

Use a custom HTTP Client

To use a custom HTTP client with this helper library, please see the advanced example of how to do so.

Annotations

Beta

Features marked with the [Beta] attribute are in a beta stage and may undergo changes in future releases. Use these features with caution as they may not be stable.

Deprecated

Features marked with the [Deprecated] attribute are deprecated and are not encouraged to use

Preview

Features marked with the [Preview] attribute are in a preview stage and are intended for evaluation purposes. They are subject to change and should not be used in production without thorough testing.

Docker Image

The Dockerfile present in this repository and its respective twilio/twilio-csharp Docker image are used by Twilio for testing purposes.

You could use the docker image for building and running tests:

docker build -t twiliobuild .

Bash:

docker run -it --rm -v $(pwd):/twilio twiliobuild
make test

Powershell:

docker run -it --rm -v ${PWD}:/twilio twiliobuild
make test

Get support

If you need help installing or using the library, please check the Twilio Support Help Center first, and file a support ticket if you don't find an answer to your question.

If you've instead found a bug in the library or would like new features added, go ahead and open issues or pull requests against this repo!

Showing the top 20 packages that depend on Twilio.

Packages Downloads
Aiursoft.Pylon
The base class, interfaces and services for Aiursoft web apps.
7
Aiursoft.Pylon
The base class, interfaces and services for Aiursoft web apps.
5
Aiursoft.Pylon
The base class, interfaces and services for Aiursoft web apps.
4
Aiursoft.Pylon
The base class, interfaces and services for Aiursoft web apps.
3

Version Downloads Last updated
7.7.0 7 11/16/2024
7.6.0 11 11/02/2024
7.5.1 3 10/29/2024
7.5.0 5 10/27/2024
7.4.0 3 10/29/2024
7.3.1 4 09/26/2024
7.3.0 4 09/24/2024
7.2.3 4 08/27/2024
7.2.2 12 07/04/2024
7.2.1 5 07/04/2024
7.2.0 10 06/19/2024
7.1.1 14 06/07/2024
7.1.0 21 05/25/2024
7.0.5 33 04/22/2024
7.0.4 5 04/13/2024
7.0.3 7 04/13/2024
7.0.2 5 04/26/2024
7.0.1 5 04/26/2024
7.0.0 5 04/26/2024
7.0.0-rc.4 4 04/26/2024
7.0.0-rc.3 6 04/26/2024
7.0.0-rc.2 5 04/26/2024
7.0.0-rc.1 5 04/26/2024
6.18.0 122 03/25/2024
6.16.1 4 04/26/2024
6.15.2 5 04/26/2024
6.15.1 4 04/26/2024
6.15.0 6 04/26/2024
6.14.1 7 04/26/2024
6.14.0 6 04/26/2024
6.13.0 5 04/26/2024
6.11.0 6 04/26/2024
6.10.1 6 04/26/2024
6.10.0 6 04/26/2024
6.9.0 5 04/26/2024
6.8.0 5 04/26/2024
6.7.0 5 04/07/2024
6.6.1 6 04/26/2024
6.6.0 7 04/26/2024
6.5.0 6 04/08/2024
6.4.0 4 04/26/2024
6.3.0 4 04/26/2024
6.2.5 5 04/26/2024
6.2.4 5 04/26/2024
6.2.3 7 04/26/2024
6.2.2 4 04/26/2024
6.2.1 4 04/26/2024
6.2.0 5 04/26/2024
6.1.0 5 04/26/2024
6.0.1 6 04/26/2024
6.0.0 4 09/11/2024
6.0.0-rc.3 5 04/26/2024
6.0.0-rc.2 5 04/26/2024
6.0.0-rc.1 5 04/26/2024
5.81.2 6 04/26/2024
5.81.1 5 04/26/2024
5.81.0 4 04/26/2024
5.80.1 5 04/06/2024
5.80.0 6 04/26/2024
5.79.0 4 04/26/2024
5.78.1 5 04/26/2024
5.78.0 6 04/26/2024
5.77.0 4 04/26/2024
5.76.0 5 04/26/2024
5.75.3 5 04/26/2024
5.75.2 6 04/26/2024
5.75.1 6 04/26/2024
5.75.0 7 04/26/2024
5.74.0 5 04/26/2024
5.73.0 5 04/26/2024
5.72.1 6 04/26/2024
5.72.0 5 04/26/2024
5.71.0 6 04/26/2024
5.70.1 5 04/26/2024
5.70.0 7 04/02/2024
5.69.0 7 04/26/2024
5.68.2 5 04/26/2024
5.68.1 6 04/26/2024
5.68.0 6 04/26/2024
5.67.0 5 03/26/2024
5.66.0 6 04/26/2024
5.65.3 6 04/26/2024
5.65.2 6 04/26/2024
5.65.0 4 04/26/2024
5.64.1 5 04/26/2024
5.64.0 6 04/21/2024
5.63.0 6 04/26/2024
5.62.0 6 04/26/2024
5.61.1 5 04/26/2024
5.61.0 4 04/26/2024
5.60.0 6 04/26/2024
5.59.0 6 04/26/2024
5.58.0 6 04/26/2024
5.57.0 6 04/26/2024
5.56.0 7 04/26/2024
5.55.0 5 04/26/2024
5.54.0 5 04/26/2024
5.53.1 5 04/26/2024
5.53.0 7 04/26/2024
5.52.1 6 04/26/2024
5.52.0 5 04/26/2024
5.51.0 5 04/26/2024
5.50.0 8 04/26/2024
5.49.0 4 04/26/2024
5.48.0 5 04/26/2024
5.47.2 4 04/26/2024
5.47.1 6 04/26/2024
5.47.0 6 04/26/2024
5.46.2 3 04/26/2024
5.46.1 6 04/26/2024
5.46.0 5 04/26/2024
5.45.2 5 04/26/2024
5.45.1 5 04/26/2024
5.45.0 5 04/26/2024
5.44.0 5 04/26/2024
5.43.0 6 04/26/2024
5.42.0 5 04/26/2024
5.41.1 7 04/26/2024
5.41.0 4 04/26/2024
5.40.0 4 04/26/2024
5.39.1 5 04/26/2024
5.39.0 5 04/26/2024
5.38.0 5 04/26/2024
5.37.6 5 04/26/2024
5.37.5 5 04/26/2024
5.37.4 5 04/18/2024
5.37.3 5 04/26/2024
5.37.2 4 05/27/2024
5.37.1 4 04/26/2024
5.37.0 5 04/26/2024
5.36.0 6 04/26/2024
5.35.1 6 04/26/2024
5.35.0 5 04/26/2024
5.34.0 6 04/26/2024
5.33.1 5 04/26/2024
5.33.0 6 04/26/2024
5.32.0 7 04/26/2024
5.31.4 5 04/07/2024
5.31.3 5 04/26/2024
5.31.2 5 04/26/2024
5.31.1 6 04/26/2024
5.31.0 5 04/26/2024
5.30.0 5 04/26/2024
5.29.1 4 04/26/2024
5.29.0 4 04/26/2024
5.28.4 5 04/26/2024
5.28.3 5 04/26/2024
5.28.2 5 04/26/2024
5.28.1 5 04/26/2024
5.28.0 6 04/26/2024
5.27.2 6 04/26/2024
5.27.1 5 04/26/2024
5.27.0 5 04/26/2024
5.26.1 7 04/26/2024
5.26.0 5 04/26/2024
5.25.1 4 04/26/2024
5.25.0 6 04/08/2024
5.24.1 6 04/26/2024
5.24.0 6 04/26/2024
5.23.0 5 04/26/2024
5.22.0 5 04/26/2024
5.21.0 5 04/26/2024
5.20.1 5 04/26/2024
5.20.0 5 04/26/2024
5.19.0 5 04/26/2024
5.18.0 4 05/27/2024
5.17.0 6 04/26/2024
5.16.4 5 04/26/2024
5.16.3 6 04/26/2024
5.16.2 6 04/26/2024
5.16.0 5 04/26/2024
5.15.1 6 03/27/2024
5.15.0 5 04/26/2024
5.14.1 5 04/26/2024
5.14.0 5 04/26/2024
5.13.8 6 04/26/2024
5.13.7 6 04/26/2024
5.13.6 5 04/08/2024
5.13.5 9 04/26/2024
5.13.4 4 04/26/2024
5.13.3 5 04/26/2024
5.13.2 6 04/26/2024
5.13.1 6 04/26/2024
5.13.0 4 04/26/2024
5.12.1 7 04/26/2024
5.12.0 5 04/26/2024
5.11.1 5 04/26/2024
5.11.0 7 04/26/2024
5.10.0 5 04/26/2024
5.9.8 6 04/26/2024
5.9.7 4 04/26/2024
5.9.6 7 04/04/2024
5.9.5 6 04/26/2024
5.9.4 4 04/26/2024
5.9.3 5 04/26/2024
5.9.2 6 04/26/2024
5.9.1 6 04/26/2024
5.9.0 5 04/26/2024
5.8.3 6 04/26/2024
5.8.2 7 04/26/2024
5.8.1 6 04/07/2024
5.8.0 6 04/26/2024
5.7.2 5 04/26/2024
5.7.1 6 04/26/2024
5.7.0 5 04/26/2024
5.6.5 5 04/26/2024
5.6.4 6 04/26/2024
5.6.3 5 04/26/2024
5.6.2 5 04/26/2024
5.6.1 6 04/26/2024
5.6.0 5 04/15/2024
5.5.3-alpha2 7 03/31/2024
5.5.3-alpha1 6 04/26/2024
5.5.2 5 04/26/2024
5.5.2-alpha1 6 04/26/2024
5.5.1 6 04/26/2024
5.5.1-alpha1 5 04/26/2024
5.5.0 4 04/26/2024
5.4.3-alpha1 5 04/26/2024
5.4.2 5 04/26/2024
5.4.2-alpha1 5 04/26/2024
5.4.1 6 03/29/2024
5.4.1-alpha1 5 04/26/2024
5.4.0 5 04/26/2024
5.4.0-alpha1 6 04/26/2024
5.3.1-alpha1 5 04/26/2024
5.3.0 8 04/26/2024
5.2.2-alpha1 6 04/26/2024
5.2.1 6 04/06/2024
5.2.1-alpha1 5 04/26/2024
5.2.0 5 04/26/2024
5.1.2-alpha1 5 04/26/2024
5.1.1 6 04/26/2024
5.1.1-alpha1 5 04/26/2024
5.1.0 6 04/26/2024
5.0.3-alpha1 7 04/26/2024
5.0.2 6 03/27/2024
5.0.2-alpha1 6 04/05/2024
5.0.1 5 04/26/2024
5.0.1-alpha1 5 04/26/2024
5.0.0 7 04/26/2024
5.0.0-rca4 5 04/26/2024
5.0.0-rca3 5 04/26/2024
5.0.0-rca2 7 04/26/2024
5.0.0-rca1 4 04/26/2024
5.0.0-rc9 4 04/26/2024
5.0.0-rc8 6 04/26/2024
5.0.0-rc7 4 04/26/2024
5.0.0-rc6 4 04/26/2024
5.0.0-rc4 5 04/26/2024
5.0.0-rc2 5 04/26/2024
5.0.0-rc10 6 04/26/2024
5.0.0-rc1 6 04/26/2024
5.0.0-alpha1 6 04/26/2024
4.7.2 6 04/26/2024
4.7.1 6 04/26/2024
4.7.0 4 04/26/2024
4.5.0 6 04/26/2024
4.4.1 7 04/26/2024
4.4.0 6 04/22/2024
4.4.0-edge 6 04/26/2024
4.3.0 3 04/26/2024
4.2.1 5 04/26/2024
4.2.0 6 04/26/2024
4.1.0 4 04/26/2024
4.0.51 5 04/26/2024
4.0.5 5 04/26/2024
4.0.4 6 04/26/2024
4.0.3 5 04/26/2024
4.0.2 5 04/26/2024
4.0.1 5 04/26/2024
4.0.0 5 04/26/2024
3.8.45-beta 0 03/19/2015
3.8.44-beta 0 03/19/2015
3.8.40-beta 0 03/06/2015
3.8.30-beta 0 03/05/2015
3.8.29-beta 0 03/05/2015
3.8.28-beta 0 03/05/2015
3.8.26-beta 0 03/05/2015
3.8.18-beta 0 12/19/2014
3.7.55-alpha 0 06/04/2014
3.7.54-alpha 0 06/04/2014
3.7.53-alpha 0 06/04/2014
3.7.51-alpha 0 06/04/2014
3.7.50-alpha 0 06/04/2014
3.7.48-alpha 0 06/04/2014
3.7.46-alpha 0 06/04/2014
3.7.45-alpha 0 06/04/2014
3.7.44-alpha 0 06/04/2014
3.7.43-alpha 0 05/31/2014
3.7.40-alpha 0 05/31/2014
3.7.39-alpha 0 05/31/2014
3.7.38-alpha 0 05/31/2014
3.7.37-alpha 0 05/30/2014
3.7.35-alpha 5 04/26/2024
3.6.29 5 04/26/2024
3.6.28 5 04/26/2024
3.6.27 6 04/26/2024
3.6.26 4 04/26/2024
3.6.25 5 04/26/2024
3.6.24 6 04/26/2024
3.6.23 0 11/05/2014
3.6.22 0 11/05/2014
3.6.20 0 10/10/2014
3.6.19 0 10/10/2014
3.6.18 0 09/29/2014
3.6.17 0 08/28/2014
3.6.16 0 05/29/2014
3.6.15 0 05/27/2014
3.6.11 0 01/25/2014
3.6.10 0 11/20/2013
3.6.9 0 11/04/2013
3.6.8 0 11/04/2013
3.6.7 0 11/04/2013
3.6.6 0 11/04/2013
3.6.5 0 10/21/2013
3.6.4 0 10/07/2013
3.6.3 0 10/03/2013
3.6.2 0 09/30/2013
3.6.1 0 09/18/2013
3.5.17 0 07/31/2013
3.5.16 0 07/20/2013
3.5.15 0 07/13/2013
3.5.14 0 06/19/2013
3.5.12 0 04/10/2013
3.5.11 0 04/09/2013
3.5.10 0 04/05/2013
3.5.9 0 04/04/2013
3.5.8 0 03/18/2013
3.5.6 0 12/17/2012
3.5.5 0 10/25/2012
3.5.4 0 10/24/2012
3.5.3 0 10/17/2012
3.5.2 0 10/17/2012
3.5.1 0 08/31/2012
3.5.0 0 08/20/2012
3.4.5 0 07/12/2012
3.4.4 0 07/12/2012
3.4.3 0 07/09/2012
3.4.2 0 04/18/2012
3.4.1 0 04/18/2012
3.4.0 0 03/21/2012
3.3.7 0 02/15/2012
3.3.6 0 02/15/2012
3.3.5 0 02/15/2012
3.3.4 0 02/07/2012
3.3.3 0 02/06/2012
3.3.2 0 11/18/2011
3.3.1 0 11/18/2011
3.2.3 0 10/19/2011
3.2.2 0 10/11/2011
3.2.1 0 09/28/2011
3.2.0 0 09/21/2011
3.1.4 0 08/26/2011
3.1.3 0 08/09/2011
3.1.0 0 07/26/2011
3.0.1 0 07/20/2011
3.0.0 0 07/17/2011
2.0.2 0 01/31/2011