001/* 002 * Copyright 2024 Vonage 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package com.vonage.client.messages.whatsapp; 017 018import com.fasterxml.jackson.annotation.JsonProperty; 019import com.vonage.client.common.E164; 020import com.vonage.client.messages.Channel; 021import com.vonage.client.messages.MessageRequest; 022import com.vonage.client.messages.MessageType; 023import java.util.UUID; 024 025public abstract class WhatsappRequest extends MessageRequest { 026 final Context context; 027 028 protected WhatsappRequest(Builder<?, ?> builder, MessageType messageType) { 029 super(builder, Channel.WHATSAPP, messageType); 030 context = builder.messageUuid != null ? new Context(builder.messageUuid) : null; 031 } 032 033 @Override 034 protected void validateSenderAndRecipient(String from, String to) throws IllegalArgumentException { 035 this.from = new E164(from).toString(); 036 this.to = new E164(to).toString(); 037 } 038 039 @JsonProperty("context") 040 public Context getContext() { 041 return context; 042 } 043 044 @SuppressWarnings("unchecked") 045 protected abstract static class Builder<M extends WhatsappRequest, B extends Builder<? extends M, ? extends B>> extends MessageRequest.Builder<M, B> { 046 UUID messageUuid; 047 048 /** 049 * (REQUIRED for replies and reaction messages) 050 * An optional context used for quoting/replying to a specific message in a conversation. When used, 051 * the WhatsApp UI will display the new message along with a contextual bubble that displays the 052 * quoted/replied to message's content.<br> 053 * This field is the UUID of the message being replied to or quoted. 054 * 055 * @param messageUuid The context's message UUID as a string. 056 * 057 * @return This builder. 058 * @since 8.7.0 059 */ 060 public B contextMessageId(String messageUuid) { 061 this.messageUuid = UUID.fromString(messageUuid); 062 return (B) this; 063 } 064 } 065}