Skip to content

Commit

Permalink
Merge branch 'master' into feature/voice_language_style
Browse files Browse the repository at this point in the history
  • Loading branch information
slorello89 authored Nov 19, 2020
2 parents 6070d98 + 1d75720 commit 9eea3a7
Show file tree
Hide file tree
Showing 27 changed files with 988 additions and 169 deletions.
24 changes: 15 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

Vonage Client Library for .NET
===================================

Expand Down Expand Up @@ -26,12 +27,12 @@ To install the C# client library using NuGet:
* Run the following command in the Package Manager Console:

```shell
Install-Package Vonage.Dotnet.Client
Install-Package Vonage
```

Alternatively:

* Download or build (see developer instructions) the `Vonage.Dotnet.Client.dll`.
* 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.
Expand Down Expand Up @@ -209,7 +210,7 @@ var credentials = Credentials.FromApiKeyAndSecret(

var vonageClient = new VonageClient(credentials);

var response = vonageClient.SmsClient.SendAnSms(new Vonage.Messaging.SendSmsRequest()
var response = await vonageClient.SmsClient.SendAnSmsAsync(new Vonage.Messaging.SendSmsRequest()
{
To = TO_NUMBER,
From = VONAGE_BRAND_NAME,
Expand Down Expand Up @@ -337,7 +338,7 @@ Use [Vonage's Redact API][doc_redact] 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 = client.RedactClient.Redact(request);
var response = await client.RedactClient.RedactAsync(request);
```

### Initiating a Call
Expand All @@ -351,7 +352,7 @@ var creds = Credentials.FromAppIdAndPrivateKeyPath(VONAGE_APPLICATION_ID, VONAGE
var client = new VonageClient(creds);

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

### Receiving a Call
Expand All @@ -378,7 +379,7 @@ public string Answer()
var credentials = Credentials.FromAppIdAndPrivateKeyPath(VONAGE_APPLICATION_ID, VONAGE_PRIVATE_KEY_PATH);
var client = new VonageClient(credentials);

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

### Sending 2FA Code
Expand All @@ -390,7 +391,7 @@ var credentials = Credentials.FromApiKeyAndSecret(VONAGE_API_KEY, VONAGE_API_SEC
var client = new VonageClient(credentials);

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

### Checking 2FA Code
Expand All @@ -402,7 +403,7 @@ var credentials = Credentials.FromApiKeyAndSecret(VONAGE_API_KEY, VONAGE_API_SEC
var client = new VonageClient(credentials);

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

### Additional Examples
Expand Down Expand Up @@ -437,7 +438,7 @@ The following is a list of Vonage APIs and whether the Vonage .NET SDK provides
## FAQ

Q: Does the .NET SDK Support the async pattern?
A: The .NET SDK does not support the async pattern at this time.
A: Yes

Contributing
------------
Expand All @@ -459,6 +460,11 @@ Special thanks to our contributors:
* [jonferreira](https://github.com/jonferreira)
* [fauna5](https://github.com/fauna5)
* [taylus](https://github.com/taylus)
* [smikis](https://github.com/smikis)
* [gagandeepp](https://github.com/gagandeepp)
* [kzuri](https://github.com/kzuri)
* [Parikshit-Hood](https://github.com/Parikshit-Hooda)
* [onpoc](https://github.com/onpoc)
License
-------
Expand Down
96 changes: 74 additions & 22 deletions Vonage.Test.Unit/VoiceClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Web;
using Vonage.Voice;
using Xunit;
using Vonage.Voice.Nccos.Endpoints;

namespace Vonage.Test.Unit
{
Expand All @@ -26,8 +27,8 @@ public void CreateCall(bool passCreds)

var request = new Voice.CallCommand
{
To = new[]
{
To = new[]
{
new Voice.Nccos.Endpoints.PhoneEndpoint
{
Number="14155550100",
Expand All @@ -39,14 +40,14 @@ public void CreateCall(bool passCreds)
Number = "14155550100",
DtmfAnswer = "p*123#"
},
Ncco = new Voice.Nccos.Ncco(new Voice.Nccos.TalkAction { Text="Hello World"}),
AnswerUrl = new [] { "https://example.com/answer" },
AnswerMethod="GET",
EventUrl= new[] { "https://example.com/event" },
EventMethod="POST",
MachineDetection="continue",
LengthTimer=1,
RingingTimer=1,
Ncco = new Voice.Nccos.Ncco(new Voice.Nccos.TalkAction { Text = "Hello World" }),
AnswerUrl = new[] { "https://example.com/answer" },
AnswerMethod = "GET",
EventUrl = new[] { "https://example.com/event" },
EventMethod = "POST",
MachineDetection = "continue",
LengthTimer = 1,
RingingTimer = 1,
};
var creds = Request.Credentials.FromAppIdAndPrivateKey(AppId, PrivateKey);
var client = new VonageClient(creds);
Expand All @@ -67,7 +68,7 @@ public void CreateCall(bool passCreds)

[Theory]
[InlineData(true, true)]
[InlineData(false, false)]
[InlineData(false, false)]
public void TestListCalls(bool passCreds, bool kitchenSink)
{
var expectedResponse = @"{
Expand Down Expand Up @@ -135,12 +136,12 @@ public void TestListCalls(bool passCreds, bool kitchenSink)
expectedUri = $"{ApiUrl}/v1/calls";
filter = new CallSearchFilter();
}

Setup(expectedUri, expectedResponse);

var creds = Request.Credentials.FromAppIdAndPrivateKey(AppId, PrivateKey);
var client = new VonageClient(creds);

Common.PageResponse<CallList> callList;
if (passCreds)
{
Expand Down Expand Up @@ -225,8 +226,8 @@ public void TestGetSpecificCall(bool passCreds)
else
{
callRecord = client.VoiceClient.GetCall(uuid);
}
}

Assert.Equal("63f61863-4a51-4f6b-86e1-46edebcf9356", callRecord.Uuid);
Assert.Equal("CON-f972836a-550f-45fa-956c-12a2ab5b7d22", callRecord.ConversationUuid);
Assert.Equal("447700900000", callRecord.To.Number);
Expand All @@ -247,7 +248,7 @@ public void TestGetSpecificCall(bool passCreds)

[Theory]
[InlineData(true, true, true)]
[InlineData(false, false, true )]
[InlineData(false, false, true)]
[InlineData(false, false, false)]
public void TestUpdateCall(bool passCreds, bool inlineNcco, bool testTransfer)
{
Expand Down Expand Up @@ -330,7 +331,7 @@ public void TestStartStream(bool passCreds, bool kitchenSink)
CallCommandResponse response;
if (passCreds)
{
response = client.VoiceClient.StartStream(uuid,command, creds);
response = client.VoiceClient.StartStream(uuid, command, creds);
}
else
{
Expand All @@ -352,7 +353,7 @@ public void StopStream(bool passCreds)
""uuid"": ""63f61863-4a51-4f6b-86e1-46edebcf9356""
}";

Setup(expectedUri, expectedResponse,"{}");
Setup(expectedUri, expectedResponse, "{}");

var creds = Request.Credentials.FromAppIdAndPrivateKey(AppId, PrivateKey);
var client = new VonageClient(creds);
Expand Down Expand Up @@ -464,7 +465,7 @@ public void TestStartDtmf(bool passCreds)
""uuid"": ""63f61863-4a51-4f6b-86e1-46edebcf9356""
}";
var expectedRequestContent = @"{""digits"":""1234""}";
var command = new DtmfCommand { Digits = "1234" };
var command = new DtmfCommand { Digits = "1234" };
Setup(expectedUri, expectedResponse, expectedRequestContent);

var creds = Request.Credentials.FromAppIdAndPrivateKey(AppId, PrivateKey);
Expand All @@ -490,12 +491,12 @@ public void TestGetRecordings(bool passCreds)
{
var expectedUri = $"{ApiUrl}/v1/calls/63f61863-4a51-4f6b-86e1-46edebcf9356";
var creds = Request.Credentials.FromAppIdAndPrivateKey(AppId, PrivateKey);
var expectedResponse = new byte[] { 0,1,2,3,4,5,6,7,8,9};
var expectedResponse = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
Setup(expectedUri, expectedResponse);
var client = new VonageClient(creds);

GetRecordingResponse response;
if (passCreds)
if (passCreds)
{
response = client.VoiceClient.GetRecording(expectedUri, creds);
}
Expand Down Expand Up @@ -556,5 +557,56 @@ public void CreateCallWithUnicodeCharecters()
Assert.Equal("outbound", response.Direction);
Assert.Equal("started", response.Status);
}


[Fact]
public void CreateCallWithStringParameters()
{
var expectedUri = $"{ApiUrl}/v1/calls/";
var expectedResponse = @"{
""uuid"": ""63f61863-4a51-4f6b-86e1-46edebcf9356"",
""status"": ""started"",
""direction"": ""outbound"",
""conversation_uuid"": ""CON-f972836a-550f-45fa-956c-12a2ab5b7d22""
}";
var expectedRequesetContent = @"{""to"":[{""number"":""14155550100"",""type"":""phone""}],""from"":{""number"":""14155550100"",""type"":""phone""},""ncco"":[{""text"":""Hello World"",""action"":""talk""}]}";
Setup(expectedUri, expectedResponse, expectedRequesetContent);
var creds = Request.Credentials.FromAppIdAndPrivateKey(AppId, PrivateKey);
var client = new VonageClient(creds);
Task<CallResponse> response;
response = client.VoiceClient.CreateCallAsync("14155550100", "14155550100", new Voice.Nccos.Ncco(new Voice.Nccos.TalkAction { Text = "Hello World" }));


Assert.Equal("63f61863-4a51-4f6b-86e1-46edebcf9356", response.GetAwaiter().GetResult().Uuid);
Assert.Equal("CON-f972836a-550f-45fa-956c-12a2ab5b7d22", response.GetAwaiter().GetResult().ConversationUuid);
Assert.Equal("outbound", response.GetAwaiter().GetResult().Direction);
Assert.Equal("started", response.GetAwaiter().GetResult().Status);
}

[Fact]
public void CreateCallWithEndpointAndNcco()
{
var expectedUri = $"{ApiUrl}/v1/calls/";
var expectedResponse = @"{
""uuid"": ""63f61863-4a51-4f6b-86e1-46edebcf9356"",
""status"": ""started"",
""direction"": ""outbound"",
""conversation_uuid"": ""CON-f972836a-550f-45fa-956c-12a2ab5b7d22""
}";
var expectedRequesetContent = @"{""to"":[{""number"":""14155550100"",""type"":""phone""}],""from"":{""number"":""14155550100"",""type"":""phone""},""ncco"":[{""text"":""Hello World"",""action"":""talk""}]}";
Setup(expectedUri, expectedResponse, expectedRequesetContent);
var creds = Request.Credentials.FromAppIdAndPrivateKey(AppId, PrivateKey);
var client = new VonageClient(creds);
Task<CallResponse> response;
var toEndpoint = new PhoneEndpoint() { Number = "14155550100" };
response = client.VoiceClient.CreateCallAsync(
toEndpoint, "14155550100", new Voice.Nccos.Ncco(new Voice.Nccos.TalkAction { Text = "Hello World" }));


Assert.Equal("63f61863-4a51-4f6b-86e1-46edebcf9356", response.GetAwaiter().GetResult().Uuid);
Assert.Equal("CON-f972836a-550f-45fa-956c-12a2ab5b7d22", response.GetAwaiter().GetResult().ConversationUuid);
Assert.Equal("outbound", response.GetAwaiter().GetResult().Direction);
Assert.Equal("started", response.GetAwaiter().GetResult().Status);
}
}
}
Loading

0 comments on commit 9eea3a7

Please sign in to comment.