Skip to content

Commit

Permalink
fix: application deserialization with Meetings custom webhooks (#532)
Browse files Browse the repository at this point in the history
* Fix Application deserialization with Meetings custom webhooks

* Add missing assertions
  • Loading branch information
Tr00d authored Oct 10, 2023
1 parent 305a1a9 commit 9166a02
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 79 deletions.
118 changes: 39 additions & 79 deletions Vonage.Test.Unit/ApplicationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,21 @@ public void CreateApplication(bool passCreds)
//ACT
var messagesWebhooks = new Dictionary<Webhook.Type, Webhook>();
messagesWebhooks.Add(Webhook.Type.InboundUrl,
new Webhook {Address = "https://example.com/webhooks/inbound", Method = "POST"});
new Webhook { Address = "https://example.com/webhooks/inbound", Method = "POST" });
messagesWebhooks.Add(Webhook.Type.StatusUrl,
new Webhook {Address = "https://example.com/webhooks/status", Method = "POST"});
new Webhook { Address = "https://example.com/webhooks/status", Method = "POST" });
var messagesCapability = new Applications.Capabilities.Messages(messagesWebhooks);
var rtcWebhooks = new Dictionary<Webhook.Type, Webhook>();
rtcWebhooks.Add(Webhook.Type.EventUrl,
new Webhook {Address = "https://example.com/webhooks/events", Method = "POST"});
new Webhook { Address = "https://example.com/webhooks/events", Method = "POST" });
var rtcCapability = new Rtc(rtcWebhooks);
var voiceWebhooks = new Dictionary<Webhook.Type, Webhook>();
voiceWebhooks.Add(Webhook.Type.AnswerUrl,
new Webhook {Address = "https://example.com/webhooks/answer", Method = "GET"});
new Webhook { Address = "https://example.com/webhooks/answer", Method = "GET" });
voiceWebhooks.Add(Webhook.Type.EventUrl,
new Webhook {Address = "https://example.com/webhooks/events", Method = "POST"});
new Webhook { Address = "https://example.com/webhooks/events", Method = "POST" });
voiceWebhooks.Add(Webhook.Type.FallbackAnswerUrl,
new Webhook {Address = "https://fallback.example.com/webhooks/answer", Method = "GET"});
new Webhook { Address = "https://fallback.example.com/webhooks/answer", Method = "GET" });
var voiceCapability = new Applications.Capabilities.Voice(voiceWebhooks);
JsonConvert.SerializeObject(voiceCapability, VonageSerialization.SerializerSettings);
var vbcCapability = new Vbc();
Expand Down Expand Up @@ -154,32 +154,32 @@ public async void CreateApplicationAsync(bool passCreds)
//ACT
var messagesWebhooks = new Dictionary<Webhook.Type, Webhook>();
messagesWebhooks.Add(Webhook.Type.InboundUrl,
new Webhook {Address = "https://example.com/webhooks/inbound", Method = "POST"});
new Webhook { Address = "https://example.com/webhooks/inbound", Method = "POST" });
messagesWebhooks.Add(Webhook.Type.StatusUrl,
new Webhook {Address = "https://example.com/webhooks/status", Method = "POST"});
new Webhook { Address = "https://example.com/webhooks/status", Method = "POST" });
var messagesCapability = new Applications.Capabilities.Messages(messagesWebhooks);
var rtcWebhooks = new Dictionary<Webhook.Type, Webhook>();
rtcWebhooks.Add(Webhook.Type.EventUrl,
new Webhook {Address = "https://example.com/webhooks/events", Method = "POST"});
new Webhook { Address = "https://example.com/webhooks/events", Method = "POST" });
var rtcCapability = new Rtc(rtcWebhooks);
var voiceWebhooks = new Dictionary<Webhook.Type, Webhook>();
voiceWebhooks.Add(Webhook.Type.AnswerUrl,
new Webhook {Address = "https://example.com/webhooks/answer", Method = "GET"});
new Webhook { Address = "https://example.com/webhooks/answer", Method = "GET" });
voiceWebhooks.Add(Webhook.Type.EventUrl,
new Webhook {Address = "https://example.com/webhooks/events", Method = "POST"});
new Webhook { Address = "https://example.com/webhooks/events", Method = "POST" });
voiceWebhooks.Add(Webhook.Type.FallbackAnswerUrl,
new Webhook {Address = "https://fallback.example.com/webhooks/answer", Method = "GET"});
new Webhook { Address = "https://fallback.example.com/webhooks/answer", Method = "GET" });
var voiceCapability = new Applications.Capabilities.Voice(voiceWebhooks);
JsonConvert.SerializeObject(voiceCapability);
var vbcCapability = new Vbc();
var capabilities = new ApplicationCapabilities
{Messages = messagesCapability, Rtc = rtcCapability, Voice = voiceCapability, Vbc = vbcCapability};
{ Messages = messagesCapability, Rtc = rtcCapability, Voice = voiceCapability, Vbc = vbcCapability };
var keys = new Keys
{
PublicKey = PublicKey,
};
var request = new CreateApplicationRequest
{Capabilities = capabilities, Keys = keys, Name = "My Application"};
{ Capabilities = capabilities, Keys = keys, Name = "My Application" };
var creds = Credentials.FromApiKeyAndSecret(this.ApiKey, this.ApiSecret);
var client = this.BuildVonageClient(creds);
Application response;
Expand Down Expand Up @@ -268,53 +268,7 @@ public async void DeleteApplicationAsync(bool passCreds)
public void GetApplication(bool passCreds)
{
var id = "78d335fa323d01149c3dd6f0d48968cf";
var expectedResponse = @"{
""id"": ""78d335fa323d01149c3dd6f0d48968cf"",
""name"": ""My Application"",
""capabilities"": {
""voice"": {
""webhooks"": {
""answer_url"": {
""address"": ""https://example.com/webhooks/answer"",
""http_method"": ""GET""
},
""fallback_answer_url"": {
""address"": ""https://fallback.example.com/webhooks/answer"",
""http_method"": ""GET""
},
""event_url"": {
""address"": ""https://example.com/webhooks/event"",
""http_method"": ""POST""
}
}
},
""messages"": {
""webhooks"": {
""inbound_url"": {
""address"": ""https://example.com/webhooks/inbound"",
""http_method"": ""POST""
},
""status_url"": {
""address"": ""https://example.com/webhooks/status"",
""http_method"": ""POST""
}
}
},
""rtc"": {
""webhooks"": {
""event_url"": {
""address"": ""https://example.com/webhooks/event"",
""http_method"": ""POST""
}
}
},
""vbc"": { }
},
""keys"": {
""public_key"": ""some public key"",
""private_key"": ""some private key""
}
}";
var expectedResponse = this.GetResponseJson();
var expectedUri = $"{this.ApiUrl}/v2/applications/{id}";
this.Setup(expectedUri, expectedResponse);
var creds = Credentials.FromApiKeyAndSecret(this.ApiKey, this.ApiSecret);
Expand Down Expand Up @@ -349,6 +303,12 @@ public void GetApplication(bool passCreds)
application.Capabilities.Rtc.Webhooks[Webhook.Type.EventUrl].Address);
Assert.Equal("POST", application.Capabilities.Rtc.Webhooks[Webhook.Type.EventUrl].Method);
Assert.Equal("My Application", application.Name);
Assert.Equal("http://example.com", application.Capabilities.Meetings.Webhooks[Webhook.Type.RoomChanged].Address);
Assert.Equal("POST", application.Capabilities.Meetings.Webhooks[Webhook.Type.RoomChanged].Method);
Assert.Equal("http://example.com", application.Capabilities.Meetings.Webhooks[Webhook.Type.SessionChanged].Address);
Assert.Equal("POST", application.Capabilities.Meetings.Webhooks[Webhook.Type.SessionChanged].Method);
Assert.Equal("https://54eba990d025.ngrok.app/recordings", application.Capabilities.Meetings.Webhooks[Webhook.Type.RecordingChanged].Address);
Assert.Equal("POST", application.Capabilities.Meetings.Webhooks[Webhook.Type.RecordingChanged].Method);
}

