Skip to content

thedonmon/telnyx-dotnet

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Telnyx.net

Build status NuGet Coverage Status

The official Telnyx library, supporting .NET Standard 2.0, .NET Core 1.0+, and .NET Framework 4.5+

Documentation

See the .NET API docs.

Installation

Install Telnyx.net via NuGet

From the command line:

nuget install Telnyx.net

From Package Manager:

PM> Install-Package Telnyx.net

From within Visual Studio:

  1. Open the Solution Explorer.
  2. Right-click on a project within your solution.
  3. Click on Manage NuGet Packages...
  4. Click on the Browse tab and search for "Telnyx.net".
  5. Click on the Telnyx.net package, select the appropriate version in the right-tab and click Install.

Set the API Key for your project

You can configure the Telnyx.net package to use your secret API key in one of two ways:

a) In your application initialization, set your API Key (only once during startup):

TelnyxConfiguration.SetApiKey("YOUR_API_KEY");

b) Pass the API key to RequestOptions:

var numberReservationsService = new NumberReservationsService();
numberReservationsService.Get("PHONE_NUMBER_ID", new RequestOptions { ApiKey = "YOUR_API_KEY" });

You can obtain your secret API key from the Auth section oin the Mission Control Portal.

Xamarin/Mono Developers (Optional)

If you are using Xamarin/Mono, you may want to provide your own HttpMessageHandler. You can do so by passing an instance to TelnyxConfiguration.HttpMessageHandler on your application's startup.

Support

Helpful Library Information

Run Test Project via Docker CLI

In order to run the tests you need to have the telnyx-mock running on your local port. This mock is used to mimic the Telnyx API in order to ensure responses will be correct.

Steps to install and run the telynx-mock can be found here: readme

Explicit steps are as follows:

  • Make sure you have docker installed. This can be either windows/mac/linux.
  • Run the docker pull cmd: docker pull telnyx/telnyx-mock:latest
  • Verify the image is pulled correctly: docker images
  • If you see the image listed, now we can run the image: docker run -p 12111-12112:12111-12112 telnyx/telnyx-mock
  • Keep this powershell or cmdline window open and run the TelynxTests project via test runner or dotnet-cli
  • Add your API key to the appsettings file. For NET45+ use App.config for netstandard/netcore use appsettings.json found in the test project

Run Telnyx.Example Project with your API Key

In oder to get the Example project to run properly, you can add your API Key to the appsettings.json file similar to above. Here you can play around with the console app without requiring the telnyx-mock to run. NOTE: This will hit the API directly so be aware of the different operations you are trying as rate limiting applies.

Request Options

All of the service methods accept an optional RequestOptions object. This is used if you want to pass the secret API key on each method.

var requestOptions = new RequestOptions();
requestOptions.ApiKey = "YOUR_API_KEY";                        // (optional) set the api key on a per-request basis

Responses

The TelnyxResponse object is an attribute (with the same name) attached to all entities in Telnyx.net when they are returned from a service call.

Example: Access the TelnyxResponse

var numberReservationsService = new NumberReservationsService();
NumberReservation reservation = numberReservationsService.Create(...);
TelnyxResponse response = reservation.TelnyxResponse;

The information that can be derived from the TelnyxResponse is available from the TelnyxResponse Class.

public class TelnyxResponse
{
	// ResponseJson will always tell you the complete json Telnyx returned to Telnyx.net.
	// this will be the same as the ObjectJson when you execute a create/get/delete call.
	// however, if you execute a List() method, the ResponseJson will have the full api result
	// from Telnyx (a phone number list with 10 phone numbers, for example).
	public string ResponseJson { get; set; }

	// when you call a List() method, the object json is the object in the response array that represents
	// the entity. The ResponseJson will be the full array returned from Telnyx on every entity, however,
	// since that was the full response from Telnyx. ObjectJson is always the same as ResponseJson when
	// you are doing a regular create/get/delete, because you are dealing with a single object.
	public string ObjectJson { get; set; }

	// this is the request id of the call. I would recommend logging
	// this and/or saving it to your database. this is very useful when troubleshooting with Telnyx support
	public string RequestId { get; set; }

	// this is the request date and time of the call. I would also recommend logging this and/or
	// saving it to your database, as it tells you when Telnyx processed the request.
	public DateTime RequestDate { get; set; }
}

Contribution Guidelines

We welcome contributions from anyone interested in Telnyx or Telnyx.net development. If you'd like to submit a pull request, it's best to start with an issue to describe what you'd like to build.

Once you've written your pull request, please make sure you test your changes.

Acknowledgments

The contributors and maintainers of Telnyx .NET would like to extend their deep gratitude to the authors of Stripe .NET, upon which this project is based. Thank you for developing such elegant, usable, and extensible code and for sharing it with the community.

About

.NET SDK for the Telnyx API

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%