Skip to content

Commit

Permalink
feat: add TimeToLive property on MMS in Messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Tr00d committed Jun 26, 2024
1 parent ac8c666 commit 79ebe28
Show file tree
Hide file tree
Showing 14 changed files with 185 additions and 56 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"channel": "mms",
"message_type": "audio",
"to": "441234567890",
"from": "015417543010",
"client_ref": "abcdefg",
"audio": {
"url": "https://test.com/me.mp3",
"caption": "Sounds I make"
},
"ttl": 600
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"channel": "mms",
"message_type": "image",
"to": "441234567890",
"from": "015417543010",
"client_ref": "abcdefg",
"image": {
"url": "https://test.com/image.png"
},
"ttl": 600
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"channel": "mms",
"message_type": "vcard",
"to": "441234567890",
"from": "015417543010",
"client_ref": "abcdefg",
"vcard": {
"url": "https://test.com/contact.vcf"
},
"ttl": 600
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"channel": "mms",
"message_type": "video",
"to": "441234567890",
"from": "015417543010",
"client_ref": "abcdefg",
"video": {
"url": "https://test.com/image.mp4",
"caption": "A video of me"
},
"ttl": 600
}
122 changes: 88 additions & 34 deletions Vonage.Test/Messages/Mms/MmsMessagesTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,24 @@ namespace Vonage.Test.Messages.Mms;
[Trait("Category", "Legacy")]
public class MmsMessagesTest : TestBase
{
private const string ResponseKey = "SendMessageReturnsOk";
private readonly VonageClient client;
private readonly string expectedResponse;
private readonly string expectedUri;
private readonly SerializationTestHelper helper;

private readonly SerializationTestHelper helper = new SerializationTestHelper(typeof(MmsMessagesTest).Namespace,
JsonSerializerBuilder.BuildWithCamelCase());

public MmsMessagesTest()
{
this.expectedUri = $"{this.ApiUrl}/v1/messages";
this.helper =
new SerializationTestHelper(typeof(MmsMessagesTest).Namespace,
JsonSerializerBuilder.BuildWithCamelCase());
this.client = this.BuildVonageClient(Credentials.FromAppIdAndPrivateKey(this.AppId, this.PrivateKey));
this.expectedResponse = this.helper.GetResponseJson(ResponseKey);
}

[Fact]
public async Task SendMmsAudioAsyncReturnsOk()
{
var expectedResponse = this.helper.GetResponseJson();
var expectedRequest = this.helper.GetRequestJson();
var request = new MmsAudioRequest
{
To = "441234567890",
Expand All @@ -39,19 +41,38 @@ public async Task SendMmsAudioAsyncReturnsOk()
},
ClientRef = "abcdefg",
};
var creds = Credentials.FromAppIdAndPrivateKey(this.AppId, this.PrivateKey);
this.Setup(this.expectedUri, expectedResponse, expectedRequest);
var client = this.BuildVonageClient(creds);
var response = await client.MessagesClient.SendAsync(request);
await this.AssertResponse(request, this.helper.GetRequestJson());
}

private async Task AssertResponse(IMessage request, string expectedRequest)
{
this.Setup(this.expectedUri, this.expectedResponse, expectedRequest);
var response = await this.client.MessagesClient.SendAsync(request);
Assert.NotNull(response);
Assert.Equal(new Guid("aaaaaaaa-bbbb-cccc-dddd-0123456789ab"), response.MessageUuid);
}

[Fact]
public async Task SendMmsAudioAsyncReturnsOkWithTtl()
{
var request = new MmsAudioRequest
{
To = "441234567890",
From = "015417543010",
Audio = new CaptionedAttachment
{
Url = "https://test.com/me.mp3",
Caption = "Sounds I make",
},
ClientRef = "abcdefg",
TimeToLive = 600,
};
await this.AssertResponse(request, this.helper.GetRequestJson());
}

