This SDK is currently available for preview purposes only. It should not be used in production environments.

Sinch .NET SDK for Conversation API

The Sinch Conversation API .NET SDK allows you to quickly interact with the Conversation API from inside your .NET applications.

Installing the SDK

The easiest way to install the SDK is using the dotnet CLI:

  1. Open a command prompt or terminal to the local repository folder.
  2. Execute the following command:
    Copy
    Copied
    dotnet add package Sinch

Initializing the client

Before initializing a client using this SDK, you'll need three pieces of information:

  • Your Project ID
  • An access key ID
  • An access key Secret

These values can be found on the Access Keys page of the Customer Dashboard. You can also create new access key IDs and Secrets, if required.

Note:

If you have trouble accessing the above link, ensure that you have gained access to the Conversation API by accepting the corresponding terms and conditions.

To start using the SDK, you need to initialize the main client class with your credentials from your Sinch dashboard.

Note:

For testing purposes on your local environment it's fine to use hardcoded values, but before deploying to production we strongly recommend using environment variables to store the credentials.

Copy
Copied
using Sinch;

var sinch = new SinchClient("YOUR_project_id",
                            "YOUR_access_key", 
                            "YOUR_access_secret");

You can also implement the client using ASP.NET dependency injection. SinchClient is thread safe, so it's fine to add it as a singleton:

Copy
Copied
builder.Services.AddSingleton<ISinchClient>(x => new SinchClient(
    builder.Configuration["YOUR_project_id"],
    builder.Configuration["YOUR_access_key"],
    builder.Configuration["YOUR_access_secret"]));

Test your SDK implementation by creating and running this simple .NET application to list the list the Conversation API apps assigned to your project:

Copy
Copied
using Sinch;

var sinch = new SinchClient(configuration["Sinch:KeyId"], configuration["Sinch:KeySecret"], configuration["Sinch:ProjectId"]);

Sinch.Numbers.Available.List.Response response = await sinch.Numbers.Available.List(new Sinch.Numbers.Available.List.Request
{
    RegionCode = "US",
    Type = Types.Local
});

Console.WriteLine(JsonSerializer.Serialize(response, new JsonSerializerOptions()
    {
        WriteIndented = true
    }));

Next steps

Now that your .NET SDK is set up, follow one of our getting started guides to learn more about how to use the .NET SDK with Conversation API, or view the SDK reference.

We'd love to hear from you!
Rate this content:
Still have a question?
 
Ask the community.