Skip to content

Commit

Permalink
feat: Add from to WhatsappCodelessWorkflow
Browse files Browse the repository at this point in the history
  • Loading branch information
SMadani committed Feb 12, 2024
1 parent 3ee9d86 commit 7ae76ef
Show file tree
Hide file tree
Showing 8 changed files with 173 additions and 80 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright 2024 Vonage
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.vonage.client.verify2;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.vonage.client.common.E164;

/**
* Intermediate class for WhatsApp workflows.
*
* @since 8.3.0
*/
@JsonInclude(value = JsonInclude.Include.NON_NULL)
abstract class AbstractWhatsappWorkflow extends AbstractNumberWorkflow {

protected AbstractWhatsappWorkflow(Builder<?, ?> builder) {
super(builder);
}

@Override
protected String validateFrom(String from) {
// TODO: remove this when removing deprecated constructors
if (from == null) return null;
return new E164(super.validateFrom(from)).toString();
}

/**
* The number to send the verification request from.
*
* @return The sender WABA number in E.164 format.
*/
@JsonProperty("from")
public String getFrom() {
return from;
}

protected abstract static class Builder<
N extends AbstractWhatsappWorkflow,
B extends AbstractWhatsappWorkflow.Builder<? extends N, ? extends B>
> extends AbstractNumberWorkflow.Builder<N, B> {

protected Builder(Channel channel, String to, String from) {
super(channel, to);
from(from);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public static final class Builder extends AbstractNumberWorkflow.Builder<SilentA
private Boolean sandbox;
private String redirectUrl;

Builder(String to) {
private Builder(String to) {
super(Channel.SILENT_AUTH, to);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/vonage/client/verify2/SmsWorkflow.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public static Builder builder(String to) {
public static final class Builder extends AbstractNumberWorkflow.Builder<SmsWorkflow, Builder> {
private String from, appHash, contentId, entityId;

Builder(String to) {
private Builder(String to) {
super(Channel.SMS, to);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public static final class Builder {
Locale locale;
List<Workflow> workflows = new ArrayList<>(1);

Builder() {}
private Builder() {}

/**
* (REQUIRED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,51 @@
* <a href=https://developer.vonage.com/en/verify/verify-v2/guides/using-whatsapp-interactive>
* WhatsApp Interactive guide</a> for an overview of how this works.
* <p>
* By default, WhatsApp messages will be sent using a Vonage WhatsApp Business Account (WABA).
* Please contact sales in order to configure Verify v2 to use your company’s WABA.
* You must have a WhatsApp Business Account configured to use the {@code from} field, which
* is now a requirement for WhatsApp workflows.
*/
@JsonInclude(value = JsonInclude.Include.NON_NULL)
public final class WhatsappCodelessWorkflow extends AbstractNumberWorkflow {
public final class WhatsappCodelessWorkflow extends AbstractWhatsappWorkflow {

WhatsappCodelessWorkflow(Builder builder) {
super(builder);
}

/**
* Constructs a new WhatsApp interactive verification workflow.
*
* @param to The number to send the verification prompt to, in E.164 format.
* @deprecated This no longer works and will be removed in a future release.
*/
@Deprecated
public WhatsappCodelessWorkflow(String to) {
super(Channel.WHATSAPP_INTERACTIVE, to);
this(to, null);
}

/**
* Constructs a new WhatsApp interactive verification workflow.
*
* @param to The number to send the verification prompt to, in E.164 format.
* @param from The WhatsApp Business Account number to send the message from, in E.164 format.
* @since 8.3.0
*/
public WhatsappCodelessWorkflow(String to, String from) {
this(builder(to, from));
}

static Builder builder(String to, String from) {
return new Builder(to, from);
}

static class Builder extends AbstractWhatsappWorkflow.Builder<WhatsappCodelessWorkflow, Builder> {

private Builder(String to, String from) {
super(Channel.WHATSAPP_INTERACTIVE, to, from);
}

@Override
public WhatsappCodelessWorkflow build() {
return new WhatsappCodelessWorkflow(this);
}
}
}
34 changes: 12 additions & 22 deletions src/main/java/com/vonage/client/verify2/WhatsappWorkflow.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@
package com.vonage.client.verify2;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;

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

WhatsappWorkflow(Builder builder) {
super(builder);
Expand All @@ -35,7 +34,9 @@ public final class WhatsappWorkflow extends AbstractNumberWorkflow {
* Constructs a new WhatsApp verification workflow.
*
* @param to The number to send the message to, in E.164 format.
* @deprecated This no longer works and will be removed in a future release.
*/
@Deprecated
public WhatsappWorkflow(String to) {
this(to, null);
}
Expand All @@ -44,31 +45,20 @@ public WhatsappWorkflow(String to) {
* Constructs a new WhatsApp verification workflow with a custom sender number.
*
* @param to The number to send the message to, in E.164 format.
* @param from The number to send the message from, in E.164 format.
* Note that you will need to get in touch with the Vonage sales team to enable use of the field.
* @param from The WhatsApp Business Account number to send the message from, in E.164 format.
*/
public WhatsappWorkflow(String to, String from) {
this(builder(to).from(from));
this(builder(to, from));
}

/**
* The number to send the verification request from, if configured.
*
* @return The sender phone number, or {@code null} if unset.
*/
@JsonProperty("from")
public String getFrom() {
return from;
}

static Builder builder(String to) {
return new Builder(to);
static Builder builder(String to, String from) {
return new Builder(to, from);
}

static class Builder extends AbstractNumberWorkflow.Builder<WhatsappWorkflow, Builder> {
static class Builder extends AbstractWhatsappWorkflow.Builder<WhatsappWorkflow, Builder> {

Builder(String to) {
super(Channel.WHATSAPP, to);
Builder(String to, String from) {
super(Channel.WHATSAPP, to, from);
}

@Override
Expand Down
Loading

0 comments on commit 7ae76ef

Please sign in to comment.