Skip to content

Commit e1174c4

Browse files
Pull request #25: Added full support for App Verify API
Merge in SDK/java_telesign_enterprise from feature/EOA2092 to developer Squashed commit of the following: commit eb8e4ec0125b119edf32f0d599a4e9e0e24a8fa9 Author: Juan Camilo Martinez <jmartinez@telesign.com> Date: Fri Aug 1 15:51:40 2025 -0500 remove log commit c7857bf65c591f96a595c025a944894960808aae Author: Juan Camilo Martinez <jmartinez@telesign.com> Date: Fri Aug 1 09:15:01 2025 -0500 fix nomenclature commit 29588102487a8036f73adbd0e7a2c3ea7d1ed441 Author: Juan Camilo Martinez <jmartinez@telesign.com> Date: Fri Aug 1 09:11:38 2025 -0500 Added full support for App Verify API
1 parent 1e66bd2 commit e1174c4

File tree

9 files changed

+339
-3
lines changed

9 files changed

+339
-3
lines changed

RELEASE.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
3.1.0
2+
- Added full support for App Verify API
3+
14
3.0.0
25
- Removed Contact method in PhoneId class.
36

build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ plugins {
66
}
77

88
group 'com.telesign.enterprise'
9-
version '3.0.0'
9+
version '3.1.0'
1010

1111
sourceCompatibility = JavaVersion.VERSION_1_8
1212
targetCompatibility = JavaVersion.VERSION_1_8
@@ -17,7 +17,7 @@ repositories {
1717
}
1818

