Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add Verify2 SMS from field #501

Merged
merged 1 commit into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading