Skip to content

Commit

Permalink
feat: Add Verify2 SMS from field
Browse files Browse the repository at this point in the history
  • Loading branch information
SMadani committed Dec 13, 2023
1 parent 4b64ecf commit f16c059
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
31 changes: 29 additions & 2 deletions src/main/java/com/vonage/client/verify2/SmsWorkflow.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,26 @@ public SmsWorkflow(String to) {
* Constructs a new SMS verification workflow.
*
* @param to The number to send the message to, in E.164 format.
*
* @param appHash Android Application Hash Key for automatic code detection on a user's device.
*
* @deprecated Use {@linkplain #SmsWorkflow(String, String, String)}.
*/
@Deprecated
public SmsWorkflow(String to, String appHash) {
super(Channel.SMS, new E164(to).toString());
this(to, null, appHash);
}

/**
* Constructs a new SMS verification workflow.
*
* @param to The number to send the message to, in E.164 format.
* @param from The number or sender ID to send the SMS from.
* @param appHash Android Application Hash Key for automatic code detection on a user's device.
*
* @since 8.1.0
*/
public SmsWorkflow(String to, String from, String appHash) {
super(Channel.SMS, new E164(to).toString(), from);
if ((this.appHash = appHash) != null && appHash.length() != 11) {
throw new IllegalArgumentException("Android app hash must be 11 characters.");
}
Expand All @@ -58,4 +73,16 @@ public SmsWorkflow(String to, String appHash) {
public String getAppHash() {
return appHash;
}

/**
* The number or sender ID the message will be sent from.
*
* @return The sender phone number or sender ID, or {@code null} if unspecified.
*
* @since 8.1.0
*/
@JsonProperty("from")
public String getFrom() {
return from;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Workflow getWorkflowAllParamsForChannel(Channel channel) {
case SILENT_AUTH:
return new SilentAuthWorkflow(TO_NUMBER, SANDBOX, REDIRECT_URL);
case SMS:
return new SmsWorkflow(TO_NUMBER, APP_HASH);
return new SmsWorkflow(TO_NUMBER, FROM_NUMBER, APP_HASH);
case WHATSAPP:
return new WhatsappWorkflow(TO_NUMBER, FROM_NUMBER);
case EMAIL:
Expand Down Expand Up @@ -107,7 +107,7 @@ String getExpectedAllParamsForSingleWorkflowJson(Channel channel) {
replacement = prefix + ",\"app_hash\":\""+APP_HASH+"\"";
expectedJson = expectedJson.replace(prefix, replacement);
}
if (channel == Channel.WHATSAPP) {
if (channel == Channel.WHATSAPP || channel == Channel.SMS) {
prefix = TO_NUMBER + '"';
replacement = prefix + ",\"from\":\""+FROM_NUMBER+"\"";
expectedJson = expectedJson.replace(prefix, replacement);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,16 @@ protected String expectedEndpointUri(VerificationRequest request) {
protected VerificationRequest sampleRequest() {
return VerificationRequest.builder()
.clientRef("my-personal-reference").locale("ar-XA")
.addWorkflow(new SmsWorkflow("447700900001", "FA+9qCX9VSu"))
.addWorkflow(new SmsWorkflow("447700900001", "447900000002", "FA+9qCX9VSu"))
.brand("ACME, Inc").codeLength(6).channelTimeout(320).build();
}

@Override
protected String sampleRequestBodyString() {
return "{\"locale\":\"ar-xa\",\"channel_timeout\":320,\"code_length\":6," +
"\"brand\":\"ACME, Inc\",\"client_ref\":\"my-personal-reference\",\"workflow\":" +
"[{\"channel\":\"sms\",\"to\":\"447700900001\",\"app_hash\":\"FA+9qCX9VSu\"}]}";
"\"brand\":\"ACME, Inc\",\"client_ref\":\"my-personal-reference\"," +
"\"workflow\":[{\"channel\":\"sms\",\"to\":\"447700900001\"," +
"\"from\":\"447900000002\",\"app_hash\":\"FA+9qCX9VSu\"}]}";
}

@Override
Expand Down

0 comments on commit f16c059

Please sign in to comment.