Make a call with ASP.NET Core 6.0

You can quickly see how the Voice API works by calling yourself using the Voice SDK.

In this guide you will learn:
  1. How to set up your ASP.NET Core console application.
  2. How to call your phone number.

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 6.0 application

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

Copy
Copied
dotnet new console

This creates a new web API application and project. Now add the Sinch Voice SDK. Run the following command:

Copy
Copied
dotnet add package Sinch.ServerSdk

The Voice SDK lets you use the Voice API with far fewer lines of code than you'd otherwise need.

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.

Make a phone call

// Find your application key and secret at dashboard.sinch.com/voice/apps
// Find your Sinch numbers at dashboard.sinch.com/numbers/your-numbers/numbers
using Sinch.ServerSdk;
using Sinch.ServerSdk.Models;

string key = "MyAppKey";
string secret = "MyAppSecret";
string to = "MyToNumber";
string fromNumber = "MyFromNumber";

var calloutApi = SinchFactory
                .CreateApiFactory(key, secret, Locale.EnUs)
                .CreateCalloutApi();
var calloutResponse = await calloutApi
                    .TtsCallout(
                        to, 
                        "Hello, this is a call from Sinch. Congratulations! You made your first call.", 
                        fromNumber)
                    .Call();

This code makes text-to-speech callout to a specified number using the Sinch Voice SDK.

To

In this example you want to call a phone number. Change the value of the to 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!

Fill in your parameters

Before you can run the code, you need to update some more values so you can connect to your Sinch account. Update the following parameters with your own values:

ParameterYour value
keyThe application key found on your Sinch dashboard. Click on your application to find the key.
secretThe application secret found on your Sinch dashboard. Click on your application to fine the secret.
fromNumberAny number you've assigned to your application. Find the number on your Sinch dashboard by clicking on your app and looking in the Inbound Numbers section.

Save the file.

Build your project

Before executing your code, you must first compile your application. Execute the following command:

Copy
Copied
dotnet build

Make your first call

Now you can execute the code and make your text-to-speech call. Run the following command:

Copy
Copied
dotnet run

You should receive a phone call to the number you called with the message "Hello, this is a call from Sinch. Congratulations! You made your first call."

Next steps

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

Additional resources

Was this page helpful?

Make a phone call

// Find your application key and secret at dashboard.sinch.com/voice/apps
// Find your Sinch numbers at dashboard.sinch.com/numbers/your-numbers/numbers
using Sinch.ServerSdk;
using Sinch.ServerSdk.Models;

string key = "MyAppKey";
string secret = "MyAppSecret";
string to = "MyToNumber";
string fromNumber = "MyFromNumber";

var calloutApi = SinchFactory
                .CreateApiFactory(key, secret, Locale.EnUs)
                .CreateCalloutApi();
var calloutResponse = await calloutApi
                    .TtsCallout(
                        to, 
                        "Hello, this is a call from Sinch. Congratulations! You made your first call.", 
                        fromNumber)
                    .Call();