Class MessagesClient

java.lang.Object
com.vonage.client.messages.MessagesClient

public class MessagesClient extends Object
  • Constructor Details

    • MessagesClient

      public MessagesClient(HttpWrapper wrapper)
      Create a new MessagesClient.
      Parameters:
      wrapper - Http Wrapper used to create message requests.
  • Method Details

    • sendMessage

      Sends a message. The details of its format, channel, sender, recipient etc. are specified entirely by the type and contents of the MessageRequest. For example, to send a text via Viber, you would construct the request like so:
      
           ViberTextRequest request = ViberTextRequest.builder()
               .from("My Company")
               .to("447700900000")
               .text("Hello from Vonage!")
               .build();
       

      If the message was sent successfully, a MessageResponse will be returned containing the unique identifier of the message. Otherwise, a MessageResponseException will be thrown, which contains details of why the request failed.
      Parameters:
      request - The message request object, as described above.
      Returns:
      The response, if the request was successful (i.e.a 202 was received from the server).
      Throws:
      MessageResponseException - If the message could not be sent. This could be for the following reasons:
      • 401: Missing or invalid credentials.
      • 402: Low balance.
      • 422: Invalid request parameters.
      • 429: Rate limit hit. Please wait and try again.
      • 500: Internal server error.
    • useSandboxEndpoint

      Calling this method will make the client use the sandbox endpoint, which will enable you to use the Messages Sandbox.
      Returns:
      This MessagesClient, for convenience.
      Since:
      7.1.0
    • useRegularEndpoint

      Calling this method will make the client use the regular endpoint returned by HttpConfig.getApiBaseUri(), which is the default behaviour. This method is provided for convenience if you wish to switch between sandbox and non-sandbox mode.
      Returns:
      This MessagesClient, for convenience.
      Since:
      7.1.0
      See Also:
    • ackInboundMessage

      public void ackInboundMessage(String messageId, ApiRegion region) throws MessageResponseException
      Marks an inbound message as "read". Currently, this only applies to WhatsApp messages.
      Parameters:
      messageId - UUID of the message to acknowledge.
      region - The regional server to use for this request. This must match the region of the message.
      Throws:
      MessageResponseException - If the acknowledgement fails. This could be for the following reasons:
      • 401: Missing or invalid credentials.
      • 404: Message not found.
      • 422: Operation not supported for this channel.
      • 429: Rate limit hit. Please wait and try again.
      • 500: Internal server error.
      Since:
      8.11.0
    • revokeOutboundMessage

      public void revokeOutboundMessage(String messageId, ApiRegion region) throws MessageResponseException
      Revokes an outbound message. Currently, this only applies to RCS messages.
      Parameters:
      messageId - UUID of the message to revoke.
      region - The regional server to use for this request. This must match the region of the message.
      Throws:
      MessageResponseException - If the acknowledgement fails. This could be for the following reasons:
      • 401:Missing or invalid credentials.
      • 404:Message not found.
      • 422:Operation not supported for this channel.
      • 429:Rate limit hit. Please wait and try again.
      • 500:Internal server error.
      Since:
      8.11.0
    • verifySignature

      public static boolean verifySignature(String jwt, String secret)
      Utility method for verifying whether a token was signed by a secret. This is mostly useful when using signed callbacks to ensure that the inbound data came from Vonage servers. The signature is performed using the SHA-256 HMAC algorithm.
      Parameters:
      jwt - The JSON Web Token to verify.
      secret - The symmetric secret key (HS256) to use for decrypting the token's signature.
      Returns:
      true if the token was signed by the secret, false otherwise.
      Since:
      7.11.0