Some features of this SDK are still in development. Consult with our online support team if you run into issues using this SDK in a production environment.

Send a Conversation Message with the Sinch .NET SDK

Note:

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

Learn how to quickly send Conversation messages in a .NET application with the Sinch .NET SDK.

Steps:
  1. Set up your .NET application
  2. Send your first message

Set up your .NET application

  1. Create a new folder where you want your app project. Then, open a terminal or command prompt to that location.
  2. Create a new .NET console app with the following command:
    Copy
    Copied
    dotnet new console

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.
  1. Open the Program.cs file in your project folder. Replace everything in the file with the "Send a Conversation message" code.

Modify your application

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

Initialize 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"]));

Fill in remaining parameters

Assign your values to the following parameters:

Placeholder valueYour value
YOUR_app_idFind your app ID on your Sinch dashboard.
YOUR_channelThe channel you want to use to send the message. This guide presets this channel property to SMS, but you may update it to any channel that's already configured on your Conversation API app. You may add the following channels to your app from the Sinch Customer Dashboard:
  • SMS
  • MESSENGER
  • MMS
  • RCS
  • WHATSAPP
  • VIBER
  • VIBERBM
  • INSTAGRAM
  • TELEGRAM
  • KAKAOTALK
  • APPLEBC
  • LINE
  • WECHAT
RECIPIENT_numberThe channel identity of the recipient to which you want to send the message. When using the SMS channel, this will be a phone number.
YOUR_sms_senderYour Sinch virtual phone number, available on the customer dashboard. This is only required if you are using the SMS channel.

Ensure that you save the file.

Build your project

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

Copy
Copied
dotnet build

Send your first message

Now you can execute the code and send your test message. Run the following command:

Copy
Copied
dotnet run
You should receive a text to the phone number you entered and you'll see a response in your terminal or command prompt. Press Enter to exit the application. You did it!

Next steps

The code you used in the Program.cs file sends a POST request to the Sinch API /Messages endpoint to send the text message. Click here to read more about the messages endpoint.

Additional resources

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