Package com.vonage.client.messages
Class MessageRequest
java.lang.Object
com.vonage.client.JsonableBaseObject
com.vonage.client.messages.MessageRequest
- All Implemented Interfaces:
Jsonable
- Direct Known Subclasses:
MessengerRequest,MmsRequest,RcsRequest,SmsTextRequest,ViberRequest,WhatsappRequest
Abstract base class of all Messages sent via the Messages v1 API. All subclasses follow a
builder pattern to enable easy construction. The design philosophy is "correct by construction":
that is, validation occurs when calling the
MessageRequest.Builder.build() method. It is still the
responsibility of the user to ensure all required parameters are set. The Javadoc for each parameter
in the builders indicates whether it is mandatory (REQUIRED) or not (OPTIONAL). Failure to specify
mandatory parameters will result in NullPointerException being thrown. Parameters which are
invalid (i.e. have malformed values, such as empty strings) will result in IllegalArgumentException
being thrown. The documentation on each parameter should provide clarity on parameter restrictions.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classMessageRequest.Builder<M extends MessageRequest,B extends MessageRequest.Builder<? extends M, ? extends B>> Mutable Builder class, designed to simulate named parameters to allow for convenient construction of MessageRequests. -
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedMessageRequest(MessageRequest.Builder<?, ?> builder, Channel channel, MessageType messageType) Constructor where all of this class's fields should be set. -
Method Summary
Modifier and TypeMethodDescriptiongetFrom()protected StringgetText()getTo()protected IntegergetTtl()protected intSets the maximum text length for text messages.protected StringvalidateClientReference(String clientRef) Validates and possibly sanitizes the client reference.protected voidvalidateSenderAndRecipient(String from, String to) This method is used to validate the format of sender and recipient fields.Methods inherited from class com.vonage.client.JsonableBaseObject
createJsonObjectMapper, equals, hashCode, toStringMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface com.vonage.client.Jsonable
toJson, updateFromJson
-
Field Details
-
from
-
to
-
ttl
-
custom
-
media
-
-
Constructor Details
-
MessageRequest
protected MessageRequest(MessageRequest.Builder<?, ?> builder, Channel channel, MessageType messageType) Constructor where all of this class's fields should be set. This is protected to prevent users form explicitly calling it; this should only be called from theMessageRequest.Builder.build()method. Subclasses should hide this constructor as well to avoid potentially confusing users on how to construct this object.- Parameters:
builder- The mutable builder object used to assign this MessageRequest's fields from.channel- The service to send the message through.messageType- The type of message to send.
-
-
Method Details
-
validateClientReference
Validates and possibly sanitizes the client reference.- Parameters:
clientRef- The clientRef field passed in from the builder.- Returns:
- The clientRef to use; usually the same as the argument.
-
validateSenderAndRecipient
This method is used to validate the format of sender and recipient fields. By default, this method checks that the recipient is an E164-compliant number and that the sender is not blank. Subclasses may re-assign the sender and recipient fields to be well-formed / standardised / compliant.- Parameters:
from- The sender number or ID passed in from the builder.to- The recipient number or ID passed in from the builder.- Throws:
IllegalArgumentException- If the sender or recipient are invalid / malformed.
-
maxTextLength
Sets the maximum text length for text messages.- Returns:
- The maximum text message string length.
- Since:
- 8.11.0
-
getMessageType
-
getChannel
-
getFrom
-
getTo
-
getClientRef
-
getWebhookUrl
-
getWebhookVersion
-
getTtl
-
getText
-
getCustom
-