Skip to content

Commit f93e5cd

Browse files
committed
feat: Q3 2024 Messages API updates
1 parent 7e4b3c4 commit f93e5cd

File tree

5 files changed

+340
-11
lines changed

5 files changed

+340
-11
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/)
55
and this project adheres to [Semantic Versioning](http://semver.org/).
66

7+
## [1.0.0-RC2] - 2024-09-2?
8+
Messages API updates based on Java SDK v8.11.0
9+
10+
### Added
11+
- RCS message type builders
12+
- WhatsApp Reaction builder
13+
- Ability to read and revoke messages (support for the `PATCH` endpoint in Messages API)
14+
715
## [1.0.0-RC1] - 2024-09-12
816
First release candidate
917

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>com.vonage</groupId>
77
<artifactId>server-sdk-kotlin</artifactId>
8-
<version>1.0.0-RC1</version>
8+
<version>1.0.0-RC2</version>
99

1010
<name>Vonage Kotlin Server SDK</name>
1111
<description>Kotlin client for Vonage APIs</description>
@@ -55,7 +55,7 @@
5555
<dependency>
5656
<groupId>com.vonage</groupId>
5757
<artifactId>server-sdk</artifactId>
58-
<version>8.10.0</version>
58+
<version>8.11.0</version>
5959
</dependency>
6060
<dependency>
6161
<groupId>org.jetbrains.kotlin</groupId>
@@ -228,7 +228,7 @@
228228
<plugins>
229229
<plugin>
230230
<artifactId>maven-gpg-plugin</artifactId>
231-
<version>3.2.5</version>
231+
<version>3.2.6</version>
232232
<executions>
233233
<execution>
234234
<id>sign-artifacts</id>

src/main/kotlin/com/vonage/client/kt/Messages.kt

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@
1515
*/
1616
package com.vonage.client.kt
1717

18+
import com.vonage.client.ApiRegion
1819
import com.vonage.client.messages.*
1920
import com.vonage.client.messages.sms.*
2021
import com.vonage.client.messages.mms.*
2122
import com.vonage.client.messages.whatsapp.*
2223
import com.vonage.client.messages.messenger.*
2324
import com.vonage.client.messages.viber.*
25+
import com.vonage.client.messages.rcs.*
2426
import java.util.UUID
2527

2628
/**
@@ -54,6 +56,51 @@ class Messages internal constructor(private val client: MessagesClient) {
5456
fun send(message: MessageRequest, sandbox: Boolean = false): UUID =
5557
(if (sandbox) client.useSandboxEndpoint()
5658
else client.useRegularEndpoint()).sendMessage(message).messageUuid
59+
60+
/**
61+
* Call this method to update an existing message.
62+
*
63+
* @param id The message UUID as a string.
64+
* @param region The API region server URL in which the message was sent.
65+
*
66+
* @return An [ExistingMessage] object for updating the existing message.
67+
*/
68+
fun existingMessage(id: String, region: ApiRegion): ExistingMessage = ExistingMessage(id, region)
69+
70+
/**
71+
* Class for working with an existing message.
72+
*
73+
* @property id The message ID.
74+
* @property region The regional URL server in which the message was sent.
75+
*/
76+
inner class ExistingMessage internal constructor(id: String, val region: ApiRegion): ExistingResource(id) {
77+
78+
/**
79+
* Marks the inbound message as read. Currently only applies to the WhatsApp channel.
80+
*
81+
* @throws [MessageResponseException] If the message could not be updated.
82+
* This may be for the following reasons:
83+
* - **401**: Invalid credentials.
84+
* - **404**: Not Found. The message ID is not known, or the wrong region was used.
85+
* - **422**: Malformed request.
86+
* - **429**: Too many requests.
87+
* - **500**: Internal server error.
88+
*/
89+
fun markAsRead(): Unit = client.ackInboundMessage(id, region)
90+
91+
/**
92+
* Revokes the outbound message. Currently only applies to the RCS channel.
93+
*
94+
* @throws [MessageResponseException] If the message could not be updated.
95+
* This may be for the following reasons:
96+
* - **401**: Invalid credentials.
97+
* - **404**: Not Found. The message ID is not known, or the wrong region was used.
98+
* - **422**: Malformed request.
99+
* - **429**: Too many requests.
100+
* - **500**: Internal server error.
101+
*/
102+
fun revoke(): Unit = client.revokeOutboundMessage(id, region)
103+
}
57104
}
58105

