Skip to content

Commit b0d402c

Browse files
authored
feat: Add from to Whatsapp Interactive Verify v2 workflow (#516)
feat: Add from to WhatsappCodelessWorkflow
1 parent 3ee9d86 commit b0d402c

File tree

8 files changed

+173
-80
lines changed

8 files changed

+173
-80
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright 2024 Vonage
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.vonage.client.verify2;
17+
18+
import com.fasterxml.jackson.annotation.JsonInclude;
19+
import com.fasterxml.jackson.annotation.JsonProperty;
20+
import com.vonage.client.common.E164;
21+
22+
/**
23+
* Intermediate class for WhatsApp workflows.
24+
*
25+
* @since 8.3.0
26+
*/
27+
@JsonInclude(value = JsonInclude.Include.NON_NULL)
28+
abstract class AbstractWhatsappWorkflow extends AbstractNumberWorkflow {
29+
30+
protected AbstractWhatsappWorkflow(Builder<?, ?> builder) {
31+
super(builder);
32+
}
33+
34+
@Override
35+
protected String validateFrom(String from) {
36+
// TODO: remove this when removing deprecated constructors
37+
if (from == null) return null;
38+
return new E164(super.validateFrom(from)).toString();
39+
}
40+
41+
/**
42+
* The number to send the verification request from.
43+
*
44+
* @return The sender WABA number in E.164 format.
45+
*/
46+
@JsonProperty("from")
47+
public String getFrom() {
48+
return from;
49+
}
50+
51+
protected abstract static class Builder<
52+
N extends AbstractWhatsappWorkflow,
53+
B extends AbstractWhatsappWorkflow.Builder<? extends N, ? extends B>
54+
> extends AbstractNumberWorkflow.Builder<N, B> {
55+
56+
protected Builder(Channel channel, String to, String from) {
57+
super(channel, to);
58+
from(from);
59+
}
60+
}
61+
}

src/main/java/com/vonage/client/verify2/SilentAuthWorkflow.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public static final class Builder extends AbstractNumberWorkflow.Builder<SilentA
115115
private Boolean sandbox;
116116
private String redirectUrl;
117117

118-
Builder(String to) {
118+
private Builder(String to) {
119119
super(Channel.SILENT_AUTH, to);
120120
}
121121

src/main/java/com/vonage/client/verify2/SmsWorkflow.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public static Builder builder(String to) {
142142
public static final class Builder extends AbstractNumberWorkflow.Builder<SmsWorkflow, Builder> {
143143
private String from, appHash, contentId, entityId;
144144

145-
Builder(String to) {
145+
private Builder(String to) {
146146
super(Channel.SMS, to);
147147
}
148148

src/main/java/com/vonage/client/verify2/VerificationRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ public static final class Builder {
200200
Locale locale;
201201
List<Workflow> workflows = new ArrayList<>(1);
202202

203-
Builder() {}
203+
private Builder() {}
204204

205205
/**
206206
* (REQUIRED)

src/main/java/com/vonage/client/verify2/WhatsappCodelessWorkflow.java

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,51 @@
2323
* <a href=https://developer.vonage.com/en/verify/verify-v2/guides/using-whatsapp-interactive>
2424
* WhatsApp Interactive guide</a> for an overview of how this works.
2525
* <p>
26-
* By default, WhatsApp messages will be sent using a Vonage WhatsApp Business Account (WABA).
27-
* Please contact sales in order to configure Verify v2 to use your company’s WABA.
26+
* You must have a WhatsApp Business Account configured to use the {@code from} field, which
27+
* is now a requirement for WhatsApp workflows.
2828
*/
2929
@JsonInclude(value = JsonInclude.Include.NON_NULL)
30-
public final class WhatsappCodelessWorkflow extends AbstractNumberWorkflow {
30+
public final class WhatsappCodelessWorkflow extends AbstractWhatsappWorkflow {
31+
32+
WhatsappCodelessWorkflow(Builder builder) {
33+
super(builder);
34+
}
3135

3236
/**
3337
* Constructs a new WhatsApp interactive verification workflow.
3438
*
3539
* @param to The number to send the verification prompt to, in E.164 format.
40+
* @deprecated This no longer works and will be removed in a future release.
3641
*/
42+
@Deprecated
3743
public WhatsappCodelessWorkflow(String to) {
38-
super(Channel.WHATSAPP_INTERACTIVE, to);
44+
this(to, null);
45+
}
46+
47+
/**
48+
* Constructs a new WhatsApp interactive verification workflow.
49+
*
50+
* @param to The number to send the verification prompt to, in E.164 format.
51+
* @param from The WhatsApp Business Account number to send the message from, in E.164 format.
52+
* @since 8.3.0
53+
*/
54+
public WhatsappCodelessWorkflow(String to, String from) {
55+
this(builder(to, from));
56+
}
57+
58+
static Builder builder(String to, String from) {
59+
return new Builder(to, from);
60+
}
61+
62+
static class Builder extends AbstractWhatsappWorkflow.Builder<WhatsappCodelessWorkflow, Builder> {
63+
64+
private Builder(String to, String from) {
65+
super(Channel.WHATSAPP_INTERACTIVE, to, from);
66+
}
67+
68+
@Override
69+
public WhatsappCodelessWorkflow build() {
70+
return new WhatsappCodelessWorkflow(this);
71+
}
3972
}
4073
}

src/main/java/com/vonage/client/verify2/WhatsappWorkflow.java

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,15 @@
1616
package com.vonage.client.verify2;
1717

1818
import com.fasterxml.jackson.annotation.JsonInclude;
19-
import com.fasterxml.jackson.annotation.JsonProperty;
2019

2120
/**
2221
* Defines properties for sending a verification code to a user over a WhatsApp message.
2322
* <p>
24-
* By default, WhatsApp messages will be sent using a Vonage WhatsApp Business Account (WABA).
25-
* Please contact sales in order to configure Verify v2 to use your company’s WABA.
23+
* You must have a WhatsApp Business Account configured to use the {@code from} field, which
24+
* is now a requirement for WhatsApp workflows.
2625
*/
2726
@JsonInclude(value = JsonInclude.Include.NON_NULL)
28-
public final class WhatsappWorkflow extends AbstractNumberWorkflow {
27+
public final class WhatsappWorkflow extends AbstractWhatsappWorkflow {
2928

3029
WhatsappWorkflow(Builder builder) {
3130
super(builder);
@@ -35,7 +34,9 @@ public final class WhatsappWorkflow extends AbstractNumberWorkflow {
3534
* Constructs a new WhatsApp verification workflow.
3635
*
3736
* @param to The number to send the message to, in E.164 format.
37+
* @deprecated This no longer works and will be removed in a future release.
3838
*/
39+
@Deprecated
3940
public WhatsappWorkflow(String to) {
4041
this(to, null);
4142
}
@@ -44,31 +45,20 @@ public WhatsappWorkflow(String to) {
4445
* Constructs a new WhatsApp verification workflow with a custom sender number.
4546
*
4647
* @param to The number to send the message to, in E.164 format.
47-
* @param from The number to send the message from, in E.164 format.
48-
* Note that you will need to get in touch with the Vonage sales team to enable use of the field.
48+
* @param from The WhatsApp Business Account number to send the message from, in E.164 format.
4949
*/
5050
public WhatsappWorkflow(String to, String from) {
51-
this(builder(to).from(from));
51+
this(builder(to, from));
5252
}
5353

54-
/**
55-
* The number to send the verification request from, if configured.
56-
*
57-
* @return The sender phone number, or {@code null} if unset.
58-
*/
59-
@JsonProperty("from")
60-
public String getFrom() {
61-
return from;
62-
}
63-
64-
static Builder builder(String to) {
65-
return new Builder(to);
54+
static Builder builder(String to, String from) {
55+
return new Builder(to, from);
6656
}
6757

68-
static class Builder extends AbstractNumberWorkflow.Builder<WhatsappWorkflow, Builder> {
58+
static class Builder extends AbstractWhatsappWorkflow.Builder<WhatsappWorkflow, Builder> {
6959

70-
Builder(String to) {
71-
super(Channel.WHATSAPP, to);
60+
Builder(String to, String from) {
61+
super(Channel.WHATSAPP, to, from);
7262
}
7363

7464
@Override

0 commit comments

Comments
 (0)