[Theory]
Expand Down Expand Up @@ -503,7 +463,7 @@ public void ListApplications(bool passCreds, bool passParameters)
if (passParameters)
{
expectedUri = $"{this.ApiUrl}/v2/applications?page_size=10&page=1&";
request = new ListApplicationsRequest {Page = 1, PageSize = 10};
request = new ListApplicationsRequest { Page = 1, PageSize = 10 };
}
else
{
Expand Down Expand Up @@ -616,7 +576,7 @@ public async void ListApplicationsAsync(bool passCreds, bool passParameters)
if (passParameters)
{
expectedUri = $"{this.ApiUrl}/v2/applications?page_size=10&page=1&";
request = new ListApplicationsRequest {Page = 1, PageSize = 10};
request = new ListApplicationsRequest { Page = 1, PageSize = 10 };
}
else
{
Expand Down Expand Up @@ -727,32 +687,32 @@ public void UpdateApplication(bool passCredentials)
//ACT
var messagesWebhooks = new Dictionary<Webhook.Type, Webhook>();
messagesWebhooks.Add(Webhook.Type.InboundUrl,
new Webhook {Address = "https://example.com/webhooks/inbound", Method = "POST"});
new Webhook { Address = "https://example.com/webhooks/inbound", Method = "POST" });
messagesWebhooks.Add(Webhook.Type.StatusUrl,
new Webhook {Address = "https://example.com/webhooks/status", Method = "POST"});
new Webhook { Address = "https://example.com/webhooks/status", Method = "POST" });
var messagesCapability = new Applications.Capabilities.Messages(messagesWebhooks);
var rtcWebhooks = new Dictionary<Webhook.Type, Webhook>();
rtcWebhooks.Add(Webhook.Type.EventUrl,
new Webhook {Address = "https://example.com/webhooks/events", Method = "POST"});
new Webhook { Address = "https://example.com/webhooks/events", Method = "POST" });
var rtcCapability = new Rtc(rtcWebhooks);
var voiceWebhooks = new Dictionary<Webhook.Type, Webhook>();
voiceWebhooks.Add(Webhook.Type.AnswerUrl,
new Webhook {Address = "https://example.com/webhooks/answer", Method = "GET"});
new Webhook { Address = "https://example.com/webhooks/answer", Method = "GET" });
voiceWebhooks.Add(Webhook.Type.EventUrl,
new Webhook {Address = "https://example.com/webhooks/events", Method = "POST"});
new Webhook { Address = "https://example.com/webhooks/events", Method = "POST" });
voiceWebhooks.Add(Webhook.Type.FallbackAnswerUrl,
new Webhook {Address = "https://fallback.example.com/webhooks/answer", Method = "GET"});
new Webhook { Address = "https://fallback.example.com/webhooks/answer", Method = "GET" });
var voiceCapability = new Applications.Capabilities.Voice(voiceWebhooks);
JsonConvert.SerializeObject(voiceCapability);
var vbcCapability = new Vbc();
var capabilities = new ApplicationCapabilities
{Messages = messagesCapability, Rtc = rtcCapability, Voice = voiceCapability, Vbc = vbcCapability};
{ Messages = messagesCapability, Rtc = rtcCapability, Voice = voiceCapability, Vbc = vbcCapability };
var keys = new Keys
{
PublicKey = PublicKey,
};
var application = new CreateApplicationRequest
{Capabilities = capabilities, Keys = keys, Name = "My Application"};
{ Capabilities = capabilities, Keys = keys, Name = "My Application" };
var creds = Credentials.FromApiKeyAndSecret(this.ApiKey, this.ApiSecret);
var client = this.BuildVonageClient(creds);
Application response;
Expand Down Expand Up @@ -848,32 +808,32 @@ public async void UpdateApplicationAsync(bool passCredentials)
//ACT
var messagesWebhooks = new Dictionary<Webhook.Type, Webhook>();
messagesWebhooks.Add(Webhook.Type.InboundUrl,
new Webhook {Address = "https://example.com/webhooks/inbound", Method = "POST"});
new Webhook { Address = "https://example.com/webhooks/inbound", Method = "POST" });
messagesWebhooks.Add(Webhook.Type.StatusUrl,
new Webhook {Address = "https://example.com/webhooks/status", Method = "POST"});
new Webhook { Address = "https://example.com/webhooks/status", Method = "POST" });
var messagesCapability = new Applications.Capabilities.Messages(messagesWebhooks);
var rtcWebhooks = new Dictionary<Webhook.Type, Webhook>();
rtcWebhooks.Add(Webhook.Type.EventUrl,
new Webhook {Address = "https://example.com/webhooks/events", Method = "POST"});
new Webhook { Address = "https://example.com/webhooks/events", Method = "POST" });
var rtcCapability = new Rtc(rtcWebhooks);
var voiceWebhooks = new Dictionary<Webhook.Type, Webhook>();
voiceWebhooks.Add(Webhook.Type.AnswerUrl,
new Webhook {Address = "https://example.com/webhooks/answer", Method = "GET"});
new Webhook { Address = "https://example.com/webhooks/answer", Method = "GET" });
voiceWebhooks.Add(Webhook.Type.EventUrl,
new Webhook {Address = "https://example.com/webhooks/events", Method = "POST"});
new Webhook { Address = "https://example.com/webhooks/events", Method = "POST" });
voiceWebhooks.Add(Webhook.Type.FallbackAnswerUrl,
new Webhook {Address = "https://fallback.example.com/webhooks/answer", Method = "GET"});
new Webhook { Address = "https://fallback.example.com/webhooks/answer", Method = "GET" });
var voiceCapability = new Applications.Capabilities.Voice(voiceWebhooks);
JsonConvert.SerializeObject(voiceCapability);
var vbcCapability = new Vbc();
var capabilities = new ApplicationCapabilities
{Messages = messagesCapability, Rtc = rtcCapability, Voice = voiceCapability, Vbc = vbcCapability};
{ Messages = messagesCapability, Rtc = rtcCapability, Voice = voiceCapability, Vbc = vbcCapability };
var keys = new Keys
{
PublicKey = PublicKey,
};
var application = new CreateApplicationRequest
{Capabilities = capabilities, Keys = keys, Name = "My Application"};
{ Capabilities = capabilities, Keys = keys, Name = "My Application" };
var creds = Credentials.FromApiKeyAndSecret(this.ApiKey, this.ApiSecret);
var client = this.BuildVonageClient(creds);
Application response;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"id": "78d335fa323d01149c3dd6f0d48968cf",
"name": "My Application",
"capabilities": {
"voice": {
"webhooks": {
"answer_url": {
"address": "https://example.com/webhooks/answer",
"http_method": "GET"
},
"fallback_answer_url": {
"address": "https://fallback.example.com/webhooks/answer",
"http_method": "GET"
},
"event_url": {
"address": "https://example.com/webhooks/event",
"http_method": "POST"
}
}
},
"messages": {
"webhooks": {
"inbound_url": {
"address": "https://example.com/webhooks/inbound",
"http_method": "POST"
},
"status_url": {
"address": "https://example.com/webhooks/status",
"http_method": "POST"
}
}
},
"rtc": {
"webhooks": {
"event_url": {
"address": "https://example.com/webhooks/event",
"http_method": "POST"
}
}
},
"vbc": {},
"meetings": {
"webhooks": {
"room_changed": {
"address": "http://example.com",
"http_method": "POST"
},
"session_changed": {
"address": "http://example.com",
"http_method": "POST"
},
"recording_changed": {
"address": "https://54eba990d025.ngrok.app/recordings",
"http_method": "POST"
}
}
}
},
"keys": {
"public_key": "some public key",
"private_key": "some private key"
}
}
3 changes: 3 additions & 0 deletions Vonage.Test.Unit/Vonage.Test.Unit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,9 @@
<None Update="Users\UpdateUser\Data\ShouldSerializeEmpty-request.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Data\ApplicationTests\GetApplication-response.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
<Exec Command="node ../.scripts/init.js"/>
Expand Down
9 changes: 9 additions & 0 deletions Vonage/Common/Webhook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ public enum Type

[EnumMember(Value = "Unknown")]
Unknown = 6,

[EnumMember(Value = "room_changed")]
RoomChanged =7,

[EnumMember(Value = "session_changed")]
SessionChanged=8,

[EnumMember(Value = "recording_changed")]
RecordingChanged = 9,
}

}

0 comments on commit 9166a02

Please sign in to comment.