[Fact]
public async Task SendMmsImageAsyncReturnsOk()
{
var expectedResponse = this.helper.GetResponseJson();
var expectedRequest = this.helper.GetRequestJson();
var request = new MmsImageRequest
{
To = "441234567890",
Expand All @@ -62,19 +83,29 @@ public async Task SendMmsImageAsyncReturnsOk()
},
ClientRef = "abcdefg",
};
var creds = Credentials.FromAppIdAndPrivateKey(this.AppId, this.PrivateKey);
this.Setup(this.expectedUri, expectedResponse, expectedRequest);
var client = this.BuildVonageClient(creds);
var response = await client.MessagesClient.SendAsync(request);
Assert.NotNull(response);
Assert.Equal(new Guid("aaaaaaaa-bbbb-cccc-dddd-0123456789ab"), response.MessageUuid);
await this.AssertResponse(request, this.helper.GetRequestJson());
}

[Fact]
public async Task SendMmsImageAsyncReturnsOkWithTtl()
{
var request = new MmsImageRequest
{
To = "441234567890",
From = "015417543010",
Image = new Attachment
{
Url = "https://test.com/image.png",
},
ClientRef = "abcdefg",
TimeToLive = 600,
};
await this.AssertResponse(request, this.helper.GetRequestJson());
}

[Fact]
public async Task SendMmsVcardAsyncReturnsOk()
{
var expectedResponse = this.helper.GetResponseJson();
var expectedRequest = this.helper.GetRequestJson();
var request = new MmsVcardRequest
{
To = "441234567890",
Expand All @@ -85,19 +116,29 @@ public async Task SendMmsVcardAsyncReturnsOk()
},
ClientRef = "abcdefg",
};
var creds = Credentials.FromAppIdAndPrivateKey(this.AppId, this.PrivateKey);
this.Setup(this.expectedUri, expectedResponse, expectedRequest);
var client = this.BuildVonageClient(creds);
var response = await client.MessagesClient.SendAsync(request);
Assert.NotNull(response);
Assert.Equal(new Guid("aaaaaaaa-bbbb-cccc-dddd-0123456789ab"), response.MessageUuid);
await this.AssertResponse(request, this.helper.GetRequestJson());
}

[Fact]
public async Task SendMmsVcardAsyncReturnsOkWithTtl()
{
var request = new MmsVcardRequest
{
To = "441234567890",
From = "015417543010",
Vcard = new Attachment
{
Url = "https://test.com/contact.vcf",
},
ClientRef = "abcdefg",
TimeToLive = 600,
};
await this.AssertResponse(request, this.helper.GetRequestJson());
}

[Fact]
public async Task SendMmsVideoAsyncReturnsOk()
{
var expectedResponse = this.helper.GetResponseJson();
var expectedRequest = this.helper.GetRequestJson();
var request = new MmsVideoRequest
{
To = "441234567890",
Expand All @@ -109,11 +150,24 @@ public async Task SendMmsVideoAsyncReturnsOk()
},
ClientRef = "abcdefg",
};
var creds = Credentials.FromAppIdAndPrivateKey(this.AppId, this.PrivateKey);
this.Setup(this.expectedUri, expectedResponse, expectedRequest);
var client = this.BuildVonageClient(creds);
var response = await client.MessagesClient.SendAsync(request);
Assert.NotNull(response);
Assert.Equal(new Guid("aaaaaaaa-bbbb-cccc-dddd-0123456789ab"), response.MessageUuid);
await this.AssertResponse(request, this.helper.GetRequestJson());
}

