Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Twilio C#/.NET Helper Library for .NET6+.

License

NotificationsYou must be signed in to change notification settings

twilio/twilio-csharp

Repository files navigation

TestQuality Gate StatusNuGetLearn 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 ontwilio.com.

More documentation for this library can be foundhere.

Versions

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

Migrate from earlier versions

See the migration guidehere. Also, if you were using theTwilio.Mvc package, that has been replaced by theTwilio.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");varcall=CallResource.Create(newPhoneNumber("+11234567890"),from:newPhoneNumber("+10987654321"),url:newUri("https://my.twiml.here"));Console.WriteLine(call.Sid);varmessage=MessageResource.Create(newPhoneNumber("+11234567890"),from:newPhoneNumber("+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 exampleshere

Organisation API exampleshere

Specify Region and/or Edge

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

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

This will result in thehostname transforming fromapi.twilio.com toapi.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 calledTWILIO_LOG_LEVEL and set it todebug 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 theTwilio documentation.

Generate TwiML

To control phone calls, your application needs to outputTwiML.

// TwiML classes can be created as standalone elementsvargather=newGather(numDigits:1,action:newUri("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 objectgather.Timeout=100;gather.MaxSpeechTime=200// Arbitrary attributes can be set by calling set/getOptionvardial=newDial().SetOption("myAttribute",200).SetOption("newAttribute",false);// Or can be created and attached to a response directly using helper methodsvarresponse=newVoiceResponse().Say("Hello Monkey").Play(newUri("http://demo.twilio.com/hellomonkey/monkey.mp3")).Append(gather).Append(dial);// Serialize the TwiML objects to XML stringConsole.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 theadvanced 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

TheDockerfile present in this repository and its respectivetwilio/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 twiliobuildmaketest

Powershell:

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

Get support

If you need help installing or using the library, please check theTwilio Support Help Center first, andfile 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!

About

Twilio C#/.NET Helper Library for .NET6+.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Contributors76

Languages


[8]ページ先頭

©2009-2025 Movatter.jp