|
15 | 15 | */
|
16 | 16 | package com.vonage.client.kt
|
17 | 17 |
|
| 18 | +import com.vonage.client.ApiRegion |
18 | 19 | import com.vonage.client.messages.*
|
19 | 20 | import com.vonage.client.messages.sms.*
|
20 | 21 | import com.vonage.client.messages.mms.*
|
21 | 22 | import com.vonage.client.messages.whatsapp.*
|
22 | 23 | import com.vonage.client.messages.messenger.*
|
23 | 24 | import com.vonage.client.messages.viber.*
|
| 25 | +import com.vonage.client.messages.rcs.* |
24 | 26 | import java.util.UUID
|
25 | 27 |
|
26 | 28 | /**
|
@@ -54,6 +56,51 @@ class Messages internal constructor(private val client: MessagesClient) {
|
54 | 56 | fun send(message: MessageRequest, sandbox: Boolean = false): UUID =
|
55 | 57 | (if (sandbox) client.useSandboxEndpoint()
|
56 | 58 | 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 | + } |
57 | 104 | }
|
58 | 105 |
|
59 | 106 | /**
|
@@ -166,6 +213,16 @@ fun whatsappFile(properties: WhatsappFileRequest.Builder.() -> Unit): WhatsappFi
|
166 | 213 | fun whatsappSticker(properties: WhatsappStickerRequest.Builder.() -> Unit): WhatsappStickerRequest =
|
167 | 214 | WhatsappStickerRequest.builder().apply(properties).build()
|
168 | 215 |
|
| 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 | + |
169 | 226 | /**
|
170 | 227 | * Creates a WhatsApp location message.
|
171 | 228 | *
|
@@ -305,3 +362,53 @@ fun viberVideo(properties: ViberVideoRequest.Builder.() -> Unit): ViberVideoRequ
|
305 | 362 | */
|
306 | 363 | fun viberFile(properties: ViberFileRequest.Builder.() -> Unit): ViberFileRequest =
|
307 | 364 | 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() |
0 commit comments