Skip to content

Telnyx.NET is a .NET 8+ SDK that provides a wrapper for the Telnyx API. It utilizes RestSharp for making HTTP requests and System.Text.Json for JSON serialization and deserialization. The SDK also uses Source Generated Json Serializer Contexts for efficient JSON processing.

Notifications You must be signed in to change notification settings

Spire-Recovery-Solutions/Telnyx.NET

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Telnyx.NET

Welcome to the Telnyx.NET SDK! This library provides a simple and intuitive way to interact with the Telnyx API using .NET. 🚀

Installation

To install the Telnyx.NET SDK, you can use the NuGet package manager:

dotnet add package Telnyx.NET

Or via the NuGet Package Manager Console:

Install-Package Telnyx.NET

Usage

Direct Initialization

Here's a quick example to get you started:

using Telnyx.NET;
using Telnyx.NET.Messaging.Models.Messages.Requests;
using Telnyx.NET.Messaging.Models.Messages.Responses;

var apiKey = "YOUR_API_KEY";
var client = new TelnyxClient(apiKey);

// Create a message request
var messageRequest = new SendMessageRequest
{
    From = "+1234567890",
    To = new List<string> { "+0987654321" },
    Text = "Hello from Telnyx.NET!"
};

// Send the message
SendMessageResponse response = await client.Messages.Send(messageRequest);

Console.WriteLine($"Message sent with ID: {response.Id}");

Using Dependency Injection

For applications using Microsoft.Extensions.DependencyInjection, you can register the Telnyx client in your service collection:

using Microsoft.Extensions.DependencyInjection;
using Telnyx.NET;

// In your Startup.cs or Program.cs
services.AddTelnyxClient(options =>
{
    options.ApiKey = "YOUR_API_KEY";
});

Then inject ITelnyxClient into your classes:

public class MessagingService
{
    private readonly ITelnyxClient _telnyxClient;

    public MessagingService(ITelnyxClient telnyxClient)
    {
        _telnyxClient = telnyxClient;
    }

    public async Task SendMessage(string to, string text)
    {
        var messageRequest = new SendMessageRequest
        {
            From = "+1234567890",
            To = new List<string> { to },
            Text = text
        };

        var response = await _telnyxClient.Messages.Send(messageRequest);
        Console.WriteLine($"Message sent with ID: {response.Id}");
    }
}

This approach is recommended for ASP.NET Core applications and other scenarios where you want to manage the lifetime of the client through dependency injection.

Contributing

We welcome contributions! Please read our contributing guidelines to get started.

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

Telnyx.NET is a .NET 8+ SDK that provides a wrapper for the Telnyx API. It utilizes RestSharp for making HTTP requests and System.Text.Json for JSON serialization and deserialization. The SDK also uses Source Generated Json Serializer Contexts for efficient JSON processing.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages