Skip to content

Commit

Permalink
Merge pull request #43 from Bandwidth/DX-2404
Browse files Browse the repository at this point in the history
DX-2404 Update `CallCallback` model to machineDetectionComplete
  • Loading branch information
ajrice6713 authored Feb 2, 2022
2 parents cbb3c9f + 54556dc commit 371cb62
Show file tree
Hide file tree
Showing 4 changed files with 195 additions and 4 deletions.
22 changes: 19 additions & 3 deletions Bandwidth.Standard/Voice/Models/CallCallback.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public CallCallback()
/// <param name="terminatingDigit">terminatingDigit.</param>
/// <param name="transcription">transcription.</param>
/// <param name="diversion">diversion.</param>
/// <param name="machineDetectionResult">machineDetectionResult.</param>
public CallCallback(
string eventType = null,
string eventTime = null,
Expand Down Expand Up @@ -90,7 +91,8 @@ public CallCallback(
string digits = null,
string terminatingDigit = null,
Models.Transcription transcription = null,
Models.Diversion diversion = null)
Models.Diversion diversion = null,
Models.MachineDetectionResult machineDetectionResult = null)
{
this.EventType = eventType;
this.EventTime = eventTime;
Expand Down Expand Up @@ -122,6 +124,7 @@ public CallCallback(
this.TerminatingDigit = terminatingDigit;
this.Transcription = transcription;
this.Diversion = diversion;
this.MachineDetectionResult = machineDetectionResult;
}

/// <summary>
Expand Down Expand Up @@ -304,6 +307,12 @@ public CallCallback(
[JsonProperty("diversion", NullValueHandling = NullValueHandling.Ignore)]
public Models.Diversion Diversion { get; set; }

/// <summary>
/// Gets or sets MachineDetectionResult.
/// </summary>
[JsonProperty("machineDetectionResult", NullValueHandling = NullValueHandling.Ignore)]
public Models.MachineDetectionResult MachineDetectionResult { get; set; }

/// <inheritdoc/>
public override string ToString()
{
Expand Down Expand Up @@ -357,7 +366,8 @@ public override bool Equals(object obj)
((this.Digits == null && other.Digits == null) || (this.Digits?.Equals(other.Digits) == true)) &&
((this.TerminatingDigit == null && other.TerminatingDigit == null) || (this.TerminatingDigit?.Equals(other.TerminatingDigit) == true)) &&
((this.Transcription == null && other.Transcription == null) || (this.Transcription?.Equals(other.Transcription) == true)) &&
((this.Diversion == null && other.Diversion == null) || (this.Diversion?.Equals(other.Diversion) == true));
((this.Diversion == null && other.Diversion == null) || (this.Diversion?.Equals(other.Diversion) == true)) &&
((this.MachineDetectionResult == null && other.MachineDetectionResult == null) || (this.MachineDetectionResult?.Equals(other.MachineDetectionResult) == true));
}

/// <inheritdoc/>
Expand Down Expand Up @@ -515,6 +525,11 @@ public override int GetHashCode()
hashCode += this.Diversion.GetHashCode();
}

if (this.MachineDetectionResult != null)
{
hashCode += this.MachineDetectionResult.GetHashCode();
}

return hashCode;
}

Expand Down Expand Up @@ -554,6 +569,7 @@ protected void ToString(List<string> toStringOutput)
toStringOutput.Add($"this.TerminatingDigit = {(this.TerminatingDigit == null ? "null" : this.TerminatingDigit == string.Empty ? "" : this.TerminatingDigit)}");
toStringOutput.Add($"this.Transcription = {(this.Transcription == null ? "null" : this.Transcription.ToString())}");
toStringOutput.Add($"this.Diversion = {(this.Diversion == null ? "null" : this.Diversion.ToString())}");
toStringOutput.Add($"this.MachineDetectionResult = {(this.MachineDetectionResult == null ? "null" : this.MachineDetectionResult.ToString())}");
}
}
}
}
101 changes: 101 additions & 0 deletions Bandwidth.Standard/Voice/Models/MachineDetectionResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// <copyright file="Diversion.cs" company="APIMatic">
// Copyright (c) APIMatic. All rights reserved.
// </copyright>
namespace Bandwidth.Standard.Voice.Models
{
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Bandwidth.Standard;
using Bandwidth.Standard.Utilities;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

/// <summary>
/// Diversion.
/// </summary>
public class MachineDetectionResult
{
/// <summary>
/// Initializes a new instance of the <see cref="MachineDetectionResult"/> class.
/// </summary>
public MachineDetectionResult()
{
}

/// <summary>
/// Initializes a new instance of the <see cref="MachineDetectionResult"/> class.
/// </summary>
/// <param name="value">value.</param>
/// <param name="duration">duration.</param>
public MachineDetectionResult(
string value = null,
string duration = null)
{
this.Value = value;
this.Duration = duration;
}

/// <summary>
/// Gets or sets Value.
/// </summary>
[JsonProperty("value", NullValueHandling = NullValueHandling.Ignore)]
public string Value { get; set; }

/// <summary>
/// Gets or sets Duration.
/// </summary>
[JsonProperty("duration", NullValueHandling = NullValueHandling.Ignore)]
public string Duration { get; set; }

/// <inheritdoc/>
public override bool Equals(object obj)
{
if (obj == null)
{
return false;
}

if (obj == this)
{
return true;
}

return obj is MachineDetectionResult other &&
((this.Value == null && other.Value == null) || (this.Value?.Equals(other.Value) == true)) &&
((this.Duration == null && other.Duration == null) || (this.Duration?.Equals(other.Duration) == true));
}

/// <inheritdoc/>
public override int GetHashCode()
{
int hashCode = 2065332573;

if (this.Value != null)
{
hashCode += this.Value.GetHashCode();
}

if (this.Duration != null)
{
hashCode += this.Duration.GetHashCode();
}

return hashCode;
}

/// <summary>
/// ToString overload.
/// </summary>
/// <param name="toStringOutput">List of strings.</param>
protected void ToString(List<string> toStringOutput)
{
toStringOutput.Add($"this.Value = {(this.Value == null ? "null" : this.Value == string.Empty ? "" : this.Value)}");
toStringOutput.Add($"this.Duration = {(this.Duration == null ? "null" : this.Duration == string.Empty ? "" : this.Duration)}");
}
}
}
74 changes: 74 additions & 0 deletions Bandwidth.StandardTests/Voice/CallCallbackUnitTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using System;
using System.Threading.Tasks;
using Bandwidth.Standard;
using Bandwidth.Standard.Voice.Exceptions;
using Bandwidth.Standard.Voice.Models;
using Xunit;

