All Projects → Vonage → Vonage Dotnet Sdk

Vonage / Vonage Dotnet Sdk

Licence: apache-2.0
Nexmo REST API client for .NET, ASP.NET, ASP.NET MVC written in C#. API support for SMS, Voice, Text-to-Speech, Numbers, Verify (2FA) and more.

Projects that are alternatives of or similar to Vonage Dotnet Sdk

Vonage Java Sdk
Vonage Server SDK for Java. API support for SMS, Voice, Text-to-Speech, Numbers, Verify (2FA) and more.
Stars: ✭ 75 (-1.32%)
Mutual labels:  phone, verify, voice, sms, two-factor-authentication
Vonage Node Sdk
Vonage API client for Node.js. API support for SMS, Voice, Text-to-Speech, Numbers, Verify (2FA) and more.
Stars: ✭ 323 (+325%)
Mutual labels:  phone, voice, sms, two-factor-authentication
Vonage Php Sdk Core
Vonage REST API client for PHP. API support for SMS, Voice, Text-to-Speech, Numbers, Verify (2FA) and more.
Stars: ✭ 849 (+1017.11%)
Mutual labels:  phone, voice, sms, two-factor-authentication
Vonage Ruby Sdk
Vonage REST API client for Ruby. API support for SMS, Voice, Text-to-Speech, Numbers, Verify (2FA) and more.
Stars: ✭ 203 (+167.11%)
Mutual labels:  phone, voice, sms, two-factor-authentication
Vonage Python Sdk
Vonage Server SDK for Python. API support for SMS, Voice, Text-to-Speech, Numbers, Verify (2FA) and more.
Stars: ✭ 134 (+76.32%)
Mutual labels:  phone, voice, sms, two-factor-authentication
vonage-node-code-snippets
NodeJS code examples for using Nexmo
Stars: ✭ 46 (-39.47%)
Mutual labels:  verify, sms, voice
laravel-authy
Rinvex Authy is a simple wrapper for @authy TOTP API, the best rated Two-Factor Authentication service for consumers, simplest 2fa Rest API for developers and a strong authentication platform for the enterprise.
Stars: ✭ 35 (-53.95%)
Mutual labels:  phone, sms, two-factor-authentication
Nexmo Node Code Snippets
NodeJS code examples for using Nexmo
Stars: ✭ 36 (-52.63%)
Mutual labels:  verify, voice, sms
Twilio Java
A Java library for communicating with the Twilio REST API and generating TwiML.
Stars: ✭ 371 (+388.16%)
Mutual labels:  phone, voice, sms
React Native Phone Verification
The best React Native example for phone verification (an alternative to Twitter Digits).
Stars: ✭ 332 (+336.84%)
Mutual labels:  verify, sms, two-factor-authentication
Twilio Csharp
Twilio C#/.NET Helper Library for .NET Framework 3.5+ and supported .NET Core versions
Stars: ✭ 541 (+611.84%)
Mutual labels:  phone, voice, sms
Authy
Rinvex Authy is a simple wrapper for @Authy TOTP API, the best rated Two-Factor Authentication service for consumers, simplest 2fa Rest API for developers and a strong authentication platform for the enterprise.
Stars: ✭ 34 (-55.26%)
Mutual labels:  phone, sms, two-factor-authentication
46elks-getting-started
An introduction to the 46elks API with code examples
Stars: ✭ 45 (-40.79%)
Mutual labels:  sms, voice
node-identif
🔑 Helper class to verify one's identity via personal channels(SMS, Phone, E-Mail and more!)
Stars: ✭ 27 (-64.47%)
Mutual labels:  phone, sms
PokerTexter
SMS App for Poker Odds. Runs on Flask + Twilio + Heroku.
Stars: ✭ 17 (-77.63%)
Mutual labels:  phone, sms
woapp
web模拟安卓操作系统,php开发,内置文件管理,电话,短信,拍照,用在树莓派上可做智能家居,视频监控,机顶盒等……
Stars: ✭ 22 (-71.05%)
Mutual labels:  phone, sms
node-gsm
📲 gsm modem module for node.js
Stars: ✭ 23 (-69.74%)
Mutual labels:  phone, sms
0x4447 product answering machine
☎️ An automated answering machine build on top of Amazon Connect
Stars: ✭ 38 (-50%)
Mutual labels:  phone, voice
Phone
With a given country and phone number, validate and reformat the mobile phone number to the E.164 standard. The purpose of this is to allow us to send SMS to mobile phones only.
Stars: ✭ 531 (+598.68%)
Mutual labels:  phone, sms
useful-twilio-functions
A set of useful Twilio Functions.
Stars: ✭ 53 (-30.26%)
Mutual labels:  sms, voice