1919
dependencies {
20-
implementation('com.telesign:telesign:2.5.0')
20+
implementation('com.telesign:telesign:3.0.0')
2121
//implementation(project(":com.telesign"))
2222
implementation 'com.google.code.gson:gson:[2.7,3.0)'
2323
testImplementation( group: 'junit', name: 'junit', version: '[4.1,)')
@@ -80,7 +80,7 @@ publishing {
8080

8181
groupId = 'com.telesign.enterprise'
8282
artifactId = 'telesignenterprise'
83-
version = '3.0.0'
83+
version = '3.1.0'
8484

8585
pom {
8686
name = 'TeleSign Enterprise SDK'

src/main/java/com/telesign/enterprise/AppVerifyClient.java

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
package com.telesign.enterprise;
22

3+
import java.io.IOException;
34
import java.net.Proxy;
5+
import java.security.GeneralSecurityException;
6+
import java.util.HashMap;
7+
import java.util.Map;
48

59
public class AppVerifyClient extends com.telesign.AppVerifyClient {
610

11+
private static final String APPVERIFY_RESOURCE = "/v1/verify/auto/voice";
12+
private static final String ENDCALL_RESOURCE = APPVERIFY_RESOURCE + "/finalize";
13+
private static final String REPORT_CALLERID_RESOURCE = APPVERIFY_RESOURCE + "/finalize/callerid";
14+
private static final String REPORT_TIMEOUT_RESOURCE = APPVERIFY_RESOURCE + "/finalize/timeout";
15+
private static final String STATUS_RESOURCE = APPVERIFY_RESOURCE + "/%s";
16+
private static final String SENDCODE_RESOURCE = APPVERIFY_RESOURCE + "/initiate";
717
private static final String sdkVersion = AppVerifyClient.class.getPackage().getImplementationVersion();
818
private static final String sdkSource = "java_telesign_enterprise";
919
private static final String sdkVersionDependency = com.telesign.RestClient.class.getPackage().getImplementationVersion();
@@ -28,4 +38,69 @@ public AppVerifyClient(String customerId,
2838
final String proxyPassword) {
2939
super(customerId, apiKey, restEndpoint, connectTimeout, readTimeout, writeTimeout, proxy, proxyUsername, proxyPassword, sdkSource, sdkVersion, sdkVersionDependency);
3040
}
41+
42+
/**
43+
* Use this endpont to initiate verification of the specified phone number using the Telesign App Verify API.
44+
* <p>
45+
* See https://developer.telesign.com/enterprise/reference/sendappverifycode for detailed API documentation.
46+
*/
47+
public TelesignResponse sendCode(String phoneNumber, HashMap<String, String> params) throws IOException, GeneralSecurityException {
48+
params.put("phone_number", phoneNumber);
49+
return this.post(SENDCODE_RESOURCE, params);
50+
}
51+
52+
/**
53+
* Use this endpoint to terminate a call created using the Telesign App Verify API if the handset does not terminate the call in your application.
54+
* <p>
55+
* See https://developer.telesign.com/enterprise/reference/endappverifycall for detailed API documentation.
56+
*/
57+
public TelesignResponse endCall(String referenceId, String verifyCode) throws IOException, GeneralSecurityException {
58+
Map<String, String> params = new HashMap<>();
59+
params.put("reference_id", referenceId);
60+
61+
if (verifyCode != null && !verifyCode.isEmpty()) {
62+
params.put("verify_code", verifyCode);
63+
}
64+
65+
return this.post(ENDCALL_RESOURCE, params);
66+
}
67+
68+
/**
69+
* If a Telesign App Verify API call is unsuccessful, the device will not receive the call.
70+
* If there is a prefix sent by Telesign in the initiate request and it cannot be matched to the CLI of the verification call,
71+
* you can use this endpoint to report the issue to Telesign for troubleshooting
72+
* <p>
73+
* See https://developer.telesign.com/enterprise/reference/reportappverifycallerid for detailed API documentation.
74+
*/
75+
public TelesignResponse reportCallerId(String referenceId, String unknownCallerId, String customerId) throws IOException, GeneralSecurityException {
76+
Map<String, String> params = new HashMap<>();
77+
params.put("reference_id", referenceId);
78+
params.put("unknown_caller_id", unknownCallerId);
79+
80+
if (customerId != null && !customerId.isEmpty()) {
81+
params.put("customer_id", customerId);
82+
}
83+
84+
return this.post(REPORT_CALLERID_RESOURCE, params);
85+
}
86+
87+
/**
88+
* If a mobile device verification call does not make it to the designated handset within the specified amount of time, you can use the Finalize Timeout endpoint to report the issue to Telesign.
89+
* <p>
90+
* See https://developer.telesign.com/enterprise/reference/reportappverifytimeout for detailed API documentation.
91+
*/
92+
public TelesignResponse reportTimeout(String referenceId) throws IOException, GeneralSecurityException {
93+
Map<String, String> params = new HashMap<>();
94+
params.put("reference_id", referenceId);
95+
return this.post(REPORT_TIMEOUT_RESOURCE, params);
96+
}
97+
98+
/**
99+
* Use this endpoint to get the status of a Telesign App Verify API request that you initiated
100+
* <p>
101+
* See https://developer.telesign.com/enterprise/reference/getappverifystatus for detailed API documentation.
102+
*/
103+
public TelesignResponse getStatus(String referenceId) throws IOException, GeneralSecurityException {
104+
return this.get(String.format(STATUS_RESOURCE, referenceId), null);
105+
}
31106
}
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
package com.telesign.enterprise;
2+
3+
import junit.framework.TestCase;
4+
import okhttp3.mockwebserver.MockResponse;
5+
import okhttp3.mockwebserver.MockWebServer;
6+
import okhttp3.mockwebserver.RecordedRequest;
7+
8+
import java.util.ArrayList;
9+
import java.util.HashMap;
10+
import java.util.List;
11+
import java.util.concurrent.TimeUnit;
12+
13+
public class AppVerifyClientTest extends TestCase {
14+
15+
private MockWebServer mockServer;
16+
17+
private String customerId;
18+
private String apiKey;
19+
20+
public void setUp() throws Exception {
21+
super.setUp();
22+
23+
this.customerId = System.getenv("CUSTOMER_ID");
24+
this.apiKey = System.getenv("API_KEY");
25+
26+
if (this.customerId == null) this.customerId = "FFFFFFFF-EEEE-DDDD-1234-AB1234567890";
27+
if (this.apiKey == null) this.apiKey = "ABC12345yusumoN6BYsBVkh+yRJ5czgsnCehZaOYldPJdmFh6NeX8kunZ2zU1YWaUw/0wV6xfw==";
28+
29+
this.mockServer = new MockWebServer();
30+
this.mockServer.start();
31+
}
32+
33+
public void tearDown() throws Exception {
34+
super.tearDown();
35+
36+
this.mockServer.shutdown();
37+
}
38+
39+
public void testSendCode() throws Exception {
40+
this.mockServer.enqueue(new MockResponse().setBody("{}"));
41+
42+
AppVerifyClient client = new AppVerifyClient(this.customerId,
43+
this.apiKey,
44+
this.mockServer.url("").toString().replaceAll("/$", ""));
45+
46+
HashMap<String, String> params = new HashMap<>();
47+
48+
String phoneNumber = "11234567890";
49+
50+
client.sendCode(phoneNumber, params);
51+
52+
RecordedRequest request = this.mockServer.takeRequest(1, TimeUnit.SECONDS);
53+
54+
String bodyExpected = String.format("phone_number=%s", phoneNumber);
55+
assertEquals("body is not as expected", bodyExpected, request.getBody().readUtf8());
56+
assertEquals("method is not as expected", "POST", request.getMethod());
57+
assertEquals("path is not as expected", "/v1/verify/auto/voice/initiate", request.getPath());
58+
assertEquals("Content-Type header is not as expected", "application/x-www-form-urlencoded", request.getHeader("Content-Type"));
59+
}
60+
61+
public void testEndCall() throws Exception {
62+
this.mockServer.enqueue(new MockResponse().setBody("{}"));
63+
64+
AppVerifyClient client = new AppVerifyClient(this.customerId,
65+
this.apiKey,
66+
this.mockServer.url("").toString().replaceAll("/$", ""));
67+
68+
String referenceId = "0123456789ABCDEF0123456789ABCDEF";
69+
70+
client.endCall(referenceId, "");
71+
72+
RecordedRequest request = this.mockServer.takeRequest(1, TimeUnit.SECONDS);
73+
74+
String bodyExpected = String.format("reference_id=%s", referenceId);
75+
assertEquals("body is not as expected", bodyExpected, request.getBody().readUtf8());
76+
assertEquals("method is not as expected", "POST", request.getMethod());
77+
assertEquals("path is not as expected", "/v1/verify/auto/voice/finalize", request.getPath());
78+
assertEquals("Content-Type header is not as expected", "application/x-www-form-urlencoded", request.getHeader("Content-Type"));
79+
}
80+
81+
public void testReportCallerId() throws Exception {
82+
this.mockServer.enqueue(new MockResponse().setBody("{}"));
83+
84+
AppVerifyClient client = new AppVerifyClient(this.customerId,
85+
this.apiKey,
86+
this.mockServer.url("").toString().replaceAll("/$", ""));
87+
88+
String referenceId = "0123456789ABCDEF0123456789ABCDEF";
89+
String unknownCallerid = "test";
90+
91+
client.reportCallerId(referenceId, unknownCallerid,"");
92+
93+
RecordedRequest request = this.mockServer.takeRequest(1, TimeUnit.SECONDS);
94+
95+
String bodyExpected = String.format("reference_id=%s&unknown_caller_id=%s", referenceId, unknownCallerid);
96+
assertEquals("body is not as expected", bodyExpected, request.getBody().readUtf8());
97+
assertEquals("method is not as expected", "POST", request.getMethod());
98+
assertEquals("path is not as expected", "/v1/verify/auto/voice/finalize/callerid", request.getPath());
99+
assertEquals("Content-Type header is not as expected", "application/x-www-form-urlencoded", request.getHeader("Content-Type"));
100+
}
101+
102+
public void testReportTimeout() throws Exception {
103+
this.mockServer.enqueue(new MockResponse().setBody("{}"));
104+
105+
AppVerifyClient client = new AppVerifyClient(this.customerId,
106+
this.apiKey,
107+
this.mockServer.url("").toString().replaceAll("/$", ""));
108+
109+
String referenceId = "0123456789ABCDEF0123456789ABCDEF";
110+
111+
client.reportTimeout(referenceId);
112+
113+
RecordedRequest request = this.mockServer.takeRequest(1, TimeUnit.SECONDS);
114+
115+
String bodyExpected = String.format("reference_id=%s", referenceId);
116+
assertEquals("body is not as expected", bodyExpected, request.getBody().readUtf8());
117+
assertEquals("method is not as expected", "POST", request.getMethod());
118+
assertEquals("path is not as expected", "/v1/verify/auto/voice/finalize/timeout", request.getPath());
119+
assertEquals("Content-Type header is not as expected", "application/x-www-form-urlencoded", request.getHeader("Content-Type"));
120+
}
121+
122+
public void testStatus() throws Exception {
123+
this.mockServer.enqueue(new MockResponse().setBody("{}"));
124+
125+
AppVerifyClient client = new AppVerifyClient(this.customerId,
126+
this.apiKey,
127+
this.mockServer.url("").toString().replaceAll("/$", ""));
128+
129+
String reference_id = "0123456789ABCDEF0123456789ABCDEF";
130+
131+
client.getStatus(reference_id);
132+
133+
RecordedRequest request = this.mockServer.takeRequest(1, TimeUnit.SECONDS);
134+
135+
assertEquals("body is not as expected", "", request.getBody().readUtf8());
136+
assertEquals("method is not as expected", "GET", request.getMethod());
137+
assertEquals("path is not as expected", String.format("/v1/verify/auto/voice/%s", reference_id), request.getPath());
138+
}
139+
140+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package appverify;
2+
3+
import com.telesign.RestClient;
4+
import com.telesign.enterprise.AppVerifyClient;
5+
6+
import java.util.HashMap;
7+
8+
public class SendCodeAppVerify {
9+
10+
public static void main(String[] args) {
11+
12+
String customerId = System.getenv().getOrDefault("CUSTOMER_ID", "FFFFFFFF-EEEE-DDDD-1234-AB1234567890");
13+
String apiKey = System.getenv().getOrDefault("API_KEY", "EXAMPLE----ABC12345yusumoN6BYsBVkh+yRJ5czgsnCehZaOYldPJdmFh6NeX8kunZ2zU1YWaUw/0wV6xfw==");
14+
String phoneNumber = System.getenv().getOrDefault("PHONE_NUMBER", "573206419532");
15+
16+
HashMap<String, String> params = new HashMap<>();
17+
18+
try {
19+
AppVerifyClient appVerifyClient = new AppVerifyClient(customerId, apiKey);
20+
RestClient.TelesignResponse telesignResponse = appVerifyClient.sendCode(phoneNumber, params);
21+
22+
} catch (Exception e) {
23+
e.printStackTrace();
24+
}
25+
}
26+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.telesign.enterprise.example.appverify;
2+
3+
import com.telesign.RestClient;
4+
import com.telesign.enterprise.AppVerifyClient;
5+
6+
import java.util.HashMap;
7+
8+
public class SendEndCallAppVerify {
9+
10+
public static void main(String[] args) {
11+
12+
String customerId = System.getenv().getOrDefault("CUSTOMER_ID", "FFFFFFFF-EEEE-DDDD-1234-AB1234567890");
13+
String apiKey = System.getenv().getOrDefault("API_KEY", "EXAMPLE----ABC12345yusumoN6BYsBVkh+yRJ5czgsnCehZaOYldPJdmFh6NeX8kunZ2zU1YWaUw/0wV6xfw==");
14+
String referenceId = System.getenv().getOrDefault("REFERENCE_ID", "0123456789ABCDEF0123456789ABCDEF");
15+
16+
try {
17+
AppVerifyClient appVerifyClient = new AppVerifyClient(customerId, apiKey);
18+
RestClient.TelesignResponse telesignResponseEndCall = appVerifyClient.endCall(referenceId, "");
19+
} catch (Exception e) {
20+
e.printStackTrace();
21+
}
22+
}
23+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.telesign.enterprise.example.appverify;
2+
3+
import com.telesign.RestClient;
4+
import com.telesign.enterprise.AppVerifyClient;
5+
6+
public class SendGetStatusAppVerify {
7+
8+
public static void main(String[] args) {
9+
10+
String customerId = System.getenv().getOrDefault("CUSTOMER_ID", "FFFFFFFF-EEEE-DDDD-1234-AB1234567890");
11+
String apiKey = System.getenv().getOrDefault("API_KEY", "EXAMPLE----ABC12345yusumoN6BYsBVkh+yRJ5czgsnCehZaOYldPJdmFh6NeX8kunZ2zU1YWaUw/0wV6xfw==");
12+
String referenceId = System.getenv().getOrDefault("REFERENCE_ID", "0123456789ABCDEF0123456789ABCDEF");
13+
14+
try {
15+
AppVerifyClient appVerifyClient = new AppVerifyClient(customerId, apiKey);
16+
RestClient.TelesignResponse telesignResponseGetStatus = appVerifyClient.getStatus(referenceId);
17+
} catch (Exception e) {
18+
e.printStackTrace();
19+
}
20+
}
21+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.telesign.enterprise.example.appverify;
2+
3+
import com.telesign.RestClient;
4+
import com.telesign.enterprise.AppVerifyClient;
5+
6+
import java.util.HashMap;
7+
8+
public class SendReportCallerIdAppVerify {
9+
10+
public static void main(String[] args) {
11+
12+
String customerId = System.getenv().getOrDefault("CUSTOMER_ID", "FFFFFFFF-EEEE-DDDD-1234-AB1234567890");
13+
String apiKey = System.getenv().getOrDefault("API_KEY", "EXAMPLE----ABC12345yusumoN6BYsBVkh+yRJ5czgsnCehZaOYldPJdmFh6NeX8kunZ2zU1YWaUw/0wV6xfw==");
14+
String referenceId = System.getenv().getOrDefault("REFERENCE_ID", "0123456789ABCDEF0123456789ABCDEF");
15+
16+
try {
17+
AppVerifyClient appVerifyClient = new AppVerifyClient(customerId, apiKey);
18+
19+
String unknownCallerid = "test";
20+
String assignedCustomerId = "";
21+
22+
RestClient.TelesignResponse telesignResponseReportCallerId = appVerifyClient.reportCallerId(referenceId, unknownCallerid, assignedCustomerId);
23+
} catch (Exception e) {
24+
e.printStackTrace();
25+
}
26+
}
27+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.telesign.enterprise.example.appverify;
2+
3+
import com.telesign.RestClient;
4+
import com.telesign.enterprise.AppVerifyClient;
5+
6+
public class SendReportTimeoutAppVerify {
7+
8+
public static void main(String[] args) {
9+
10+
String customerId = System.getenv().getOrDefault("CUSTOMER_ID", "FFFFFFFF-EEEE-DDDD-1234-AB1234567890");
11+
String apiKey = System.getenv().getOrDefault("API_KEY", "EXAMPLE----ABC12345yusumoN6BYsBVkh+yRJ5czgsnCehZaOYldPJdmFh6NeX8kunZ2zU1YWaUw/0wV6xfw==");
12+
String referenceId = System.getenv().getOrDefault("REFERENCE_ID", "0123456789ABCDEF0123456789ABCDEF");
13+
14+
try {
15+
AppVerifyClient appVerifyClient = new AppVerifyClient(customerId, apiKey);
16+
RestClient.TelesignResponse telesignResponseReportTimeout = appVerifyClient.reportTimeout(referenceId);
17+
} catch (Exception e) {
18+
e.printStackTrace();
19+
}
20+
}
21+
}

0 commit comments

Comments
 (0)