SharpNyx 0.2.4

C# Telnyx API wrapper for .Net Core 2.1.

Install-Package SharpNyx -Version 0.2.4
dotnet add package SharpNyx --version 0.2.4
<PackageReference Include="SharpNyx" Version="0.2.4" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SharpNyx --version 0.2.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

SharpNyx

Telnyx API C# wrapper for .Net Core. Uses HttpClient.

Dependencies

  • .NETCoreApp 2.1
  • Newtonsoft.Json (>= 12.0.2)

It should work with .Net standard but you may have to manually import the Telnyx.dll.

Installation

Add the NuGet package or download and reference the Telnyx.dll issued in Releases.
https://www.nuget.org/packages/SharpNyx

Usage

Send a message
//Import
using Telnyx.SharpNyx;

//Quick instantiation
MessagingAPIClient mac = new MessagingAPIClient("Q7EI8KGZJ3FrwBxMKq5zmID1");

//Make a new SMS message
SMS sms = new SMS("BUGSINC", "+16506003337", "Hello Telnyx");

//Call and wait for SendSMS to finish
mac.SendSMSAsync(sms).Wait();

//Check to see if it is queued
bool isq = sms.IsQueued;
SMS
//Send a message with just the recipient and body
Message msg = new Message();
msg.ToPhoneNumber = "+16506003337";
msg.Body = "Hello Telnyx";
Send Quick MMS
//Quickly send one image without subject
MessagingAPIClient mac = new MessagingAPIClient("M7RI1KGBJ8FrwBxTKq3zmIN1");

string url = "https://nssdc.gsfc.nasa.gov/planetary/image/saturn.jpg";

MMS mms = new MMS("BUGSINC", "+16508976777", new Dictionary<string, string> { { MediaUtype.Image, url } });

mac.SendMMSAsync(mms).Wait();

return mms.IsQueued;
MMS With Two Images
//Send two images with a subject
MessagingAPIClient mac = new MessagingAPIClient("M7RI1KGBJ8FrwBxTKq3zmIN1");

string url1 = "https://upload.wikimedia.org/wikipedia/commons/5/5f/HubbleDeepField.800px.jpg";
string url2 = "https://upload.wikimedia.org/wikipedia/commons/e/e1/M45map.jpg";

Dictionary<string, string> dic1 = new Dictionary<string, string>();
dic1.Add(MediaUtype.Image, url1);

Dictionary<string, string> dic2 = new Dictionary<string, string>();
dic2.Add(MediaUtype.Image, url2);

MMS mms = new MMS()
{
    FromPhoneNumber = "BUGSINC",
    Subject = "Alcyone",
    ToPhoneNumber = "+16508976777",
    MediaUrls = new List<Dictionary<string, string>>() { dic1, dic2 }
};

mac.SendMMSAsync(mms).Wait();

return mms.IsQueued;
The Messaging API Client (MAC)

MAC is the main broker for the HttpClient. MAC does the work of sending messages, and communicating with the Telnyx Rest API.

MAC implements a static HttpClient to use for the entire application. You can instantiate the MessagingAPIClient by directly adding the x-secret.

The MAC will add the secret to the header every time a new request is made. So you can change the secret for the same instance.

//Get the full Http response from the API call
string httpstatus = mac.HttpResponse.StatusCode.ToString(); //returns OK for 200

//Reponse Status returns the status. This field is used to determine the Message.IsQueued value.
string responsemessage = mac.ReponseStatus;

//Reponse Message returns "Queued" if successful, returns the message if unsuccessful delivery
string responsemessage = mac.ReponseMessage;

//Grab System.Exception
mac.MACException;
Accepted Response Payload
//Get the full response payload on an accepted outbound message request
AcceptedResponsePayload arp = AcceptedResponsePayload.FromJson(mac.ReponseString);
string smsid = arp.SMSId; //Generated message ID from Telnyx
Rejected Response Payload
//Get the response error details from the mac response string if message is not queued
RejectedResponsePayload rrp = RejectedResponsePayload.FromJson(mac.ReponseString);
string errormessage = err.Message;
Message Delivery Record
//Returns null if there is an exception
MessageDeliveryRecord mdr = await trc.GetMessageDeliveryRecord(msgid);
return mdr.Errors;

MIT License
2019 Bharat Bhardwaj

SharpNyx

Telnyx API C# wrapper for .Net Core. Uses HttpClient.

Dependencies

  • .NETCoreApp 2.1
  • Newtonsoft.Json (>= 12.0.2)