Vonage Client Library for .NET

Build Status codecov Contributor Covenant

Nexmo is now known as Vonage

You can use this C# client library to integrate Vonage's APIs to your application. To use this, you'll need a Vonage API account. Sign up for free at vonage.com.

Installation

To use the client library you'll need to have created a Vonage account.

To install the C# client library using NuGet:

  • Run the following command in the Package Manager Console:
    Install-Package Vonage

Alternatively:

  • Download or build (see developer instructions) the Vonage.dll.
  • If you have downloaded a release, ensure you are referencing the required dependencies by either including them with your project's NuGet dependencies or manually referencing them.
  • Reference the assembly in your code.

Targeted frameworks

  • 4.5.2

NOTE: for 4.5.2 frameworks you will need to enable TLS 1.2 either via registry or by setting it globally - System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;

  • 4.6
  • .NET Standard 2.0 - supports everything 4.6.1 and above

Configuration:

To setup the configuration of the Vonage Client you can do one of the following.

  • Create a Vonage Client instance and pass in credentials in the constructor - this will only affect the security credentials (Api Key, Api Secret, Signing Secret, Signing Method Private Key, App Id)
var credentials = Credentials.FromApiKeyAndSecret(
    VONAGE_API_KEY,
    VONAGE_API_SECRET
    );

