Bandwidth's API docs can be found at https://dev.bandwidth.com
CSharp specific docs can be found at https://dev.bandwidth.com/sdks/csharp.html
nuget install Bandwidth.Sdk -OutputDirectory packages
*Note: This only adds the package to the disk. The packages.config or dependency file needs to be modified to add it to the project.
*Note: If you see this error System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a send.
This code may be needed System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
using Bandwidth.Standard;
//create Configuration with credentials
BandwidthClient client = new BandwidthClient.Builder()
.Environment(Bandwidth.Standard.Environment.Production)
.VoiceBasicAuthCredentials( username, password )
.MessagingBasicAuthCredentials( token, secret )
.Build();
//Select namespaced controller.
Bandwidth.Standard.Voice.Controllers.APIController voiceController = client.Voice.APIController;
Bandwidth.Standard.Messaging.Controllers.APIController msgController = client.Messaging.APIController;
using Bandwidth.Standard.Voice.Controllers;
callRequest.ApplicationId = "3-d-4-b-5";
callRequest.To="+19999999999";
callRequest.AnswerUrl= "https://test.com";
callRequest.MFrom="+17777777777";
//Be aware that the Voice Client can throw exceptions
try {
var response = voiceController.CreateCall("account.id", callRequest);
} catch (APIException e) {
WriteLine( e.Message );
} catch (IOException e) {
WriteLine( e.Message );
}
using Bandwidth.Standard.Voice.Bxml;
//Bandwidth XML (BXML) verb SpeakSenetence plays the sentence audio
SpeakSentence speakSentence = new SpeakSentence();
speakSentence.Sentence = "Hello World";
//Add the verb to a Response object
Response res = new Response();
res.Add(speakSentence);
//view the BXML
Console.write( res.ToBXML() );
using Bandwidth.Standard.Messaging;
using Bandwidth.Standard.Messaging.Controllers;
using Bandwidth.Standard.Messaging.Models;
MessageRequest msgRequest = new MessageRequest();
msgRequest.ApplicationId = applicationId;
msgRequest.MFrom = "+18888888888";
msgRequest.To = new string[1] {"9199199999"};
msgRequest.Text = "The quick brown fox jumps over a lazy dog.";
var response = msgController.CreateMessage(msgUserId, msgRequest);