Add CustomFriendlyName parameter to Twilio Verify requests

This commit is contained in:
Chris Eager 2021-04-19 17:53:50 -05:00 committed by Chris Eager
parent 6c37b658ac
commit 5ee56b022c
4 changed files with 25 additions and 6 deletions

View File

@ -11,6 +11,7 @@ twilio: # Twilio gateway configuration
android202103VerificationText: # Text to use for the verification message on android-2021-03 client types. Will be passed to String.format with the verification code as argument 1.
genericVerificationText: # Text to use when the client type is unrecognized. Will be passed to String.format with the verification code as argument 1.
androidAppHash: # Hash appended to Android
verifyServiceFriendlyName: # Service name used in template. Requires Twilio account rep to enable
push:
queueSize: # Size of push pending queue

View File

@ -55,6 +55,9 @@ public class TwilioConfiguration {
@NotEmpty
private String androidAppHash;
@NotEmpty
private String verifyServiceFriendlyName;
public String getAccountId() {
return accountId;
}
@ -178,4 +181,12 @@ public class TwilioConfiguration {
public void setAndroidAppHash(String androidAppHash) {
this.androidAppHash = androidAppHash;
}
public void setVerifyServiceFriendlyName(String serviceFriendlyName) {
this.verifyServiceFriendlyName = serviceFriendlyName;
}
public String getVerifyServiceFriendlyName() {
return verifyServiceFriendlyName;
}
}

View File

@ -72,6 +72,7 @@ class TwilioVerifySender {
private final URI verifyServiceUri;
private final URI verifyApprovalBaseUri;
private final String androidAppHash;
private final String verifyServiceFriendlyName;
private final FaultTolerantHttpClient httpClient;
TwilioVerifySender(String baseUri, FaultTolerantHttpClient httpClient, TwilioConfiguration twilioConfiguration) {
@ -85,7 +86,7 @@ class TwilioVerifySender {
.create(baseUri + "/v2/Services/" + twilioConfiguration.getVerifyServiceSid() + "/Verifications/");
this.androidAppHash = twilioConfiguration.getAndroidAppHash();
this.verifyServiceFriendlyName = twilioConfiguration.getVerifyServiceFriendlyName();
this.httpClient = httpClient;
}
@ -153,6 +154,7 @@ class TwilioVerifySender {
requestParameters.put("To", destination);
requestParameters.put("CustomCode", verificationCode);
requestParameters.put("Channel", channel);
requestParameters.put("CustomFriendlyName", verifyServiceFriendlyName);
locale.ifPresent(loc -> requestParameters.put("Locale", loc));
clientType.filter(client -> client.startsWith("android"))
.ifPresent(ignored -> requestParameters.put("AppHash", androidAppHash));

View File

@ -39,6 +39,7 @@ public class TwilioVerifySenderTest {
private static final String VERIFY_SERVICE_SID = "verify_service_sid";
private static final String LOCAL_DOMAIN = "test.com";
private static final String ANDROID_APP_HASH = "someHash";
private static final String SERVICE_FRIENDLY_NAME = "SignalTest";
private static final String VERIFICATION_SID = "verification";
@ -75,6 +76,7 @@ public class TwilioVerifySenderTest {
configuration.setVerifyServiceSid(VERIFY_SERVICE_SID);
configuration.setLocalDomain(LOCAL_DOMAIN);
configuration.setAndroidAppHash(ANDROID_APP_HASH);
configuration.setVerifyServiceFriendlyName(SERVICE_FRIENDLY_NAME);
return configuration;
}
@ -108,8 +110,8 @@ public class TwilioVerifySenderTest {
.withHeader("Content-Type", equalTo("application/x-www-form-urlencoded"))
.withRequestBody(equalTo(
(expectedLocale == null ? "" : "Locale=" + expectedLocale + "&")
+ "Channel=sms&To=%2B14153333333&CustomCode=123456"
+ (expectAppHash ? "&AppHash=" + ANDROID_APP_HASH : "")
+ "Channel=sms&To=%2B14153333333&CustomFriendlyName=" + SERVICE_FRIENDLY_NAME
+ "&CustomCode=123456" + (expectAppHash ? "&AppHash=" + ANDROID_APP_HASH : "")
)));
}
@ -142,7 +144,8 @@ public class TwilioVerifySenderTest {
.withHeader("Content-Type", equalTo("application/x-www-form-urlencoded"))
.withRequestBody(equalTo(
(expectedLocale == null ? "" : "Locale=" + expectedLocale + "&")
+ "Channel=call&To=%2B14153333333&CustomCode=123456")));
+ "Channel=call&To=%2B14153333333&CustomFriendlyName=" + SERVICE_FRIENDLY_NAME
+ "&CustomCode=123456")));
}
private static Object argumentsForDeliverVoxVerificationWithVerify() {
@ -171,7 +174,8 @@ public class TwilioVerifySenderTest {
verify(3, postRequestedFor(urlEqualTo("/v2/Services/" + VERIFY_SERVICE_SID + "/Verifications"))
.withHeader("Content-Type", equalTo("application/x-www-form-urlencoded"))
.withRequestBody(equalTo("Channel=sms&To=%2B14153333333&CustomCode=123456")));
.withRequestBody(equalTo("Channel=sms&To=%2B14153333333&CustomFriendlyName=" + SERVICE_FRIENDLY_NAME
+ "&CustomCode=123456")));
}
@Test
@ -190,7 +194,8 @@ public class TwilioVerifySenderTest {
verify(3, postRequestedFor(urlEqualTo("/v2/Services/" + VERIFY_SERVICE_SID + "/Verifications"))
.withHeader("Content-Type", equalTo("application/x-www-form-urlencoded"))
.withRequestBody(equalTo("Channel=call&To=%2B14153333333&CustomCode=123456")));
.withRequestBody(equalTo("Channel=call&To=%2B14153333333&CustomFriendlyName=" + SERVICE_FRIENDLY_NAME
+ "&CustomCode=123456")));
}
@Test