Package com.vonage.client.messages
Class MessagesClient
java.lang.Object
com.vonage.client.messages.MessagesClient
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidackInboundMessage(String messageId, ApiRegion region) Marks an inbound message as "read".voidrevokeOutboundMessage(String messageId, ApiRegion region) Revokes an outbound message.sendMessage(MessageRequest request) Sends a message.Calling this method will make the client use the regular endpoint returned byHttpConfig.getApiBaseUri(), which is the default behaviour.Calling this method will make the client use the sandbox endpoint, which will enable you to use the Messages Sandbox.static booleanverifySignature(String jwt, String secret) Utility method for verifying whether a token was signed by a secret.
-
Constructor Details
-
MessagesClient
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, aMessageResponsewill be returned containing the unique identifier of the message. Otherwise, aMessageResponseExceptionwill 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 byHttpConfig.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
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
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:
trueif the token was signed by the secret,falseotherwise.- Since:
- 7.11.0
-