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
SinchSDK can be installed using the Nuget package manager or the dotnet CLI.
dotnet add package Sinch Once the SDK is installed, you must start by initializing the main client class.
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).
usingSinch;varsinch=newSinchClient(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 singletonbuilder.Services.AddSingleton<ISinch>(x =>newSinchClient(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:
varsinch=newSinchClient(configuration["Sinch:ProjectId"],configuration["Sinch:KeyId"],configuration["Sinch:KeySecret"], options =>{options.SmsRegion=Sinch.SMS.SmsRegion.Eu;options.ConversationRegion=Sinch.Conversation.ConversationRegion.Eu;});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:
usingSinch.Numbers.Active.List;ListActiveNumbersResponseresponse=awaitsinch.Numbers.Active.List(newListActiveNumbersRequest{RegionCode="US",Type=Types.Mobile});To configure a logger, provide your own HttpClient, or any additional options utilize SinchOptions action within the constructor:
usingSinch;usingSinch.SMS;varsinch=newSinchClient(configuration["Sinch:ProjectId"],configuration["Sinch:KeyId"],configuration["Sinch:KeySecret"], options =>{// provide any logger factory which satisfies Microsoft.Extensions.Logging.ILoggerFactoryoptions.LoggerFactory=LoggerFactory.Create(config =>{// add log output to consoleconfig.AddConsole();});// Provide your http client hereoptions.HttpClient=newHttpClient();// Set a hosting region for Smsoptions.SmsRegion=SmsRegion.Eu;});For an unsuccessful API calls SinchApiException will be thrown:
usingSinch;usingSinch.SMS.Batches.Send;try{varbatch=awaitsinch.Sms.Batches.Send(newSendTextBatchRequest(){Body="Hello, World!",To=newList<string>(){"+123456789"}});}catch(SinchApiExceptione){logger.LogError("Api Exception. Status:{status}. Detailed message:{message}",e.Status,e.DetailedMessage);}For additional examples see examples
This project is licensed under the Apache License. See the LICENSE file for the license text.