Class MessageRequest.Builder<M extends MessageRequest,B extends MessageRequest.Builder<? extends M,? extends B>>

java.lang.Object
com.vonage.client.messages.MessageRequest.Builder<M,B>
Type Parameters:
M - The type of MessageRequest that will be constructed when calling the build() method.
B - The type of Builder that will be returned when chaining method calls. This is necessary to enable the methods to be called in any order and still return the most specific concrete subtype of builder, rather than this base class.
Direct Known Subclasses:
MessengerRequest.Builder, MmsRequest.Builder, RcsRequest.Builder, SmsTextRequest.Builder, ViberRequest.Builder, WhatsappRequest.Builder
Enclosing class:
MessageRequest

public abstract static class MessageRequest.Builder<M extends MessageRequest,B extends MessageRequest.Builder<? extends M,? extends B>> extends Object
Mutable Builder class, designed to simulate named parameters to allow for convenient construction of MessageRequests. Subclasses should add their own mutable parameters and a method for setting them whilst returning the builder, to allow for chaining.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Protected constructor to prevent users from explicitly creating this object.
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract M
    Builds the MessageRequest.
    protected B
    caption(String caption)
    (OPTIONAL) Additional text to accompany the media.
    clientRef(String clientRef)
    (OPTIONAL) Sets the client reference, which will be present in every message status.
    protected B
    custom(Map<String,?> payload)
    (REQUIRED) Custom payload.
    from(String from)
    (REQUIRED) Sets the sender number or ID.
    protected B
    name(String name)
    (OPTIONAL) The media name.
    protected B
    text(String text)
    (REQUIRED) Sets the text field.
    to(String to)
    (REQUIRED) Sets the recipient number or ID.
    protected B
    ttl(int ttl)
    (OPTIONAL) The duration in milliseconds the delivery of a message will be attempted.
    protected B
    url(String url)
    (REQUIRED) Sets the media URL.
    webhookUrl(String webhookUrl)
    (OPTIONAL) Specifies the URL to which Status Webhook messages will be sent for this particular message.
    Specifies which version of the Messages API will be used to send Status Webhook messages for this particular message.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Builder

      protected Builder()
      Protected constructor to prevent users from explicitly creating this object. This should only be called by the static builder() method in the non-abstract subclasses of this builder's parent (declaring) class.
  • Method Details

    • from

      public B from(String from)
      (REQUIRED) Sets the sender number or ID.
      Parameters:
      from - The number or ID to send the message from.
      Returns:
      This builder.
    • custom

      protected B custom(Map<String,?> payload)
      (REQUIRED) Custom payload. The schema of a custom object can vary widely according to the channel. Please consult the relevant documentation for details.
      Parameters:
      payload - The custom payload properties to send as a Map.
      Returns:
      This builder.
    • to

      public B to(String to)
      (REQUIRED) Sets the recipient number or ID.
      Parameters:
      to - The number or ID to send the message to.
      Returns:
      This builder.
    • clientRef

      public B clientRef(String clientRef)
      (OPTIONAL) Sets the client reference, which will be present in every message status.
      Parameters:
      clientRef - Client reference of up to 40 characters.
      Returns:
      This builder.
    • webhookUrl

      public B webhookUrl(String webhookUrl)
      (OPTIONAL) Specifies the URL to which Status Webhook messages will be sent for this particular message. Overrides account-level and application-level Status Webhook url settings on a per-message basis.
      Parameters:
      webhookUrl - The status webhook URL as a string.
      Returns:
      This builder.
      Since:
      8.1.0
    • webhookVersion

      public B webhookVersion(MessagesVersion webhookVersion)
      Specifies which version of the Messages API will be used to send Status Webhook messages for this particular message. For example, if MessagesVersion.V0_1 is set, then the JSON body of Status Webhook messages for this message will be sent in Messages v0.1 format. Over-rides account-level and application-level API version settings on a per-message basis.
      Parameters:
      webhookVersion - The messages API version enum.
      Returns:
      This builder.
      Since:
      8.1.0
    • ttl

      protected B ttl(int ttl)
      (OPTIONAL) The duration in milliseconds the delivery of a message will be attempted. By default, Vonage attempts delivery for 72 hours, however the maximum effective value depends on the operator and is typically 24 to 48 hours. We recommend this value should be kept at its default or at least 30 minutes.
      Parameters:
      ttl - The time-to-live for this message before abandoning delivery attempts, in milliseconds.
      Returns:
      This builder.
    • text

      protected B text(String text)
      (REQUIRED) Sets the text field.
      Parameters:
      text - The text string.
      Returns:
      This builder.
    • url

      protected B url(String url)
      (REQUIRED) Sets the media URL.
      Parameters:
      url - The URL as a string.
      Returns:
      This builder.
    • caption

      protected B caption(String caption)
      (OPTIONAL) Additional text to accompany the media. Must be between 1 and 2000 characters.
      Parameters:
      caption - The caption string.
      Returns:
      This builder.
    • name

      protected B name(String name)
      (OPTIONAL) The media name.
      Parameters:
      name - The name string.
      Returns:
      This builder.
    • build

      public abstract M build()
      Builds the MessageRequest.
      Returns:
      A MessageRequest, populated with all fields from this builder.