Skip to content

Commit c3d4158

Browse files
feat: Add template_id support to VerificationRequest
- Add templateId field to VerificationRequest class - Add templateId(UUID) builder method - Add getTemplateId() getter with @JsonProperty annotation - Add comprehensive unit tests - Update CHANGELOG.md This change adds support for using custom templates in verification requests, allowing users to specify a template_id when creating verification requests via the Verify v2 API.
1 parent 035e9a7 commit c3d4158

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
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+
# [Unreleased]
6+
- Added `templateId` support to `VerificationRequest` for Verify v2 API to allow using custom templates
7+
58
# [9.7.0] - 2025-12-04
69
- Added native RCS message types (card, carousel) and suggestions support to eliminate need for custom message type
710

src/main/java/com/vonage/client/verify2/VerificationRequest.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.List;
2222
import java.util.Locale;
2323
import java.util.Objects;
24+
import java.util.UUID;
2425
import java.util.regex.Pattern;
2526

2627
/**
@@ -41,11 +42,13 @@ public class VerificationRequest implements Jsonable {
4142
protected final Integer channelTimeout, codeLength;
4243
protected final Boolean fraudCheck;
4344
protected final String brand, code, clientRef;
45+
protected final UUID templateId;
4446
protected final List<Workflow> workflows;
4547

4648
VerificationRequest(Builder builder) {
4749
locale = builder.locale;
4850
clientRef = builder.clientRef;
51+
templateId = builder.templateId;
4952
fraudCheck = builder.fraudCheck != null && !builder.fraudCheck ? false : null;
5053
if ((brand = builder.brand) == null || brand.trim().isEmpty()) {
5154
throw new IllegalArgumentException("Brand name is required.");
@@ -179,6 +182,17 @@ public boolean isCodeless() {
179182
return workflows.stream().allMatch(type -> type instanceof SilentAuthWorkflow);
180183
}
181184

185+
/**
186+
* A custom template ID to use for the verification request.
187+
* This allows you to use a pre-configured template instead of the default verification message.
188+
*
189+
* @return The template ID, or {@code null} if not set.
190+
*/
191+
@JsonProperty("template_id")
192+
public UUID getTemplateId() {
193+
return templateId;
194+
}
195+
182196
/**
183197
* Entry point for constructing an instance of this class.
184198
*
@@ -193,6 +207,7 @@ public static final class Builder {
193207
String brand, code, clientRef;
194208
Integer timeout, codeLength;
195209
Locale locale;
210+
UUID templateId;
196211
final List<Workflow> workflows = new ArrayList<>(1);
197212

198213
private Builder() {}
@@ -364,6 +379,20 @@ public Builder fraudCheck() {
364379
return fraudCheck(false);
365380
}
366381

382+
/**
383+
* (OPTIONAL)
384+
* A custom template ID to use for the verification request.
385+
* This allows you to use a pre-configured template instead of the default verification message.
386+
*
387+
* @param templateId The UUID of the template to use.
388+
*
389+
* @return This builder.
390+
*/
391+
public Builder templateId(UUID templateId) {
392+
this.templateId = templateId;
393+
return this;
394+
}
395+
367396
/**
368397
* Constructs a VerificationRequest with this builder's properties.
369398
*

src/test/java/com/vonage/client/verify2/VerificationRequestTest.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.Arrays;
2424
import java.util.Collections;
2525
import java.util.Locale;
26+
import java.util.UUID;
2627

2728
public class VerificationRequestTest {
2829
static final boolean SANDBOX = true;
@@ -39,6 +40,7 @@ public class VerificationRequestTest {
3940
CONTENT_ID = "1107158078772563946",
4041
ENTITY_ID = "1101407360000017170",
4142
REDIRECT_URL = "https://acme-app.com/sa/redirect";
43+
static final UUID TEMPLATE_ID = UUID.fromString("8f35a1a7-eb2f-4552-8fdf-fffdaee41bc9");
4244

4345
Builder newBuilder() {
4446
return VerificationRequest.builder().brand(BRAND);
@@ -371,4 +373,41 @@ class SelfRefrencing extends VerificationRequest {
371373
.addWorkflow(new SmsWorkflow(TO_NUMBER)).brand("Test")).toJson()
372374
);
373375
}
376+
377+
@Test
378+
public void testTemplateId() {
379+
Builder builder = getBuilderRequiredParamsSingleWorkflow(Channel.SMS);
380+
VerificationRequest request = builder.build();
381+
assertNull(request.getTemplateId());
382+
383+
builder.templateId(TEMPLATE_ID);
384+
request = builder.build();
385+
assertEquals(TEMPLATE_ID, request.getTemplateId());
386+
387+
String json = request.toJson();
388+
assertTrue(json.contains("\"template_id\":\"" + TEMPLATE_ID + "\""));
389+
}
390+
391+
@Test
392+
public void testTemplateIdInJson() {
393+
for (Channel channel : Channel.values()) {
394+
Builder builder = getBuilderRequiredParamsSingleWorkflow(channel);
395+
builder.templateId(TEMPLATE_ID);
396+
VerificationRequest request = builder.build();
397+
String json = request.toJson();
398+
assertTrue(json.contains("\"template_id\":\"" + TEMPLATE_ID + "\""),
399+
"template_id should be included in JSON for " + channel);
400+
}
401+
}
402+
403+
@Test
404+
public void testTemplateIdNotIncludedWhenNull() {
405+
for (Channel channel : Channel.values()) {
406+
Builder builder = getBuilderRequiredParamsSingleWorkflow(channel);
407+
VerificationRequest request = builder.build();
408+
String json = request.toJson();
409+
assertFalse(json.contains("\"template_id\""),
410+
"template_id should not be included in JSON when null for " + channel);
411+
}
412+
}
374413
}

0 commit comments

Comments
 (0)