Make a call with .NET SDK

This guide shows how to make a Text-to-speech phone call in a .NET application using the Voice API and .NET SDK.

In this guide you will learn:

What you need to know before you start

Before you can get started, you need the following already set up:

Set up your ASP.NET Core application

Create a new project folder and open a command prompt. Execute the following command to create a new ASP.NET Core console application:

Copy
Copied
dotnet new console

This creates a new console application and project.

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 --prerelease
Note:
Because the Sinch .NET SDK is in prerelease, you must include the --prerelease option to install it.

Modify your application

In your project folder, open the Program.cs file and paste the provided "Program.cs" code into the file, replacing all the existing content.

The code provided includes placeholder parameters. You'll need to update the parameters detailed in the following subsections with your values.

Initialize the client

To start using the Voice API with the SDK, you need to initialize the main client class with your credentials from your Sinch dashboard and additionally create a Voice client object that uses your Voice app credentials.

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_access_key", 
                            "YOUR_access_secret", 
                            "YOUR_project_id");

var voice = sinch.Voice("YOUR_application_key", "YOUR_application_secret");

Or, if you only need to use Voice API:

Copy
Copied
using Sinch;

var sinch = new SinchClient(default, default, default);

var voice = sinch.Voice("YOUR_application_key", "YOUR_application_secret");

Destination number

In this example you want to call a phone number. Change the value of the YOUR_phone_number parameter to the phone number you verified in your dashboard in E.164 format.
Note:

When your account is in trial mode, you can only call your verified numbers. If you want to call any number, you need to upgrade your account!

Save the file.

Make your phone call

  1. Now you can execute the code and make your phone call. Run the following command:
    Copy
    Copied
    dotnet run

    You should receive a phone call to your mobile handset with a voice speaking the words in the request. You should also see the JSON response in the console.

Next steps

Now that you know how to make a call, learn how to handle an incoming call.

Additional resources

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