It should work with .Net standard but you may have to manually import the Telnyx.dll.

Installation

Add the NuGet package or download and reference the Telnyx.dll issued in Releases.
https://www.nuget.org/packages/SharpNyx

Usage

Send a message
//Import
using Telnyx.SharpNyx;

//Quick instantiation
MessagingAPIClient mac = new MessagingAPIClient("Q7EI8KGZJ3FrwBxMKq5zmID1");

//Make a new SMS message
SMS sms = new SMS("BUGSINC", "+16506003337", "Hello Telnyx");

//Call and wait for SendSMS to finish
mac.SendSMSAsync(sms).Wait();

//Check to see if it is queued
bool isq = sms.IsQueued;
SMS
//Send a message with just the recipient and body
Message msg = new Message();
msg.ToPhoneNumber = "+16506003337";
msg.Body = "Hello Telnyx";
Send Quick MMS
//Quickly send one image without subject
MessagingAPIClient mac = new MessagingAPIClient("M7RI1KGBJ8FrwBxTKq3zmIN1");

string url = "https://nssdc.gsfc.nasa.gov/planetary/image/saturn.jpg";

MMS mms = new MMS("BUGSINC", "+16508976777", new Dictionary<string, string> { { MediaUtype.Image, url } });

mac.SendMMSAsync(mms).Wait();

return mms.IsQueued;
MMS With Two Images
//Send two images with a subject
MessagingAPIClient mac = new MessagingAPIClient("M7RI1KGBJ8FrwBxTKq3zmIN1");

string url1 = "https://upload.wikimedia.org/wikipedia/commons/5/5f/HubbleDeepField.800px.jpg";
string url2 = "https://upload.wikimedia.org/wikipedia/commons/e/e1/M45map.jpg";

Dictionary<string, string> dic1 = new Dictionary<string, string>();
dic1.Add(MediaUtype.Image, url1);

Dictionary<string, string> dic2 = new Dictionary<string, string>();
dic2.Add(MediaUtype.Image, url2);

MMS mms = new MMS()
{
    FromPhoneNumber = "BUGSINC",
    Subject = "Alcyone",
    ToPhoneNumber = "+16508976777",
    MediaUrls = new List<Dictionary<string, string>>() { dic1, dic2 }
};

mac.SendMMSAsync(mms).Wait();

return mms.IsQueued;
The Messaging API Client (MAC)

MAC is the main broker for the HttpClient. MAC does the work of sending messages, and communicating with the Telnyx Rest API.

MAC implements a static HttpClient to use for the entire application. You can instantiate the MessagingAPIClient by directly adding the x-secret.

The MAC will add the secret to the header every time a new request is made. So you can change the secret for the same instance.

//Get the full Http response from the API call
string httpstatus = mac.HttpResponse.StatusCode.ToString(); //returns OK for 200

//Reponse Status returns the status. This field is used to determine the Message.IsQueued value.
string responsemessage = mac.ReponseStatus;

//Reponse Message returns "Queued" if successful, returns the message if unsuccessful delivery
string responsemessage = mac.ReponseMessage;

//Grab System.Exception
mac.MACException;
Accepted Response Payload
//Get the full response payload on an accepted outbound message request
AcceptedResponsePayload arp = AcceptedResponsePayload.FromJson(mac.ReponseString);
string smsid = arp.SMSId; //Generated message ID from Telnyx
Rejected Response Payload
//Get the response error details from the mac response string if message is not queued
RejectedResponsePayload rrp = RejectedResponsePayload.FromJson(mac.ReponseString);
string errormessage = err.Message;
Message Delivery Record
//Returns null if there is an exception
MessageDeliveryRecord mdr = await trc.GetMessageDeliveryRecord(msgid);
return mdr.Errors;

MIT License
2019 Bharat Bhardwaj

Release Notes

SharpNyx v0.2.4
New features
-Better MAC exception handling.
public System.Exception MACException has been added to the MAC. The async methods will no longer throw exceptions. The exception will be added to the MAC instance and can be grabbed using MACExeption.

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
0.2.4 100 6/8/2019
0.2.3 84 5/31/2019
0.2.2 67 5/30/2019
0.2.1 73 5/30/2019
0.2.0 67 5/29/2019
0.1.8 64 5/26/2019
0.1.7 72 5/25/2019
0.1.6 72 5/25/2019
0.1.5 65 5/24/2019
0.1.4 69 5/24/2019
0.1.2 69 5/24/2019
0.1.0 75 5/24/2019