Unimatrix C# / .NET SDK
Installation
The recommended way to install the Unimatrix SDK for .NET is to use the nuget package manager, which is available on NuGet.
If you are building with the .NET CLI, run the following command to add UniSdk
as a dependency to your project:
dotnet add package UniSdk
If you are using the Visual Studio IDE, run the following command in the Package Manager Console:
Install-Package UniSdk
Usage
The following example shows how to use the Unimatrix .NET SDK to interact with Unimatrix services.
Initialize a client
using UniSdk;
var client = new UniClient("your access key id", "your access key secret"); // if using simple auth mode, just pass in the first parameter
or you can configure your credentials by environment variables:
export UNIMTX_ACCESS_KEY_ID=your_access_key_id
export UNIMTX_ACCESS_KEY_SECRET=your_access_key_secret
Send SMS
Send a text message to a single recipient.
using System;
using UniSdk;
class Program
{
static void Main(string[] args)
{
var client = new UniClient();
try
{
var resp = client.Messages.Send(new {
to = "+1206880xxxx", // in E.164 format
text = "Your verification code is 2048."
});
Console.WriteLine(resp.Data);
}
catch (UniException ex)
{
Console.WriteLine(ex);
}
}
}
or use async method:
using System;
using System.Threading.Tasks;
using UniSdk;
class Program
{
static async Task Main(string[] args)
{
var client = new UniClient();
try
{
var resp = await client.Messages.SendAsync(new {
// ...
});
Console.WriteLine(resp.Data);
}
catch (UniException ex)
{
Console.WriteLine(ex);
}
}
}
Send a message using a template with variables.
client.Messages.Send(new {
to = "+1650253xxxx",
signature = "Unimatrix",
templateId = "pub_verif_en_basic2",
templateData = new {
code = "2048"
}
});
Send OTP
Send a one-time passcode (OTP) to a recipient. The following example will send a automatically generated verification code to the user.
using System;
using UniSdk;
class Program
{
static void Main(string[] args)
{
var client = new UniClient();
var resp = client.Otp.Send(new {
to = "+1206880xxxx"
});
Console.WriteLine(resp.Data);
}
}
Verify OTP
Verify the one-time passcode (OTP) that a user provided. The following example will check whether the user-provided verification code is correct.
using System;
using UniSdk;
class Program
{
static void Main(string[] args)
{
var client = new UniClient();
var resp = client.Otp.Verify(new {
to = "+1206880xxxx",
code = "123456" // the code user provided
});
Console.WriteLine(resp.Valid);
}
}