Visitar URL original
feat(voice): CPS tracking on create call and started webhook (DEVX-11… · Vonage/vonage-java-sdk@6564a9e · GitHub
Skip to content

Commit 6564a9e

Browse files
feat(voice): CPS tracking on create call and started webhook (DEVX-11542, DEVX-11549) (#632)
* feat(voice): add return_cps_on_started to create call request Adds Call.Builder#returnCpsOnStarted so callers can request CPS usage and limit data in the started event webhook. Omitted from the request unless set. DEVX-11542 * feat(voice): add CPS fields to started event webhook Adds cps_region_usage, cps_global_usage and cps_limit to EventWebhook. Present only on started events when return_cps_on_started is true. DEVX-11549 * chore(deps): bump Jackson from 2.22.0 to 2.22.2 Fixes jackson-databind advisories GHSA-q4xh-88c3-wmh7 (high), GHSA-gx83-3vf8-gh7j, GHSA-wjgm-6hv5-3cvf, GHSA-vvgp-rfg2-7rr6, GHSA-5gvw-p9qm-jgwh and GHSA-5jmj-h7xm-6q6v. * Bump to 9.15.0 for release
1 parent 25a6e55 commit 6564a9e

8 files changed

Lines changed: 131 additions & 8 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
All notable changes to this project will be documented in this file.
33
This project adheres to [Semantic Versioning](http://semver.org/).
44

5+
# [9.15.0]
6+
- Voice: Added `returnCpsOnStarted` to `Call.Builder` (`return_cps_on_started`) to request calls per second (CPS) usage and limit data in the `started` event webhook
7+
- Voice: Added `getCpsRegionUsage()`, `getCpsGlobalUsage()` and `getCpsLimit()` to `EventWebhook` for the new `started` event CPS fields
8+
- Dependencies: Bumped Jackson from 2.22.0 to 2.22.2 to address `jackson-databind` security advisories (GHSA-q4xh-88c3-wmh7, GHSA-gx83-3vf8-gh7j, GHSA-wjgm-6hv5-3cvf, GHSA-vvgp-rfg2-7rr6, GHSA-5gvw-p9qm-jgwh, GHSA-5jmj-h7xm-6q6v)
9+
510
# [9.14.0]
611
- Auth: Added public `RequestSigning.verifyRequestSignature(InputStream, String, Map, String, HashType)` overload, so callers can verify signed callbacks (e.g. SMS) using a non-MD5 algorithm such as `HMAC_SHA256`. Previously the only publicly accessible overload was hardcoded to `HashType.MD5` and the algorithm-aware overload was package-private. Existing overloads are unchanged and still default to MD5
712

‎README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ Add the following to your `build.gradle` or `build.gradle.kts` file:
8383

8484
```groovy
8585
dependencies {
86-
implementation("com.vonage:server-sdk:9.14.0")
86+
implementation("com.vonage:server-sdk:9.15.0")
8787
}
8888
```
8989

@@ -94,7 +94,7 @@ Add the following to the `<dependencies>` section of your `pom.xml` file:
9494
<dependency>
9595
<groupId>com.vonage</groupId>
9696
<artifactId>server-sdk</artifactId>
97-
<version>9.14.0</version>
97+
<version>9.15.0</version>
9898
</dependency>
9999
```
100100

‎pom.xml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>com.vonage</groupId>
77
<artifactId>server-sdk</artifactId>
8-
<version>9.14.0</version>
8+
<version>9.15.0</version>
99

1010
<name>Vonage Java Server SDK</name>
1111
<description>Java client for Vonage APIs</description>
@@ -46,7 +46,7 @@
4646
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
4747
<nexusUrl>https://central.sonatype.com</nexusUrl>
4848
<mockito.version>5.23.0</mockito.version>
49-
<jackson.version>2.22.0</jackson.version>
49+
<jackson.version>2.22.2</jackson.version>
5050
<jjwt.version>0.12.6</jjwt.version>
5151
</properties>
5252

‎src/main/java/com/vonage/client/HttpWrapper.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public class HttpWrapper {
4444

4545
private static final String
4646
CLIENT_NAME = "vonage-java-sdk",
47-
CLIENT_VERSION = "9.14.0",
47+
CLIENT_VERSION = "9.15.0",
4848
JAVA_VERSION = System.getProperty("java.version"),
4949
USER_AGENT = String.format("%s/%s java/%s", CLIENT_NAME, CLIENT_VERSION, JAVA_VERSION);
5050

‎src/main/java/com/vonage/client/voice/Call.java‎

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public class Call extends JsonableBaseObject {
3636
private MachineDetection machineDetection;
3737
private AdvancedMachineDetection advancedMachineDetection;
3838
private Integer lengthTimer, ringingTimer;
39-
private Boolean fromRandomNumber;
39+
private Boolean fromRandomNumber, returnCpsOnStarted;
4040
private Collection<? extends Action> ncco;
4141

4242
/**
@@ -66,6 +66,7 @@ else if ((fromRandomNumber = builder.fromRandomNumber) != null && fromRandomNumb
6666
answerUrl = builder.answerUrl != null ? Collections.singletonList(URI.create(builder.answerUrl)) : null;
6767
eventUrl = builder.eventUrl != null ? Collections.singletonList(URI.create(builder.eventUrl)) : null;
6868
ncco = builder.ncco;
69+
returnCpsOnStarted = builder.returnCpsOnStarted;
6970
advancedMachineDetection = builder.advancedMachineDetection;
7071
if ((machineDetection = builder.machineDetection) != null && advancedMachineDetection != null) {
7172
throw new IllegalStateException("Cannot set both machineDetection and advancedMachineDetection.");
@@ -232,6 +233,20 @@ public Boolean getFromRandomNumber() {
232233
return fromRandomNumber;
233234
}
234235

236+
/**
237+
* Whether the {@code started} event webhook will include calls per second (CPS) usage and limit data
238+
* ({@code cps_region_usage}, {@code cps_global_usage} and {@code cps_limit}).
239+
*
240+
* @return {@code true} if CPS data will be included in the {@code started} event,
241+
* or {@code null} if unspecified (the default, equivalent to {@code false}).
242+
*
243+
* @since 9.15.0
244+
*/
245+
@JsonProperty("return_cps_on_started")
246+
public Boolean getReturnCpsOnStarted() {
247+
return returnCpsOnStarted;
248+
}
249+
235250
/**
236251
* Gets the NCCOs to use for this call.
237252
*
@@ -265,7 +280,7 @@ public static class Builder {
265280
private MachineDetection machineDetection;
266281
private AdvancedMachineDetection advancedMachineDetection;
267282
private Integer lengthTimer, ringingTimer;
268-
private Boolean fromRandomNumber;
283+
private Boolean fromRandomNumber, returnCpsOnStarted;
269284
private Collection<Action> ncco;
270285

271286
Builder() {}
@@ -422,6 +437,22 @@ public Builder fromRandomNumber(boolean fromRandomNumber) {
422437
return this;
423438
}
424439

440+
/**
441+
* Set to {@code true} to include calls per second (CPS) usage and limit data in the {@code started}
442+
* event webhook. When enabled, the event will contain {@code cps_region_usage}, {@code cps_global_usage}
443+
* and {@code cps_limit}. When omitted or {@code false}, the {@code started} event is unchanged.
444+
*
445+
* @param returnCpsOnStarted Whether to include CPS data in the {@code started} event.
446+
*
447+
* @return This builder.
448+
*
449+
* @since 9.15.0
450+
*/
451+
public Builder returnCpsOnStarted(boolean returnCpsOnStarted) {
452+
this.returnCpsOnStarted = returnCpsOnStarted;
453+
return this;
454+
}
455+
425456
/**
426457
* Sets the actions to take on the call.
427458
*

‎src/main/java/com/vonage/client/voice/EventWebhook.java‎

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class EventWebhook extends JsonableBaseObject {
4040
private DtmfResult dtmf;
4141
private SpeechResults speech;
4242
private Instant timestamp, startTime, endTime;
43-
private Integer duration, size, sipCode;
43+
private Integer duration, size, sipCode, cpsRegionUsage, cpsGlobalUsage, cpsLimit;
4444
private Double rate, price;
4545
private URI recordingUrl;
4646
private String to, from, network, reason,
@@ -310,6 +310,45 @@ public Integer getSipCode() {
310310
return sipCode;
311311
}
312312

313+
/**
314+
* Calls per second (CPS) in use within the region at the time the call was created. This is only present
315+
* on {@linkplain CallStatus#STARTED} events when the call was created with
316+
* {@link Call.Builder#returnCpsOnStarted(boolean)} set to {@code true}.
317+
*
318+
* @return The regional CPS usage, or {@code null} if not applicable.
319+
* @since 9.15.0
320+
*/
321+
@JsonProperty("cps_region_usage")
322+
public Integer getCpsRegionUsage() {
323+
return cpsRegionUsage;
324+
}
325+
326+
/**
327+
* Calls per second (CPS) in use across all regions at the time the call was created. This is only present
328+
* on {@linkplain CallStatus#STARTED} events when the call was created with
329+
* {@link Call.Builder#returnCpsOnStarted(boolean)} set to {@code true}.
330+
*
331+
* @return The global CPS usage, or {@code null} if not applicable.
332+
* @since 9.15.0
333+
*/
334+
@JsonProperty("cps_global_usage")
335+
public Integer getCpsGlobalUsage() {
336+
return cpsGlobalUsage;
337+
}
338+
339+
/**
340+
* Maximum calls per second (CPS) configured for the account. This is only present
341+
* on {@linkplain CallStatus#STARTED} events when the call was created with
342+
* {@link Call.Builder#returnCpsOnStarted(boolean)} set to {@code true}.
343+
*
344+
* @return The account's CPS limit, or {@code null} if not applicable.
345+
* @since 9.15.0
346+
*/
347+
@JsonProperty("cps_limit")
348+
public Integer getCpsLimit() {
349+
return cpsLimit;
350+
}
351+
313352
/**
314353
* Constructs an instance, populating this class's fields from the JSON string.
315354
*

‎src/test/java/com/vonage/client/voice/CallTest.java‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,30 @@ public void testSipHeader() {
429429
assertThrows(IllegalArgumentException.class, () -> SipHeader.fromString("unknown"));
430430
}
431431

432+
@Test
433+
public void testToJsonReturnCpsOnStarted() {
434+
Call.Builder builder = Call.builder().to(new PhoneEndpoint("4477999000"))
435+
.from("44111222333").answerUrl("https://callback.example.com/");
436+
String prefix = "{\"to\":[{\"number\":\"4477999000\",\"type\":\"phone\"}],"
437+
+ "\"from\":{\"number\":\"44111222333\",\"type\":\"phone\"},"
438+
+ "\"answer_method\":\"GET\",\"answer_url\":[\"https://callback.example.com/\"]";
439+
440+
Call enabled = builder.returnCpsOnStarted(true).build();
441+
assertTrue(enabled.getReturnCpsOnStarted());
442+
assertEquals(prefix + ",\"return_cps_on_started\":true}", enabled.toJson());
443+
444+
Call disabled = builder.returnCpsOnStarted(false).build();
445+
assertFalse(disabled.getReturnCpsOnStarted());
446+
assertEquals(prefix + ",\"return_cps_on_started\":false}", disabled.toJson());
447+
}
448+
449+
@Test
450+
public void testReturnCpsOnStartedOmittedByDefault() {
451+
Call call = Call.builder().to(new VbcEndpoint("123")).build();
452+
assertNull(call.getReturnCpsOnStarted());
453+
assertFalse(call.toJson().contains("return_cps_on_started"));
454+
}
455+
432456
@Test
433457
public void testNulllAnswerMethod() {
434458
Call call = Call.builder().to(new VbcEndpoint("123"))

‎src/test/java/com/vonage/client/voice/EventWebhookTest.java‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ public void testSerdesAllFields() {
155155
public void testParseEmptyJson() {
156156
EventWebhook event = EventWebhook.fromJson("{}");
157157
testJsonableBaseObject(event);
158+
assertNull(event.getCpsRegionUsage());
159+
assertNull(event.getCpsGlobalUsage());
160+
assertNull(event.getCpsLimit());
158161
assertNull(event.getDetail());
159162
assertNull(event.getCallUuid());
160163
assertNull(event.getReason());
@@ -273,5 +276,26 @@ public void testEventWithoutSipCode() {
273276
EventWebhook event = EventWebhook.fromJson(json);
274277
assertEquals(CallStatus.STARTED, event.getStatus());
275278
assertNull(event.getSipCode());
279+
assertNull(event.getCpsRegionUsage());
280+
assertNull(event.getCpsGlobalUsage());
281+
assertNull(event.getCpsLimit());
282+
}
283+
284+
@Test
285+
public void testStartedEventWithCpsFields() {
286+
String json = "{\"from\":\"442079460000\",\"to\":\"447700900000\"," +
287+
"\"uuid\":\"aaaaaaaa-bbbb-cccc-dddd-0123456789ab\"," +
288+
"\"conversation_uuid\":\"CON-aaaaaaaa-bbbb-cccc-dddd-0123456789ab\"," +
289+
"\"status\":\"started\",\"direction\":\"outbound\"," +
290+
"\"timestamp\":\"2020-01-01T12:00:00.000Z\"," +
291+
"\"cps_region_usage\":1,\"cps_global_usage\":0,\"cps_limit\":3}";
292+
EventWebhook event = EventWebhook.fromJson(json);
293+
testJsonableBaseObject(event);
294+
assertEquals(CallStatus.STARTED, event.getStatus());
295+
assertEquals(CallDirection.OUTBOUND, event.getDirection());
296+
assertEquals("aaaaaaaa-bbbb-cccc-dddd-0123456789ab", event.getCallUuid());
297+
assertEquals(1, event.getCpsRegionUsage());
298+
assertEquals(0, event.getCpsGlobalUsage());
299+
assertEquals(3, event.getCpsLimit());
276300
}
277301
}

0 commit comments

Comments
 (0)