Skip to content

Commit

Permalink
refactor: [breaking] remove obsolete Input from webhooks
Browse files Browse the repository at this point in the history
  • Loading branch information
Tr00d committed Mar 14, 2024
1 parent 70428e7 commit d166b59
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 70 deletions.
24 changes: 0 additions & 24 deletions Vonage.Test/WebhookStructsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -269,30 +269,6 @@ public void TestHumanMachine(string type)
DateTimeStyles.AdjustToUniversal), humanMachineWebhook.TimeStamp);
}

[Fact]
public void TestInputOld()
{
var json = @"
{
""from"":""442079460000"",
""to"":""447700900000"",
""uuid"":""aaaaaaaa-bbbb-cccc-dddd-0123456789ab"",
""conversation_uuid"":""CON-aaaaaaaa-bbbb-cccc-dddd-0123456789ab"",
""dtmf"":""42"",
""timed_out"":""true"",
""timestamp"":""2020-01-01T12:00:00.000Z""
}";
var inputWebhook = (Input) EventBase.ParseEvent(json);
Assert.Equal("442079460000", inputWebhook.From);
Assert.Equal("447700900000", inputWebhook.To);
Assert.Equal("42", inputWebhook.Dtmf);
Assert.Equal("aaaaaaaa-bbbb-cccc-dddd-0123456789ab", inputWebhook.Uuid);
Assert.Equal("CON-aaaaaaaa-bbbb-cccc-dddd-0123456789ab", inputWebhook.ConversationUuid);
Assert.Equal(DateTime.ParseExact("2020-01-01T12:00:00.000Z", "yyyy-MM-dd'T'HH:mm:ss.fff'Z'",
CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal |
DateTimeStyles.AdjustToUniversal), inputWebhook.TimeStamp);
}

[Fact]
public void TestNotifications()
{
Expand Down
11 changes: 5 additions & 6 deletions Vonage/Voice/EventWebhooks/EventBase.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Newtonsoft.Json;
using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using Vonage.Serialization;

namespace Vonage.Voice.EventWebhooks;
Expand All @@ -15,8 +15,7 @@ public class EventBase

public static EventBase ParseEvent(string json)
{
var data = (JObject)JsonConvert.DeserializeObject(json);

var data = (JObject) JsonConvert.DeserializeObject(json);
if (data.Property("status") != null)
{
return DeserializeStatus(json, data.Property("status"));
Expand All @@ -36,7 +35,7 @@ public static EventBase ParseEvent(string json)
{
if (data["dtmf"].Type == JTokenType.String)
{
return JsonConvert.DeserializeObject<Input>(json, VonageSerialization.SerializerSettings);
return JsonConvert.DeserializeObject<MultiInput>(json, VonageSerialization.SerializerSettings);
}

return JsonConvert.DeserializeObject<MultiInput>(json, VonageSerialization.SerializerSettings);
Expand All @@ -57,7 +56,7 @@ public static EventBase ParseEvent(string json)

private static EventBase DeserializeStatus(string json, JProperty statusProperty)
{
var status = ((string)statusProperty.Value).ToLower();
var status = ((string) statusProperty.Value).ToLower();
switch (status)
{
case "started":
Expand Down
38 changes: 0 additions & 38 deletions Vonage/Voice/EventWebhooks/Input.cs

This file was deleted.

31 changes: 29 additions & 2 deletions Vonage/Voice/EventWebhooks/MultiInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,44 @@

namespace Vonage.Voice.EventWebhooks;

public class MultiInput : Input
public class MultiInput : Event
{
/// <summary>
/// Result of Dtmf input
/// </summary>
[JsonProperty("dtmf")]
public new DtmfResult Dtmf { get; set; }
public DtmfResult Dtmf { get; set; }

/// <summary>
/// Result of the speech recognition
/// </summary>
[JsonProperty("speech")]
public SpeechResult Speech { get; set; }

/// <summary>
/// The buttons pressed by the user
/// </summary>
/// <summary>
/// Whether the input action timed out: true if it did, false if not
/// </summary>
[JsonProperty("timed_out")]
public bool TimedOut { get; set; }

/// <summary>
/// The unique identifier for this conversation
/// </summary>
[JsonProperty("conversation_uuid")]
public string ConversationUuid { get; set; }

/// <summary>
/// The number the call came from
/// </summary>
[JsonProperty("from")]
public string From { get; set; }

/// <summary>
/// The number the call was made to
/// </summary>
[JsonProperty("to")]
public string To { get; set; }
}

0 comments on commit d166b59

Please sign in to comment.