var vonageClient = new VonageClient(credentials);
var results = client.SMS.Send(request: new SMS.SMSRequest
var response = vonageClient.SmsClient.SendAnSms(new Vonage.Messaging.SendSmsRequest()
{
    To = TO_NUMBER,
    From = VONAGE_BRAND_NAME,
    Text = "A text message sent using the Vonage SMS API"
});

Or

  • Provide the vonage URLs, API key, secret, and application credentials (for JWT) in appsettings.json:
{
  "appSettings": {
    "Vonage.UserAgent": "myApp/1.0",
    "Vonage.Url.Rest": "https://rest.nexmo.com",
    "Vonage.Url.Api": "https://api.nexmo.com",
    "Vonage_key": "VONAGE-API-KEY",
    "Vonage_secret": "VONAGE-API-SECRET",    
    "Vonage.Application.Id": "ffffffff-ffff-ffff-ffff-ffffffffffff",
    "Vonage.Application.Key": "VONAGE_APPLICATION_PRIVATE_KEY"
  }
}

Note: In the event multiple configuration files are found, the order of precedence is as follows:

* ```appsettings.json``` which overrides
* ```settings.json```

Or

  • Access the Configuration instance and set the appropriate key in your code for example:
Configuration.Instance.Settings["appSettings:Vonage.Url.Api"] = "https://www.example.com/api";
Configuration.Instance.Settings["appSettings:Vonage.Url.Rest"] = "https://www.example.com/rest";

NOTE: Private Key is the literal key - not a path to the file containing the key

Configuration Reference

Key Description
Vonage_key Your API key from the dashboard
Vonage_secret Your API secret from the dashboard
Vonage.Application.Id Your application ID
Vonage.Application.Key Your application's private key
Vonage.security_secret Optional. This is the signing secret that's used for signing SMS
Vonage.signing_method Optional. This is the method used for signing SMS messages
Vonage.Url.Rest Optional. Vonage REST API base URL. Defaults to https://rest.nexmo.com
Vonage.Url.Api Optional. Vonage API base URL. Defaults to https://api.nexmo.com
Vonage.RequestsPerSecond Optional. Throttle to specified requests per second.
Vonage.UserAgent Optional. Your app-specific usage identifier in the format of name/version. Example: "myApp/1.0"

Logging

v5.0.0 +

The Library uses Microsoft.Extensions.Logging to preform all of it's logging tasks. To configure logging for you app simply create a new ILoggerFactory and call the LogProvider.SetLogFactory() method to tell the Vonage library how to log. For example, to log to the console with serilog you can do the following:

using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Configuration;
using Vonage.Logger;
using Serilog;

var log = new LoggerConfiguration()
    .MinimumLevel.Debug()
    .WriteTo.Console(outputTemplate: "{Timestamp:HH:mm} [{Level}]: {Message}\n")
    .CreateLogger();
var factory = new LoggerFactory();
factory.AddSerilog(log);
LogProvider.SetLogFactory(factory);

[3.1.x, 5.0.0)

The library makes use of LibLog to facilitate logging.

Your application controls if and how logging occurs. Example using Serilog and Serilog.Sinks.Console v3.x:

using Vonage.Request;
using Serilog;

// set up logging at startup
var log = new LoggerConfiguration()
  .MinimumLevel.Debug()
  .WriteTo.Console(outputTemplate: "{Timestamp:HH:mm} [{Level}] ({Name:l}) {Message}")
  .CreateLogger();
Log.Logger = log;

Log.Logger.Debug("start");
var client = new Vonage.VonageClient(new Credentials("example", "password"));
client.Account.GetBalance();
Log.Logger.Debug("end");

2.2.0 - 3.0.x

You can request console logging by placing a logging.json file alongside your appsettings.json configuration.

Note that logging Vonage messages will very likely expose your key and secret to the console as they can be part of the query string.

Example logging.json contents that would log all requests as well as major configuration and authentication errors:

{
  "IncludeScopes": "true",
  "LogLevel": {
    "Default": "Debug",
    "Vonage": "Debug",
    "Vonage.Authentication": "Error",
    "Vonage.Configuration": "Error"
  }
}

You may specify other types of logging (file, etc.).

Examples

We are working on a separate repository for .NET examples. Check it out here!

The following examples show how to:

Sending a Message

Use Vonage's SMS API to send an SMS message.

var credentials = Credentials.FromApiKeyAndSecret(
    VONAGE_API_KEY,
    VONAGE_API_SECRET
    );

var vonageClient = new VonageClient(credentials);

var response = await vonageClient.SmsClient.SendAnSmsAsync(new Vonage.Messaging.SendSmsRequest()
{
    To = TO_NUMBER,
    From = VONAGE_BRAND_NAME,
    Text = "A text message sent using the Vonage SMS API"
});

Receiving a Message

Use Vonage's SMS API to receive an SMS message. Assumes your Vonage webhook endpoint is configured.

The best method for receiving an SMS will vary depending on whether you configure your webhooks to be GET or POST. Will Also Vary between ASP.NET MVC and ASP.NET MVC Core.

ASP.NET MVC Core

GET
[HttpGet("webhooks/inbound-sms")]
public async Task<IActionResult> InboundSmsGet()
{
    var inbound = Vonage.Utility.WebhookParser.ParseQuery<InboundSms>(Request.Query);
    return NoContent();
}
POST
[HttpPost("webhooks/inbound-sms")]
public async Task<IActionResult> InboundSms()
{
    var inbound = await Vonage.Utility.WebhookParser.ParseWebhookAsync<InboundSms>(Request.Body, Request.ContentType);
    return NoContent();
}

ASP.NET MVC

GET
[HttpGet]
[Route("webhooks/inbound-sms")]
public async Task<HttpResponseMessage> GetInbound()
{
    var inboundSms = WebhookParser.ParseQueryNameValuePairs<InboundSms>(Request.GetQueryNameValuePairs());
    return new HttpResponseMessage(HttpStatusCode.NoContent);
}
POST
[HttpPost]
[Route("webhooks/inbound-sms")]
public async Task<HttpResponseMessage> PostInbound()
{
    var inboundSms = WebhookParser.ParseWebhook<InboundSms>(Request);
    return new HttpResponseMessage(HttpStatusCode.NoContent);
}

Receiving a Message Delivery Receipt

Use Vonage's SMS API to receive an SMS delivery receipt. Assumes your Vonage webhook endpoint is configured.

The best method for receiving an SMS will vary depending on whether you configure your webhooks to be GET or POST. Will Also Vary between ASP.NET MVC and ASP.NET MVC Core.

ASP.NET MVC Core

GET
[HttpGet("webhooks/dlr")]
public async Task<IActionResult> InboundSmsGet()
{
    var dlr = Vonage.Utility.WebhookParser.ParseQuery<DeliveryReceipt>(Request.Query);
    return NoContent();
}
POST
[HttpPost("webhooks/dlr")]
public async Task<IActionResult> InboundSms()
{
    var dlr = await Vonage.Utility.WebhookParser.ParseWebhookAsync<DeliveryReceipt>(Request.Body, Request.ContentType);
    return NoContent();
}

ASP.NET MVC

GET
[HttpGet]
[Route("webhooks/dlr")]
public async Task<HttpResponseMessage> GetInbound()
{
    var dlr = WebhookParser.ParseQueryNameValuePairs<DeliveryReceipt>(Request.GetQueryNameValuePairs());
    return new HttpResponseMessage(HttpStatusCode.NoContent);
}
POST
[HttpPost]
[Route("webhooks/dlr")]
public async Task<HttpResponseMessage> PostInbound()
{
    var dlr = WebhookParser.ParseWebhook<DeliveryReceipt>(Request);
    return new HttpResponseMessage(HttpStatusCode.NoContent);
}

Redacting a message

Use Vonage's Redact API to redact a SMS message.

var credentials = Credentials.FromApiKeyAndSecret(VONAGE_API_KEY, VONAGE_API_SECRET);
var client = new VonageClient(credentials);
var request = new RedactRequest() { Id = VONAGE_REDACT_ID, Type = VONAGE_REDACT_TYPE, Product = VONAGE_REDACT_PRODUCT };
var response = await client.RedactClient.RedactAsync(request);

Initiating a Call

Use Vonage's Voice API to initiate a voice call.

NOTE: You must have a valid Application ID and private key in order to make voice calls. Use either Vonage.Application or Vonage's Node.js-based CLI tool to register. See the Application API documentation for details.

var creds = Credentials.FromAppIdAndPrivateKeyPath(VONAGE_APPLICATION_ID, VONAGE_PRIVATE_KEY_PATH);
var client = new VonageClient(creds);

var command = new CallCommand() { To = new Endpoint[] { toEndpoint }, From = fromEndpoint, AnswerUrl=new[] { ANSWER_URL}};
var response = await client.VoiceClient.CreateCallAsync(command);

Receiving a Call

Use Vonage's Voice API to receive a voice call.

[HttpGet("webhooks/answer")]
public string Answer()
{
    var talkAction = new TalkAction()
    {
        Text = $"Thank you for calling from " +
        $"{string.Join(" ", Request.Query["from"].ToString().ToCharArray())}"
    };
    var ncco = new Ncco(talkAction);
    return ncco.ToString();
}

Get Details About a Call

var credentials = Credentials.FromAppIdAndPrivateKeyPath(VONAGE_APPLICATION_ID, VONAGE_PRIVATE_KEY_PATH);
var client = new VonageClient(credentials);

var response = await client.VoiceClient.GetCallAsync(UUID);

Sending 2FA Code

Use Vonage's Verify API to send 2FA pin code.

var credentials = Credentials.FromApiKeyAndSecret(VONAGE_API_KEY, VONAGE_API_SECRET);
var client = new VonageClient(credentials);

var request = new VerifyRequest() { Brand = BRAND_NAME, Number = RECIPIENT_NUMBER };
var response = await client.VerifyClient.VerifyRequestAsync(request);

Checking 2FA Code

Use Vonage's Verify API to check 2FA pin code.

var credentials = Credentials.FromApiKeyAndSecret(VONAGE_API_KEY, VONAGE_API_SECRET);
var client = new VonageClient(credentials);

var request = new VerifyCheckRequest() { Code = CODE, RequestId = REQUEST_ID };
var response = await client.VerifyClient.VerifyCheckAsync(request);

Additional Examples

  • Check out the sample MVC application and tests for more examples. Make sure to copy appsettings.json.example to appsettings.json and enter your key/secret.

Supported APIs

The following is a list of Vonage APIs and whether the Vonage .NET SDK provides support for them:

API API Release Status Supported?
Account API General Availability
Alerts API General Availability
Application API General Availability
Audit API Beta
Conversation API Beta
Dispatch API Beta
External Accounts API Beta
Media API Beta
Messages API Beta
Number Insight API General Availability
Number Management API General Availability
Pricing API General Availability
Redact API Developer Preview
Reports API Beta
SMS API General Availability
Verify API General Availability
Voice API General Availability

FAQ

Q: Does the .NET SDK Support the async pattern? A: Yes

Contributing

Visual Studio 2017 is required (Community is fine). v15.5+ is recommended.

  1. Get the latest code either by cloning the repository or downloading a snapshot of the source.
  2. Open "Vonage.sln"
  3. Build! NuGet dependencies should be brought down automatically; check your settings if they are not.

Pull requests are welcome!

Thanks

Special thanks to our contributors:

License

This library is released under the MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].