-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for call control gather function (#77)
* Added support for call control gather function * Added JSON attribute * Cleanup --------- Co-authored-by: jeff anderson <[email protected]>
- Loading branch information
1 parent
f0aaa41
commit 07f8674
Showing
5 changed files
with
214 additions
and
0 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
src/Telnyx.net/Entities/Calls/CallControl/Gather/CallGatherResponse.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
namespace Telnyx | ||
{ | ||
using System.Runtime.Serialization; | ||
using Newtonsoft.Json; | ||
|
||
/// <summary> | ||
/// Gather Response. | ||
/// </summary> | ||
public class CallGatherResponse : TelnyxEntity | ||
{ | ||
/// <summary> | ||
/// The status of the Call. | ||
/// </summary> | ||
/// <value> Status of the Call.</value> | ||
[JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))] | ||
public enum ResultEnum | ||
{ | ||
/// <summary> | ||
/// Enum PendingEnum for answered | ||
/// </summary> | ||
[EnumMember(Value = "ok")] | ||
Success = 0, | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets destination number or SIP URI of the call. | ||
/// </summary> | ||
[JsonProperty("result")] | ||
public ResultEnum? Result { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
src/Telnyx.net/Services/Calls/CallControl/Gather/CallControlGatherOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
namespace Telnyx | ||
{ | ||
using System; | ||
using Newtonsoft.Json; | ||
|
||
/// <summary> | ||
/// CallControlGatherUsingSpeakCreateOptions. | ||
/// </summary> | ||
public class CallControlGatherOptions : BaseOptions | ||
{ | ||
/// <summary> | ||
/// Gets or sets the minimum number of digits to fetch. This parameter has a minimum value of 1. | ||
/// Default: 1. | ||
/// </summary> | ||
[JsonProperty("minimum_digits")] | ||
public int MinimumDigits { get; set; } = 1; | ||
|
||
/// <summary> | ||
/// Gets or sets the maximum number of digits to fetch. This parameter has a maximum value of 128. | ||
/// Default: 128. | ||
/// </summary> | ||
[JsonProperty("maximum_digits")] | ||
public int MaximumDigits { get; set; } = 128; | ||
|
||
/// <summary> | ||
/// Gets or sets the number of milliseconds to wait to complete the request. | ||
/// Default: 60000. | ||
/// </summary> | ||
[JsonProperty("timeout_millis")] | ||
public int TimeoutMillis { get; set; } = 60000; | ||
|
||
/// <summary> | ||
/// Gets or sets the digit used to terminate input if fewer than maximum_digits digits have been gathered. | ||
/// Default: "#". | ||
/// </summary> | ||
[JsonProperty("terminating_digit")] | ||
public string TerminatingDigit { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets a list of all digits accepted as valid. | ||
/// Default: "0123456789#*". | ||
/// </summary> | ||
[JsonProperty("valid_digits")] | ||
public string ValidDigits { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the number of milliseconds to wait for input between digits. | ||
/// Default: 5000. | ||
/// </summary> | ||
[JsonProperty("inter_digit_timeout_millis")] | ||
public int InterDigitTimeoutMillis { get; set; } = 5000; | ||
|
||
/// <summary> | ||
/// Gets or sets the number of milliseconds to wait for the first DTMF. | ||
/// Default: 5000. | ||
/// </summary> | ||
/// | ||
[JsonProperty("initial_timeout_millis")] | ||
public int InitialTimeoutMillis { get; set; } = 5000; | ||
|
||
/// <summary> | ||
/// Gets or sets use this field to add state to every subsequent webhook. It must be a valid Base-64 encoded string. | ||
/// </summary> | ||
[JsonProperty("client_state")] | ||
public string ClientState { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets use this field to avoid duplicate commands. Telnyx will ignore commands with the same. | ||
/// </summary> | ||
[JsonProperty("command_id")] | ||
public Guid? CommandId { get; set; } | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/Telnyx.net/Services/Calls/CallControl/Gather/CallControlGatherService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
namespace Telnyx | ||
{ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
/// <summary> | ||
/// CallControlGatherService. | ||
/// </summary> | ||
public class CallControlGatherService : Service<CallGatherResponse>, | ||
INestedCreatableWithIdInMid<CallGatherResponse, CallControlGatherOptions> | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="CallControlGatherService"/> class. | ||
/// </summary> | ||
public CallControlGatherService() | ||
: base(null) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="CallControlGatherService"/> class. | ||
/// </summary> | ||
/// <param name="apiKey">api key.</param> | ||
public CallControlGatherService(string apiKey) | ||
: base(apiKey) | ||
{ | ||
} | ||
|
||
/// <inheritdoc/> | ||
public override string BasePath => "/calls"; | ||
|
||
/// <inheritdoc/> | ||
public virtual CallGatherResponse Create(string id, CallControlGatherOptions options, string postFix = "actions/gather", RequestOptions requestOptions = null) | ||
{ | ||
return this.CreateEntity(id, postFix, options, requestOptions, string.Empty); | ||
} | ||
|
||
/// <inheritdoc/> | ||
public async Task<CallGatherResponse> CreateAsync(string parentId, CallControlGatherOptions createOptions, string postFix = "actions/gather", RequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken)) | ||
{ | ||
return await this.CreateEntityAsync(parentId, postFix, createOptions, requestOptions, string.Empty, cancellationToken); | ||
} | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
src/TelnyxTests/Services/Calls/CallControl/Gather/CallControlGatherTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// <copyright file="CallControlGatherTest.cs" company="Telnyx"> | ||
// Copyright (c) Telnyx. All rights reserved. | ||
// </copyright> | ||
|
||
namespace TelnyxTests.Services.Calls.CallCommands | ||
{ | ||
using System.Threading.Tasks; | ||
using Telnyx; | ||
using Xunit; | ||
|
||
public class CallControlGatherTest : BaseTelnyxTest | ||
{ | ||
private const string CallControllId = "call_123"; | ||
|
||
private readonly CallControlGatherService service; | ||
private readonly CallControlGatherOptions createOptions; | ||
|
||
public CallControlGatherTest(MockHttpClientFixture mockHttpClientFixture) | ||
: base(mockHttpClientFixture) | ||
{ | ||
this.service = new CallControlGatherService(); | ||
|
||
this.createOptions = new CallControlGatherOptions() | ||
{ | ||
ClientState = "aGF2ZSBhIG5pY2UgZGF5ID1d", | ||
CommandId = new System.Guid("891510ac-f3e4-11e8-af5b-de00688a4901"), | ||
InterDigitTimeoutMillis = 5000, | ||
TimeoutMillis = 60000, | ||
ValidDigits = "123", | ||
TerminatingDigit = "#", | ||
MaximumDigits = 10, | ||
MinimumDigits = 1, | ||
}; | ||
} | ||
|
||
[Fact] | ||
public void Create() | ||
{ | ||
var message = this.service.Create(CallControllId, this.createOptions); | ||
//this.AssertRequest(HttpMethod.Post, $"/v2/calls/{CallControllId}/actions/gather"); | ||
Assert.NotNull(message); | ||
Assert.Equal(typeof(CallGatherUsingAudioResponse), message.GetType()); | ||
} | ||
|
||
[Fact] | ||
public async Task CreateAsync() | ||
{ | ||
var message = await this.service.CreateAsync(CallControllId, this.createOptions); | ||
//this.AssertRequest(HttpMethod.Post, $"/v2/calls/{CallControllId}/actions/gather"); | ||
Assert.NotNull(message); | ||
Assert.Equal(typeof(CallGatherUsingAudioResponse), message.GetType()); | ||
} | ||
} | ||
} |