Skip to content

Commit 228720e

Browse files
feat(messages): Additional RCS config options and fix for TTL visibility
* feat(messages): Additional RCS config options * fix(messages): Made RCS TTL public so it can be set
1 parent cff1df0 commit 228720e

File tree

8 files changed

+414
-41
lines changed

8 files changed

+414
-41
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
44

55
# [9.10.0]
66
- Exceptions: Added `getRawRequest()` and `getRawResponse()` methods to `VonageApiResponseException` for debugging API errors
7+
- Messages: RCS TTL is now publicly settable on all RCS message types, with validation between 300 and 2592000 seconds
78

89
# [9.9.0]
910
- Video: Added post-call transcription options
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright 2025 Vonage
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.vonage.client.messages.rcs;
17+
18+
import com.fasterxml.jackson.annotation.JsonValue;
19+
20+
/**
21+
* The orientation of a rich card.
22+
*
23+
* @since 9.9.0
24+
*/
25+
public enum CardOrientation {
26+
/**
27+
* Vertical card orientation.
28+
*/
29+
VERTICAL,
30+
31+
/**
32+
* Horizontal card orientation.
33+
*/
34+
HORIZONTAL;
35+
36+
@JsonValue
37+
@Override
38+
public String toString() {
39+
return name();
40+
}
41+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright 2025 Vonage
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.vonage.client.messages.rcs;
17+
18+
import com.fasterxml.jackson.annotation.JsonValue;
19+
20+
/**
21+
* The width of the rich cards displayed in a carousel.
22+
*
23+
* @since 9.9.0
24+
*/
25+
public enum CardWidth {
26+
/**
27+
* Small card width.
28+
*/
29+
SMALL,
30+
31+
/**
32+
* Medium card width.
33+
*/
34+
MEDIUM;
35+
36+
@JsonValue
37+
@Override
38+
public String toString() {
39+
return name();
40+
}
41+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright 2025 Vonage
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.vonage.client.messages.rcs;
17+
18+
import com.fasterxml.jackson.annotation.JsonValue;
19+
20+
/**
21+
* The alignment of the thumbnail image in a rich card.
22+
* This property only applies when sending rich cards with a card_orientation of HORIZONTAL.
23+
*
24+
* @since 9.9.0
25+
*/
26+
public enum ImageAlignment {
27+
/**
28+
* Image aligned to the right.
29+
*/
30+
RIGHT,
31+
32+
/**
33+
* Image aligned to the left.
34+
*/
35+
LEFT;
36+
37+
@JsonValue
38+
@Override
39+
public String toString() {
40+
return name();
41+
}
42+
}

src/main/java/com/vonage/client/messages/rcs/Rcs.java

Lines changed: 124 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,20 @@
2424
* @since 9.6.0
2525
*/
2626
public final class Rcs extends JsonableBaseObject {
27-
private String category;
28-
Boolean trustedRecipient;
27+
String category;
28+
CardOrientation cardOrientation;
29+
ImageAlignment imageAlignment;
30+
CardWidth cardWidth;
2931

3032
Rcs() {}
3133

34+
private Rcs(Builder builder) {
35+
this.category = builder.category;
36+
this.cardOrientation = builder.cardOrientation;
37+
this.imageAlignment = builder.imageAlignment;
38+
this.cardWidth = builder.cardWidth;
39+
}
40+
3241
/**
3342
* Creates an RCS options object with the specified category.
3443
*
@@ -39,37 +48,132 @@ public Rcs(String category) {
3948
}
4049

4150
/**
42-
* Creates an RCS options object with the specified category and trusted recipient flag.
51+
* The RCS message category.
4352
*
44-
* @param category The RCS message category.
45-
* @param trustedRecipient Whether the recipient is trusted.
53+
* @return The category as a string, or {@code null} if not set.
54+
*/
55+
@JsonProperty("category")
56+
public String getCategory() {
57+
return category;
58+
}
59+
60+
/**
61+
* The orientation of the rich card.
62+
*
63+
* @return The card orientation, or {@code null} if not set.
4664
*
47-
* @since 9.8.0
65+
* @since 9.9.0
4866
*/
49-
public Rcs(String category, Boolean trustedRecipient) {
50-
this.category = category;
51-
this.trustedRecipient = trustedRecipient;
67+
@JsonProperty("card_orientation")
68+
public CardOrientation getCardOrientation() {
69+
return cardOrientation;
5270
}
5371

5472
/**
55-
* The RCS message category.
73+
* The alignment of the thumbnail image in the rich card.
74+
* This property only applies when sending rich cards with a card_orientation of HORIZONTAL.
5675
*
57-
* @return The category as a string, or {@code null} if not set.
76+
* @return The image alignment, or {@code null} if not set.
77+
*
78+
* @since 9.9.0
5879
*/
59-
@JsonProperty("category")
60-
public String getCategory() {
61-
return category;
80+
@JsonProperty("image_alignment")
81+
public ImageAlignment getImageAlignment() {
82+
return imageAlignment;
6283
}
6384

6485
/**
65-
* Whether the recipient is trusted.
86+
* The width of the rich cards displayed in the carousel.
87+
*
88+
* @return The card width, or {@code null} if not set.
6689
*
67-
* @return The trusted recipient flag as a Boolean, or {@code null} if not set.
90+
* @since 9.9.0
91+
*/
92+
@JsonProperty("card_width")
93+
public CardWidth getCardWidth() {
94+
return cardWidth;
95+
}
96+
97+
/**
98+
* Entry point for constructing an instance of this class.
99+
*
100+
* @return A new Builder.
101+
*
102+
* @since 9.9.0
103+
*/
104+
public static Builder builder() {
105+
return new Builder();
106+
}
107+
108+
/**
109+
* Builder for constructing an Rcs object with fluent API.
68110
*
69-
* @since 9.8.0
111+
* @since 9.9.0
70112
*/
71-
@JsonProperty("trusted_recipient")
72-
public Boolean getTrustedRecipient() {
73-
return trustedRecipient;
113+
public static final class Builder {
114+
private String category;
115+
private CardOrientation cardOrientation;
116+
private ImageAlignment imageAlignment;
117+
private CardWidth cardWidth;
118+
119+
Builder() {}
120+
121+
/**
122+
* (OPTIONAL)
123+
* Sets the RCS message category.
124+
*
125+
* @param category The RCS category.
126+
* @return This builder.
127+
*/
128+
public Builder category(String category) {
129+
this.category = category;
130+
return this;
131+
}
132+
133+
/**
134+
* (OPTIONAL)
135+
* Sets the orientation of the rich card.
136+
*
137+
* @param cardOrientation The card orientation.
138+
* @return This builder.
139+
*/
140+
public Builder cardOrientation(CardOrientation cardOrientation) {
141+
this.cardOrientation = cardOrientation;
142+
return this;
143+
}
144+
145+
/**
146+
* (OPTIONAL)
147+
* Sets the alignment of the thumbnail image in the rich card.
148+
* This property only applies when sending rich cards with a card_orientation of HORIZONTAL.
149+
*
150+
* @param imageAlignment The image alignment.
151+
* @return This builder.
152+
*/
153+
public Builder imageAlignment(ImageAlignment imageAlignment) {
154+
this.imageAlignment = imageAlignment;
155+
return this;
156+
}
157+
158+
/**
159+
* (OPTIONAL)
160+
* Sets the width of the rich cards displayed in the carousel.
161+
*
162+
* @param cardWidth The card width.
163+
* @return This builder.
164+
*/
165+
public Builder cardWidth(CardWidth cardWidth) {
166+
this.cardWidth = cardWidth;
167+
return this;
168+
}
169+
170+
/**
171+
* Builds the Rcs object.
172+
*
173+
* @return A new Rcs instance.
174+
*/
175+
public Rcs build() {
176+
return new Rcs(this);
177+
}
74178
}
75179
}

src/main/java/com/vonage/client/messages/rcs/RcsRequest.java

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,28 @@
2727
*/
2828
public abstract class RcsRequest extends MessageRequest {
2929
protected Rcs rcs;
30+
protected Boolean trustedRecipient;
3031

3132
protected RcsRequest(Builder<?, ?> builder, MessageType messageType) {
3233
super(builder, Channel.RCS, messageType);
3334
this.rcs = builder.rcs;
35+
this.trustedRecipient = builder.trustedRecipient;
36+
int min = 20, max = 259200;
37+
if (ttl != null && (ttl < min || ttl > max)) {
38+
throw new IllegalArgumentException("TTL must be between "+min+" and "+max+" seconds.");
39+
}
3440
}
3541

3642
@JsonProperty("ttl")
3743
public Integer getTtl() {
3844
return ttl;
3945
}
4046

47+
@JsonProperty("trusted_recipient")
48+
public Boolean getTrustedRecipient() {
49+
return trustedRecipient;
50+
}
51+
4152
@JsonProperty("rcs")
4253
public Rcs getRcs() {
4354
return rcs;
@@ -46,6 +57,7 @@ public Rcs getRcs() {
4657
@SuppressWarnings("unchecked")
4758
protected abstract static class Builder<M extends RcsRequest, B extends Builder<? extends M, ? extends B>> extends MessageRequest.Builder<M, B> {
4859
protected Rcs rcs;
60+
protected Boolean trustedRecipient;
4961

5062
/**
5163
* (OPTIONAL)
@@ -61,19 +73,6 @@ public B rcs(Rcs rcs) {
6173
return (B) this;
6274
}
6375

64-
/**
65-
* (OPTIONAL)
66-
* Sets the RCS message category.
67-
*
68-
* @param category The RCS category.
69-
* @return This builder.
70-
*
71-
* @since 9.5.0
72-
*/
73-
public B rcsCategory(String category) {
74-
return rcs(new Rcs(category));
75-
}
76-
7776
/**
7877
* (OPTIONAL)
7978
* Indicates if the recipient is trusted.
@@ -84,15 +83,20 @@ public B rcsCategory(String category) {
8483
* @since 9.8.0
8584
*/
8685
public B trustedRecipient(Boolean trustedRecipient) {
87-
if (rcs == null) {
88-
rcs = new Rcs();
89-
}
90-
rcs.trustedRecipient = trustedRecipient;
86+
this.trustedRecipient = trustedRecipient;
9187
return (B) this;
9288
}
9389

90+
/**
91+
* (OPTIONAL)
92+
* Sets the time-to-live for the RCS message.
93+
*
94+
* @param ttl The duration in seconds the delivery of a message will be attempted,
95+
* between 300 and 2592000 seconds.
96+
* @return This builder.
97+
*/
9498
@Override
95-
protected B ttl(int ttl) {
99+
public B ttl(int ttl) {
96100
return super.ttl(ttl);
97101
}
98102
}

0 commit comments

Comments
 (0)