Skip to content

Commit

Permalink
Added support for call control gather function (#77)
Browse files Browse the repository at this point in the history
* Added support for call control gather function

* Added JSON attribute

* Cleanup

---------

Co-authored-by: jeff anderson <[email protected]>
  • Loading branch information
troutkilroy and jeff anderson authored Mar 1, 2024
1 parent f0aaa41 commit 07f8674
Show file tree
Hide file tree
Showing 5 changed files with 214 additions and 0 deletions.
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; }
}
}
12 changes: 12 additions & 0 deletions src/Telnyx.net/Services/Calls/CallControl/CallControlService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class CallControlService
private readonly CallControlBridgeService callControlBridgeService;
private readonly CallControlForkStartService callControlForkStartService;
private readonly CallControlForkStopService callControlForkStopService;
private readonly CallControlGatherService callControlGatherService;
private readonly CallControlGatherUsingAudioService callControlGatherUsingAudioService;
private readonly CallControlGatherUsingSpeakService callControlGatherUsingSpeakService;
private readonly CallControlHangupService callControlHangupService;
Expand All @@ -40,6 +41,7 @@ public CallControlService()
this.callControlBridgeService = new CallControlBridgeService();
this.callControlForkStartService = new CallControlForkStartService();
this.callControlForkStopService = new CallControlForkStopService();
this.callControlGatherService = new CallControlGatherService();
this.callControlGatherUsingAudioService = new CallControlGatherUsingAudioService();
this.callControlGatherUsingSpeakService = new CallControlGatherUsingSpeakService();
this.callControlHangupService = new CallControlHangupService();
Expand Down Expand Up @@ -129,6 +131,16 @@ public virtual async Task<CallForkStopResponse> ForkStopAsync(CallControlForkSto
return await this.callControlForkStopService.CreateAsync(this.CallControlId, options, postFix, requestOptions, ct);
}

public virtual CallGatherResponse Gather(CallControlGatherOptions options, string postFix = "actions/gather", RequestOptions requestOptions = null)
{
return this.callControlGatherService.Create(this.CallControlId, options, postFix, requestOptions);
}

public virtual async Task<CallGatherResponse> GatherAsync(CallControlGatherOptions options, string postFix = "actions/gather", RequestOptions requestOptions = null, CancellationToken ct = default)
{
return await this.callControlGatherService.CreateAsync(this.CallControlId, options, postFix, requestOptions, ct);
}

public virtual CallGatherUsingAudioResponse GatherUsingAudio(CallControlGatherUsingAudioOptions options, string postFix = "actions/gather_using_audio", RequestOptions requestOptions = null)
{
return this.callControlGatherUsingAudioService.Create(this.CallControlId, options, postFix, requestOptions);
Expand Down
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; }
}
}
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);
}
}
}
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());
}
}
}

0 comments on commit 07f8674

Please sign in to comment.