59106
/**
@@ -166,6 +213,16 @@ fun whatsappFile(properties: WhatsappFileRequest.Builder.() -> Unit): WhatsappFi
166213
fun whatsappSticker(properties: WhatsappStickerRequest.Builder.() -> Unit): WhatsappStickerRequest =
167214
WhatsappStickerRequest.builder().apply(properties).build()
168215

216+
/**
217+
* Creates a WhatsApp reaction message.
218+
*
219+
* @param properties A lambda function for setting the message's parameters.
220+
*
221+
* @return A [WhatsappReactionRequest] object with the specified properties.
222+
*/
223+
fun whatsappReaction(properties: WhatsappReactionRequest.Builder.() -> Unit): WhatsappReactionRequest =
224+
WhatsappReactionRequest.builder().apply(properties).build()
225+
169226
/**
170227
* Creates a WhatsApp location message.
171228
*
@@ -305,3 +362,53 @@ fun viberVideo(properties: ViberVideoRequest.Builder.() -> Unit): ViberVideoRequ
305362
*/
306363
fun viberFile(properties: ViberFileRequest.Builder.() -> Unit): ViberFileRequest =
307364
ViberFileRequest.builder().apply(properties).build()
365+
366+
/**
367+
* Creates an RCS text message.
368+
*
369+
* @param properties A lambda function for setting the message's parameters.
370+
*
371+
* @return An [RcsTextRequest] object with the specified properties.
372+
*/
373+
fun rcsText(properties: RcsTextRequest.Builder.() -> Unit): RcsTextRequest =
374+
RcsTextRequest.builder().apply(properties).build()
375+
376+
/**
377+
* Creates an RCS image message.
378+
*
379+
* @param properties A lambda function for setting the message's parameters.
380+
*
381+
* @return An [RcsImageRequest] object with the specified properties.
382+
*/
383+
fun rcsImage(properties: RcsImageRequest.Builder.() -> Unit): RcsImageRequest =
384+
RcsImageRequest.builder().apply(properties).build()
385+
386+
/**
387+
* Creates an RCS video message.
388+
*
389+
* @param properties A lambda function for setting the message's parameters.
390+
*
391+
* @return An [RcsVideoRequest] object with the specified properties.
392+
*/
393+
fun rcsVideo(properties: RcsVideoRequest.Builder.() -> Unit): RcsVideoRequest =
394+
RcsVideoRequest.builder().apply(properties).build()
395+
396+
/**
397+
* Creates an RCS file message.
398+
*
399+
* @param properties A lambda function for setting the message's parameters.
400+
*
401+
* @return An [RcsFileRequest] object with the specified properties.
402+
*/
403+
fun rcsFile(properties: RcsFileRequest.Builder.() -> Unit): RcsFileRequest =
404+
RcsFileRequest.builder().apply(properties).build()
405+
406+
/**
407+
* Creates an RCS custom message.
408+
*
409+
* @param properties A lambda function for setting the message's parameters.
410+
*
411+
* @return An [RcsCustomRequest] object with the specified properties.
412+
*/
413+
fun rcsCustom(properties: RcsCustomRequest.Builder.() -> Unit): RcsCustomRequest =
414+
RcsCustomRequest.builder().apply(properties).build()

src/test/kotlin/com/vonage/client/kt/AbstractTest.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,15 @@ abstract class AbstractTest {
101101
protected val fileUrl = "$exampleUrlBase/file.pdf"
102102

103103
private val port = 8081
104+
private val wmBaseUrl = "http://localhost:$port"
104105
private val wiremock: WireMockServer = WireMockServer(
105106
options().port(port).notifier(ConsoleNotifier(false))
106107
)
107108

108109
val vonage = Vonage {
109110
authFromEnv(); httpConfig {
110-
baseUri("http://localhost:$port")
111+
baseUri(wmBaseUrl)
112+
regionalUriGetter { wmBaseUrl }
111113
}
112114
apiKey(apiKey); apiSecret(apiSecret); signatureSecret(null)
113115
applicationId(applicationId); privateKeyPath(privateKeyPath)

0 commit comments

Comments
 (0)