[Fact]
public async Task SendMmsVideoAsyncReturnsOkWithTtl()
{
var request = new MmsVideoRequest
{
To = "441234567890",
From = "015417543010",
Video = new CaptionedAttachment
{
Url = "https://test.com/image.mp4",
Caption = "A video of me",
},
ClientRef = "abcdefg",
TimeToLive = 600,
};
await this.AssertResponse(request, this.helper.GetRequestJson());
}
}
28 changes: 15 additions & 13 deletions Vonage.Test/Vonage.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -317,27 +317,15 @@
<None Include="Messages\Mms\Data\SendMmsAudioAsyncReturnsOk-request.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Messages\Mms\Data\SendMmsAudioAsyncReturnsOk-response.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Messages\Mms\Data\SendMmsImageAsyncReturnsOk-request.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Messages\Mms\Data\SendMmsImageAsyncReturnsOk-response.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Messages\Mms\Data\SendMmsVcardAsyncReturnsOk-request.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Messages\Mms\Data\SendMmsVcardAsyncReturnsOk-response.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Messages\Mms\Data\SendMmsVideoAsyncReturnsOk-request.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Messages\Mms\Data\SendMmsVideoAsyncReturnsOk-response.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Messages\Sms\Data\SendSmsAsyncReturnsInvalidCredentials-request.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down Expand Up @@ -682,7 +670,6 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<Folder Include="Messages\Messenger\Data"/>
<Folder Include="Messages\Mms\Data"/>
<Folder Include="Messages\Sms\Data"/>
<None Update="Data\NccoTests\TestConnectWithAdvancedMachineDetection-request.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
Expand Down Expand Up @@ -1248,6 +1235,21 @@
<None Update="Video\ExperienceComposer\Data\ShouldDeserialize200-response.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Messages\Mms\Data\SendMmsAudioAsyncReturnsOkWithTtl-request.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Messages\Mms\Data\SendMmsImageAsyncReturnsOkWithTtl-request.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Messages\Mms\Data\SendMmsVcardAsyncReturnsOkWithTtl-request.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Messages\Mms\Data\SendMmsVideoAsyncReturnsOkWithTtl-request.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Messages\Mms\Data\SendMessageReturnsOk-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/Messages/Mms/MmsAudioRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,13 @@ public class MmsAudioRequest : MessageRequestBase
public override MessagesChannel Channel => MessagesChannel.MMS;

public override MessagesMessageType MessageType => MessagesMessageType.Audio;

/// <summary>
/// Time-To-Live (how long a message should exist before it is delivered successfully) in seconds. If a message is not
/// delivered successfully within the TTL time, the message is considered expired and will be rejected if TTL is
/// supported.
/// </summary>
[JsonPropertyName("ttl")]
[JsonPropertyOrder(7)]
public int? TimeToLive { get; set; }
}
9 changes: 9 additions & 0 deletions Vonage/Messages/Mms/MmsImageRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,13 @@ public class MmsImageRequest : MessageRequestBase
[JsonPropertyOrder(6)] public Attachment Image { get; set; }

public override MessagesMessageType MessageType => MessagesMessageType.Image;

/// <summary>
/// Time-To-Live (how long a message should exist before it is delivered successfully) in seconds. If a message is not
/// delivered successfully within the TTL time, the message is considered expired and will be rejected if TTL is
/// supported.
/// </summary>
[JsonPropertyOrder(7)]
[JsonPropertyName("ttl")]
public int? TimeToLive { get; set; }
}
9 changes: 9 additions & 0 deletions Vonage/Messages/Mms/MmsVcardRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,13 @@ public class MmsVcardRequest : MessageRequestBase

public override MessagesMessageType MessageType => MessagesMessageType.Vcard;
[JsonPropertyOrder(6)] public Attachment Vcard { get; set; }

/// <summary>
/// Time-To-Live (how long a message should exist before it is delivered successfully) in seconds. If a message is not
/// delivered successfully within the TTL time, the message is considered expired and will be rejected if TTL is
/// supported.
/// </summary>
[JsonPropertyName("ttl")]
[JsonPropertyOrder(7)]
public int? TimeToLive { get; set; }
}
9 changes: 9 additions & 0 deletions Vonage/Messages/Mms/MmsVideoRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,13 @@ public class MmsVideoRequest : MessageRequestBase

public override MessagesMessageType MessageType => MessagesMessageType.Video;
[JsonPropertyOrder(6)] public CaptionedAttachment Video { get; set; }

/// <summary>
/// Time-To-Live (how long a message should exist before it is delivered successfully) in seconds. If a message is not
/// delivered successfully within the TTL time, the message is considered expired and will be rejected if TTL is
/// supported.
/// </summary>
[JsonPropertyName("ttl")]
[JsonPropertyOrder(7)]
public int? TimeToLive { get; set; }
}

0 comments on commit 79ebe28

Please sign in to comment.