Skip to content
Twilio C#/.NET Helper Library for .NET Framework 3.5+ and supported .NET Core versions
C#
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src/Twilio Release 5.37.3 Jan 22, 2020
test/Twilio.Test [Librarian] Regenerated @ d279b32f822f241b774d58939b2c4c04ca4152e9 Jan 22, 2020
.gitattributes Instruct git to leave the line endings alone May 12, 2015
.gitignore Updated Twilio.Types.Client implementation of IEndpoint to function a… May 21, 2019
.travis.yml Switch travis to xenial with dotnet 2.1 May 15, 2019
CHANGES.md [Librarian] Regenerated @ d279b32f822f241b774d58939b2c4c04ca4152e9 Jan 22, 2020
CODE_OF_CONDUCT.md
CONTRIBUTING.md
Dockerfile Add Dockerfile and related changes to build the Docker image (#427) Jul 5, 2018
Doxyfile Revert "Add Google Tag Manager to generated docs (will add google ana… Mar 26, 2019
ISSUE_TEMPLATE.md docs: baseline all the templated markdown docs (#510) Jan 17, 2020
LICENSE.md docs: baseline all the templated markdown docs (#510) Jan 17, 2020
Makefile Updates target to netstandard 2.0 (#450) Oct 25, 2018
PULL_REQUEST_TEMPLATE.md docs: baseline all the templated markdown docs (#510) Jan 17, 2020
README.md docs: add supported language versions to README (#506) Nov 26, 2019
Twilio.sln Updates target to netstandard 2.0 (#450) Oct 25, 2018
UPGRADE.md Revert "Revert "Document Sync breaking change in 5.9.x (#398)"" (#400) Nov 17, 2017
VERSIONS.md [Librarian] Regenerated @ 36666be96315587760af943d4fe939d892f128d7 Sep 18, 2019
appveyor.yml Update appveyor.yml Nov 13, 2019
build.ps1 Updates target to netstandard 2.0 (#450) Oct 25, 2018

README.md

twilio-csharp

Build status NuGet Learn with TwilioQuest

Twilio REST API and TwiML Libraries for .NET

Twilio provides a simple 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.

Migrating 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 written in C#, VB.Net, and F# that utilize .NET Framework 3.5 or above or any supported version of .NET Core (.NET Standard v1.4).

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);

Generating 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>
*/

Docker Image

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

Getting help

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!

You can’t perform that action at this time.