namespace Bandwidth.StandardTests.Voice
{
public class CallCallbackUnitTest
{
[Fact]
public void InitiateEvent()
{
var initiateEvent = new CallCallback()
{
EventType = "initiate",
EventTime = "2019-06-20T15:56:11.554Z",
AccountId = "55555555",
ApplicationId = "7fc9698a-b04a-468b-9e8f-91238c0d0086",
From = "+15551112222",
To = "+15553334444",
Direction = "inbound",
CallId = "c-95ac8d6e-1a31c52e-b38f-4198-93c1-51633ec68f8d",
CallUrl = "https://voice.bandwidth.com/api/v2/accounts/55555555/calls/c-95ac8d6e-1a31c52e-b38f-4198-93c1-51633ec68f8d",
StartTime = "2019-06-20T15:54:22.234Z"
};

Assert.Equal("initiate", initiateEvent.EventType);
Assert.Equal("2019-06-20T15:56:11.554Z", initiateEvent.EventTime);
Assert.Equal("55555555", initiateEvent.AccountId);
Assert.Equal("7fc9698a-b04a-468b-9e8f-91238c0d0086", initiateEvent.ApplicationId);
Assert.Equal("+15551112222", initiateEvent.From);
Assert.Equal("+15553334444", initiateEvent.To);
Assert.Equal("inbound", initiateEvent.Direction);
Assert.Equal("c-95ac8d6e-1a31c52e-b38f-4198-93c1-51633ec68f8d", initiateEvent.CallId);
Assert.Equal("https://voice.bandwidth.com/api/v2/accounts/55555555/calls/c-95ac8d6e-1a31c52e-b38f-4198-93c1-51633ec68f8d", initiateEvent.CallUrl);
Assert.Equal("2019-06-20T15:54:22.234Z", initiateEvent.StartTime);
}

[Fact]
public void MachineDetectionCompleteEvent()
{
var machineDetectionCompleteEvent = new CallCallback()
{
EventType = "machineDetectionComplete",
EventTime = "2019-06-20T15:56:11.554Z",
AccountId = "55555555",
ApplicationId = "7fc9698a-b04a-468b-9e8f-91238c0d0086",
From = "+15551112222",
To = "+15553334444",
Direction = "inbound",
CallId = "c-6a0d8e3e-1c71aa98-fb05-46ca-acf8-f735db20fa28",
CallUrl = "https://voice.bandwidth.com/api/v2/accounts/55555555/calls/c-6a0d8e3e-1c71aa98-fb05-46ca-acf8-f735db20fa28",
AnswerTime = "2019-06-20T15:54:22.234Z",
MachineDetectionResult = new MachineDetectionResult() {Value = "answering-machine", Duration = "PT4.9891287S"}
};

Assert.Equal("machineDetectionComplete", machineDetectionCompleteEvent.EventType);
Assert.Equal("2019-06-20T15:56:11.554Z", machineDetectionCompleteEvent.EventTime);
Assert.Equal("55555555", machineDetectionCompleteEvent.AccountId);
Assert.Equal("7fc9698a-b04a-468b-9e8f-91238c0d0086", machineDetectionCompleteEvent.ApplicationId);
Assert.Equal("+15551112222", machineDetectionCompleteEvent.From);
Assert.Equal("+15553334444", machineDetectionCompleteEvent.To);
Assert.Equal("inbound", machineDetectionCompleteEvent.Direction);
Assert.Equal("c-6a0d8e3e-1c71aa98-fb05-46ca-acf8-f735db20fa28", machineDetectionCompleteEvent.CallId);
Assert.Equal("https://voice.bandwidth.com/api/v2/accounts/55555555/calls/c-6a0d8e3e-1c71aa98-fb05-46ca-acf8-f735db20fa28", machineDetectionCompleteEvent.CallUrl);
Assert.Equal("2019-06-20T15:54:22.234Z", machineDetectionCompleteEvent.AnswerTime);
Assert.Equal("answering-machine", machineDetectionCompleteEvent.MachineDetectionResult.Value);
Assert.Equal("PT4.9891287S", machineDetectionCompleteEvent.MachineDetectionResult.Duration);
}
}

}
2 changes: 1 addition & 1 deletion Bandwidth.StandardTests/Voice/CreateCallTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,4 @@ public async Task CreateCallInvalidFromPhoneNumberThrows()
Assert.Equal("Something's not quite right... Your request is invalid. Please fix it before trying again.", ex.Message);
}
}
}
}

0 comments on commit 371cb62

Please sign in to comment.