From f16c059d60f1f92d2a8788a359989aa6af355686 Mon Sep 17 00:00:00 2001 From: Sina Madani Date: Wed, 13 Dec 2023 18:00:24 +0000 Subject: [PATCH] feat: Add Verify2 SMS from field --- .../vonage/client/verify2/SmsWorkflow.java | 31 +++++++++++++++++-- .../verify2/VerificationRequestTest.java | 4 +-- .../client/verify2/Verify2ClientTest.java | 7 +++-- 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/vonage/client/verify2/SmsWorkflow.java b/src/main/java/com/vonage/client/verify2/SmsWorkflow.java index 812aaa462..2a00cc977 100644 --- a/src/main/java/com/vonage/client/verify2/SmsWorkflow.java +++ b/src/main/java/com/vonage/client/verify2/SmsWorkflow.java @@ -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."); } @@ -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; + } } diff --git a/src/test/java/com/vonage/client/verify2/VerificationRequestTest.java b/src/test/java/com/vonage/client/verify2/VerificationRequestTest.java index 79bd86e27..4d3ebf15b 100644 --- a/src/test/java/com/vonage/client/verify2/VerificationRequestTest.java +++ b/src/test/java/com/vonage/client/verify2/VerificationRequestTest.java @@ -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: @@ -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); diff --git a/src/test/java/com/vonage/client/verify2/Verify2ClientTest.java b/src/test/java/com/vonage/client/verify2/Verify2ClientTest.java index 270f37856..91d41073a 100644 --- a/src/test/java/com/vonage/client/verify2/Verify2ClientTest.java +++ b/src/test/java/com/vonage/client/verify2/Verify2ClientTest.java @@ -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