Sinch 1.1.2
dotnet add package Sinch --version 1.1.2
NuGet\Install-Package Sinch -Version 1.1.2
<PackageReference Include="Sinch" Version="1.1.2" />
paket add Sinch --version 1.1.2
#r "nuget: Sinch, 1.1.2"
// Install Sinch as a Cake Addin #addin nuget:?package=Sinch&version=1.1.2 // Install Sinch as a Cake Tool #tool nuget:?package=Sinch&version=1.1.2
Sinch .NET SDK
Here you'll find documentation related to the Sinch .NET SDK, including how to install it, initialize it, and start developing .NET code using Sinch services.
To use Sinch services, you'll need a Sinch account and access keys. You can sign up for an account and create access keys at dashboard.sinch.com.
For more information on the Sinch APIs on which this SDK is based, refer to the official developer documentation portal.
- Installation
- Getting started
- Client initialization
- Supported Sinch products
- Logging, HttpClient and additional options
- Handling Exceptions
Installation
SinchSDK can be installed using the Nuget package manager or the dotnet
CLI.
dotnet add package Sinch
Getting started
Once the SDK is installed, you must start by initializing the main client class.
Client initialization
To initialize communication with the Sinch servers, credentials obtained from the Sinch dashboard must be provided to the main client class of this SDK. It's highly recommended to not hardcode these credentials and to load them from environment variables instead or any key-secret storage (for example, app-secrets).
using Sinch;
var sinch = new SinchClient(configuration["Sinch:ProjectId"], configuration["Sinch:KeyId"], configuration["Sinch:KeySecret"]);
With ASP.NET dependency injection:
// SinchClient is thread safe so it's okay to add it as a singleton
builder.Services.AddSingleton<ISinch>(x => new SinchClient(
builder.Configuration["Sinch:ProjectId"],
builder.Configuration["Sinch:KeyId"],
builder.Configuration["Sinch:KeySecret"]
));
To configure Conversation or Sms hosting regions, and any other additional parameters, use SinchOptions
:
var sinch = new SinchClient(
configuration["Sinch:ProjectId"],
configuration["Sinch:KeyId"],
configuration["Sinch:KeySecret"],
options =>
{
options.SmsRegion = Sinch.SMS.SmsRegion.Eu;
options.ConversationRegion = Sinch.Conversation.ConversationRegion.Eu;
});
Supported Sinch Products
Sinch client provides access to the following Sinch products:
- SMS
- Conversation
- Numbers
- Verification
- Voice
- additional products coming soon!
Usage example of the numbers
product, assuming sinch
is a type of ISinchClient
:
using Sinch.Numbers.Active.List;
ListActiveNumbersResponse response = await sinch.Numbers.Active.List(new ListActiveNumbersRequest
{
RegionCode = "US",
Type = Types.Mobile
});
Logging, HttpClient, and additional options
To configure a logger, provide your own HttpClient
, or any additional options utilize SinchOptions
action within the constructor:
using Sinch;
using Sinch.SMS;
var sinch = new SinchClient(
configuration["Sinch:ProjectId"],
configuration["Sinch:KeyId"],
configuration["Sinch:KeySecret"],
options =>
{
// provide any logger factory which satisfies Microsoft.Extensions.Logging.ILoggerFactory
options.LoggerFactory = LoggerFactory.Create(config => {
// add log output to console
config.AddConsole();
});
// Provide your http client here
options.HttpClient = new HttpClient();
// Set a hosting region for Sms
options.SmsRegion = SmsRegion.Eu;
});
Handling exceptions
For an unsuccessful API calls SinchApiException
will be thrown:
using Sinch;
using Sinch.SMS.Batches.Send;
try {
var batch = await sinch.Sms.Batches.Send(new SendTextBatchRequest()
{
Body = "Hello, World!",
To = new List<string>()
{
"+123456789"
}
});
}
catch(SinchApiException e)
{
logger.LogError("Api Exception. Status: {status}. Detailed message: {message}", e.Status, e.DetailedMessage);
}
Sample apps
For additional examples see examples
License
This project is licensed under the Apache License. See the LICENSE file for the license text.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net6.0
- Microsoft.Extensions.Http (>= 7.0.0)
- System.Text.Json (>= 8.0.5)
-
net7.0
- Microsoft.Extensions.Http (>= 7.0.0)
- System.Text.Json (>= 8.0.5)
-
net8.0
- Microsoft.Extensions.Http (>= 7.0.0)
- System.Text.Json (>= 8.0.5)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.1.2 | 562 | 10/16/2024 |
1.1.1 | 1,698 | 7/16/2024 |
1.1.0 | 109 | 7/15/2024 |
1.0.1 | 1,379 | 5/13/2024 |
1.0.0 | 135 | 5/7/2024 |
0.1.19-alpha | 296 | 4/17/2024 |
0.1.18-alpha | 125 | 3/25/2024 |
0.1.17-alpha | 157 | 2/21/2024 |
0.1.16-alpha | 116 | 2/5/2024 |
0.1.15-alpha | 109 | 2/1/2024 |
0.1.14-alpha | 116 | 1/22/2024 |
0.1.13-alpha | 1,508 | 12/13/2023 |
0.1.11-alpha | 139 | 11/30/2023 |
0.1.10-alpha | 116 | 11/29/2023 |
0.1.9-alpha | 837 | 10/27/2023 |
0.1.8-alpha | 137 | 10/26/2023 |
0.1.7-alpha | 109 | 9/21/2023 |
0.1.6-alpha | 134 | 9/11/2023 |
0.1.5-alpha | 150 | 9/1/2023 |
0.1.4-alpha | 137 | 8/21/2023 |
0.1.2-alpha.1 | 98 | 7/19/2023 |