# twilio-csharp
[![Build status](https://travis-ci.com/twilio/twilio-csharp.svg?branch=main)](https://travis-ci.com/twilio/twilio-csharp.svg?branch=main)
[![NuGet](https://img.shields.io/nuget/v/Twilio.svg)](https://www.nuget.org/packages/Twilio)
[![Learn with TwilioQuest](https://img.shields.io/static/v1?label=TwilioQuest&message=Learn%20to%20contribute%21&color=F22F46&labelColor=1f243c&style=flat-square&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAMAAAD04JH5AAAASFBMVEUAAAAZGRkcHBwjIyMoKCgAAABgYGBoaGiAgICMjIyzs7PJycnMzMzNzc3UoBfd3d3m5ubqrhfrMEDu7u739/f4vSb/3AD///9tbdyEAAAABXRSTlMAAAAAAMJrBrEAAAKoSURBVHgB7ZrRcuI6EESdyxXGYoNFvMD//+l2bSszRgyUYpFAsXOeiJGmj4NkuWx1Qeh+Ekl9DgEXOBwOx+Px5xyQhDykfgq4wG63MxxaR4ddIkg6Ul3g84vCIcjPBA5gmUMeXESrlukuoK33+33uID8TWeLAdOWsKpJYzwVMB7bOzYSGOciyUlXSn0/ABXTosJ1M1SbypZ4O4MbZuIDMU02PMbauhhHMHXbmebmALIiEbbbbbUrpF1gwE9kFfRNAJaP+FQEXCCTGyJ4ngDrjOFo3jEL5JdqjF/pueR4cCeCGgAtwmuRS6gDwaRiGvu+DMFwSBLTE3+jF8JyuV1okPZ+AC4hDFhCHyHQjdjPHUKFDlHSJkHQXMB3KpSwXNGJPcwwTdZiXlRN0gSp0zpWxNtM0beYE0nRH6QIbO7rawwXaBYz0j78gxjokDuv12gVeUuBD0MDi0OQCLvDaAho4juP1Q/jkAncXqIcCfd+7gAu4QLMACCLxpRsSuQh0igu0C9Svhi7weAGZg50L3IE3cai4IfkNZAC8dfdhsUD3CgKBVC9JE5ABAFzg4QL/taYPAAWrHdYcgfLaIgAXWJ7OV38n1LEF8tt2TH29E+QAoDoO5Ve/LtCQDmKM9kPbvCEBApK+IXzbcSJ0cIGF6e8gpcRhUDogWZ8JnaWjPXc/fNnBBUKRngiHgTUSivSzDRDgHZQOLvBQgf8rRt+VdBUUhwkU6VpJ+xcOwQUqZr+mR0kvBUgv6cB4+37hQAkXqE8PwGisGhJtN4xAHMzrsgvI7rccXqSvKh6jltGlrOHA3Xk1At3LC4QiPdX9/0ndHpGVvTjR4bZA1ypAKgVcwE5vx74ulwIugDt8e/X7JgfkucBMIAr26ndnB4UCLnDOqvteQsHlgX9N4A+c4cW3DXSPbwAAAABJRU5ErkJggg==)](https://twil.io/learn-open-source)
**The default branch name for this repository has been changed to `main` as of 07/27/2020.**
## 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][apidocs].
More documentation for this library can be found [here][libdocs].
## Versions
`twilio-csharp` uses a modified version of [Semantic Versioning](https://semver.org) for all changes. [See this document](VERSIONS.md) for details.
### Migrating from earlier versions
See the migration guide [here][migrating]. Also, if you were using the `Twilio.Mvc` package, that has been replaced by the [Twilio.AspNet.Mvc][aspnet] 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](https://www.twilio.com/docs/api/errors/20426) indicate that TLS 1.0/1.1 is being used. With .NET, you can enable TLS 1.2 using this setting:
```csharp
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
```
### Supported .NET versions
This library supports .NET applications that utilize .NET Framework 3.5+ or .NET Core 1.0+ (.NET Standard 1.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:
```csharp
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);
```
## Specify Region and/or Edge
To take advantage of Twilio's [Global Infrastructure](https://www.twilio.com/docs/global-infrastructure), specify the target Region and/or Edge for the client:
```csharp
TwilioClient.SetRegion("au1");
TwilioClient.SetEdge("sydney");
```
This will result in the `hostname` transforming from `api.twilio.com` to `api.sydney.au1.twilio.com`.
## 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:
```csharp
TwilioClient.SetLogLevel("debug");
```
## Handling Exceptions
For an example on how to handle exceptions in this helper library, please see the [Twilio documentation](https://www.twilio.com/docs/libraries/csharp-dotnet/usage-guide#handling-errors).
## Generating TwiML
To control phone calls, your application needs to output [TwiML][twiml].
```csharp
// 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>
*/
```
## Using a Custom HTTP Client
To use a custom HTTP client with this helper library, please see the [Twilio documentation](https://www.twilio.com/docs/libraries/csharp-dotnet/custom-http-clients-dot-net-framework).
## 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](https://support.twilio.com) first, and [file a support ticket](https://twilio.com/help/contact) 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!
[twilio]: https://www.twilio.com
[apidocs]: https://www.twilio.com/docs/api
[twiml]: https://www.twilio.com/docs/api/twiml
[libdocs]: https://twilio.github.io/twilio-csharp
[migrating]: https://www.twilio.com/docs/libraries/csharp/migrating-your-csharp-dot-net-application-twilio-sdk-4x-5x
[aspnet]: https://github.com/twilio/twilio-aspnet
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
特里维奥夏普 截至2020年7月27日,此存储库的默认分支名称已更改为main 。 用于.NET的Twilio REST API和TwiML库 Twilio提供了一个简单的基于HTTP的API,用于发送和接收电话和短信。 在上了解更多。 该库的更多文档可以在找到。 版本号 twilio-csharp对所有更改使用的修改版本。 详细信息,。 从早期版本迁移 请参阅的迁移指南。 另外,如果您使用的是Twilio.Mvc程序包,则已由与此版本的库兼容的程序包替换。 TLS 1.2要求 现在,在访问REST API时,要求新帐户和子帐户使用TLS 1.2。 表明正在使用TLS 1.0 / 1.1。
资源推荐
资源详情
资源评论
收起资源包目录
twilio-csharp:适用于.NET Framework 3.5+和受支持的.NET Core版本的Twilio C#.NET帮助程序库 (1337个子文件)
TriggerResource.cs 62KB
ServiceResource.cs 58KB
IncomingPhoneNumberResource.cs 58KB
ParticipantResource.cs 55KB
CallResource.cs 54KB
ReservationResource.cs 50KB
ServiceResource.cs 50KB
ReservationResource.cs 49KB
ServiceResource.cs 42KB
ApplicationResource.cs 41KB
RecordResource.cs 40KB
HostedNumberOrderResource.cs 40KB
ThisMonthResource.cs 40KB
YesterdayResource.cs 40KB
LastMonthResource.cs 40KB
AllTimeResource.cs 40KB
MonthlyResource.cs 40KB
YearlyResource.cs 40KB
DailyResource.cs 40KB
TodayResource.cs 40KB
MessageResource.cs 40KB
ParticipantResource.cs 39KB
FlexFlowResource.cs 38KB
ServiceResource.cs 38KB
DomainResource.cs 37KB
ServiceResource.cs 37KB
ServiceResource.cs 37KB
CompositionHookResource.cs 36KB
ConversationResource.cs 36KB
ParticipantResourceTest.cs 36KB
ParticipantResource.cs 36KB
RecordingResource.cs 35KB
MessageResource.cs 34KB
MemberResource.cs 34KB
CallResourceTest.cs 34KB
ConversationResource.cs 34KB
MessageResource.cs 34KB
ServiceResource.cs 33KB
TaskResource.cs 33KB
WebhookResource.cs 33KB
SimResource.cs 33KB
SyncMapItemResource.cs 32KB
TollFreeResource.cs 32KB
WebhookResource.cs 32KB
SyncListItemResource.cs 32KB
TaskQueueResource.cs 32KB
MobileResource.cs 32KB
FactorResource.cs 32KB
LocalResource.cs 32KB
ChannelResource.cs 32KB
MessageResource.cs 32KB
AddressResource.cs 32KB
ServiceResource.cs 31KB
MemberResource.cs 31KB
ByocTrunkResource.cs 31KB
MessageResource.cs 31KB
IpAddressResource.cs 31KB
AssistantResource.cs 31KB
SessionResource.cs 30KB
VoiceResponse.cs 30KB
WebhookResource.cs 30KB
FaxResource.cs 30KB
WebhookResource.cs 30KB
ChannelResource.cs 30KB
WorkflowResource.cs 30KB
ServiceResource.cs 29KB
RatePlanResource.cs 29KB
ConnectionPolicyTargetResource.cs 29KB
WorkerResource.cs 29KB
WorkspaceResource.cs 29KB
BundleResource.cs 29KB
TrunkResource.cs 29KB
UserResource.cs 29KB
SampleResource.cs 29KB
Say.cs 28KB
RecordingResource.cs 28KB
SampleResource.cs 28KB
CredentialResource.cs 28KB
MessageResource.cs 28KB
QueryResource.cs 28KB
DeviceResource.cs 28KB
CompositionResource.cs 28KB
CredentialResource.cs 28KB
AssistantResource.cs 28KB
QueryResource.cs 27KB
SyncListItemResource.cs 27KB
SyncMapItemResource.cs 27KB
ChallengeResource.cs 27KB
OriginationUrlResource.cs 27KB
Dial.cs 27KB
UserResource.cs 27KB
RoomResource.cs 27KB
ChannelResource.cs 27KB
MemberResource.cs 27KB
VariableResource.cs 27KB
CertificateResource.cs 27KB
WebhookResource.cs 27KB
UserResource.cs 26KB
CredentialResource.cs 26KB
TaskResource.cs 26KB
共 1337 条
- 1
- 2
- 3
- 4
- 5
- 6
- 14
资源评论
- jimmy.net2021-08-12用户下载后在一定时间内未进行评价,系统默认好评。
Jeckaijew
- 粉丝: 25
- 资源: 4533
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功