From e5f360c1dd1e82127264f9fd4aabba5074f95259 Mon Sep 17 00:00:00 2001 From: SNCFamiraBenkaci <157110586+SNCFamiraBenkaci@users.noreply.github.com> Date: Tue, 20 Aug 2024 18:58:45 +0200 Subject: [PATCH] send message type image (#1690) * send message type image * send message type image --------- Co-authored-by: BENKACI Amira --- .../src/main/kotlin/WhatsAppCloudBuilder.kt | 16 +++++++ .../send/message/WhatsAppCloudBotMessage.kt | 10 ++--- ...Type.kt => WhatsAppCloudBotMessageType.kt} | 2 +- .../WhatsAppCloudSendBotImageMessage.kt | 17 +++----- .../WhatsAppCloudSendBotInteractiveMessage.kt | 2 +- .../WhatsAppCloudSendBotLocationMessage.kt | 2 +- .../message/WhatsAppCloudSendBotMessage.kt | 5 ++- .../WhatsAppCloudSendBotTemplateMessage.kt | 2 +- .../WhatsAppCloudSendBotTextMessage.kt | 2 +- .../message/content/WhatsAppCloudBotImage.kt | 23 ++++++++++ .../content/WhatsAppCloudBotImageMessage.kt | 43 +++++++++++++++++++ .../WhatsAppCloudBotInteractiveMessage.kt | 2 +- .../WhatsAppCloudBotLocationMessage.kt | 4 +- .../WhatsAppCloudBotTemplateMessage.kt | 4 +- .../content/WhatsAppCloudBotTextMessage.kt | 2 +- .../services/WhatsAppCloudApiService.kt | 34 ++++++++++++++- 16 files changed, 140 insertions(+), 30 deletions(-) rename bot/connector-whatsapp-cloud/src/main/kotlin/model/send/message/{WhatsAppCoudBotMessageType.kt => WhatsAppCloudBotMessageType.kt} (94%) rename bot/connector-whatsapp-cloud/src/main/kotlin/model/send/{media => message}/WhatsAppCloudSendBotImageMessage.kt (54%) create mode 100644 bot/connector-whatsapp-cloud/src/main/kotlin/model/send/message/content/WhatsAppCloudBotImage.kt create mode 100644 bot/connector-whatsapp-cloud/src/main/kotlin/model/send/message/content/WhatsAppCloudBotImageMessage.kt diff --git a/bot/connector-whatsapp-cloud/src/main/kotlin/WhatsAppCloudBuilder.kt b/bot/connector-whatsapp-cloud/src/main/kotlin/WhatsAppCloudBuilder.kt index a6365c73bf..8fed478270 100644 --- a/bot/connector-whatsapp-cloud/src/main/kotlin/WhatsAppCloudBuilder.kt +++ b/bot/connector-whatsapp-cloud/src/main/kotlin/WhatsAppCloudBuilder.kt @@ -92,6 +92,22 @@ fun BotBus.whatsAppCloudText( userId = userId.id, ) +fun BotBus.whatsAppCloudImage( + id: String, + link: String? = null, + caption: CharSequence? = null, + ): WhatsAppCloudBotImageMessage = + WhatsAppCloudBotImageMessage( + messagingProduct = "whatsapp", + image = WhatsAppCloudBotImage( + id = id, + link = link, + caption = translate(caption).toString() + ), + recipientType = WhatsAppCloudBotRecipientType.individual, + userId = userId.id, + ) + fun I18nTranslator.whatsAppCloudReplyButtonMessage( text: CharSequence, vararg replies: QuickReply, diff --git a/bot/connector-whatsapp-cloud/src/main/kotlin/model/send/message/WhatsAppCloudBotMessage.kt b/bot/connector-whatsapp-cloud/src/main/kotlin/model/send/message/WhatsAppCloudBotMessage.kt index 51c72a650f..6ca89f6701 100644 --- a/bot/connector-whatsapp-cloud/src/main/kotlin/model/send/message/WhatsAppCloudBotMessage.kt +++ b/bot/connector-whatsapp-cloud/src/main/kotlin/model/send/message/WhatsAppCloudBotMessage.kt @@ -20,10 +20,7 @@ import ai.tock.bot.connector.ConnectorMessage import ai.tock.bot.connector.ConnectorType import ai.tock.bot.connector.whatsapp.cloud.UserHashedIdCache import ai.tock.bot.connector.whatsapp.cloud.WhatsAppCloudConnectorMessage -import ai.tock.bot.connector.whatsapp.cloud.model.send.message.content.WhatsAppCloudBotInteractiveMessage -import ai.tock.bot.connector.whatsapp.cloud.model.send.message.content.WhatsAppCloudBotLocationMessage -import ai.tock.bot.connector.whatsapp.cloud.model.send.message.content.WhatsAppCloudBotTemplateMessage -import ai.tock.bot.connector.whatsapp.cloud.model.send.message.content.WhatsAppCloudBotTextMessage +import ai.tock.bot.connector.whatsapp.cloud.model.send.message.content.* import ai.tock.bot.connector.whatsapp.cloud.whatsAppCloudConnectorType import com.fasterxml.jackson.annotation.JsonIgnore import com.fasterxml.jackson.annotation.JsonProperty @@ -41,9 +38,10 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo JsonSubTypes.Type(value = WhatsAppCloudBotInteractiveMessage::class, name = "interactive"), JsonSubTypes.Type(value = WhatsAppCloudBotLocationMessage::class, name = "location"), JsonSubTypes.Type(value = WhatsAppCloudBotTemplateMessage::class, name = "template"), -) + JsonSubTypes.Type(value = WhatsAppCloudBotImageMessage::class, name = "image") + ) -abstract class WhatsAppCloudBotMessage ( val type: WhatsAppCoudBotMessageType, @JsonIgnore internal open val userId: String?) : +abstract class WhatsAppCloudBotMessage (val type: WhatsAppCloudBotMessageType, @JsonIgnore internal open val userId: String?) : ConnectorMessage, WhatsAppCloudConnectorMessage() { @get:JsonIgnore diff --git a/bot/connector-whatsapp-cloud/src/main/kotlin/model/send/message/WhatsAppCoudBotMessageType.kt b/bot/connector-whatsapp-cloud/src/main/kotlin/model/send/message/WhatsAppCloudBotMessageType.kt similarity index 94% rename from bot/connector-whatsapp-cloud/src/main/kotlin/model/send/message/WhatsAppCoudBotMessageType.kt rename to bot/connector-whatsapp-cloud/src/main/kotlin/model/send/message/WhatsAppCloudBotMessageType.kt index 6d8cef5e21..eb5f5e64da 100644 --- a/bot/connector-whatsapp-cloud/src/main/kotlin/model/send/message/WhatsAppCoudBotMessageType.kt +++ b/bot/connector-whatsapp-cloud/src/main/kotlin/model/send/message/WhatsAppCloudBotMessageType.kt @@ -16,6 +16,6 @@ package ai.tock.bot.connector.whatsapp.cloud.model.send.message -enum class WhatsAppCoudBotMessageType { +enum class WhatsAppCloudBotMessageType { text, reaction, image, audio , video, location, contacts, interactive, template } \ No newline at end of file diff --git a/bot/connector-whatsapp-cloud/src/main/kotlin/model/send/media/WhatsAppCloudSendBotImageMessage.kt b/bot/connector-whatsapp-cloud/src/main/kotlin/model/send/message/WhatsAppCloudSendBotImageMessage.kt similarity index 54% rename from bot/connector-whatsapp-cloud/src/main/kotlin/model/send/media/WhatsAppCloudSendBotImageMessage.kt rename to bot/connector-whatsapp-cloud/src/main/kotlin/model/send/message/WhatsAppCloudSendBotImageMessage.kt index 3c6c1dff52..390c0c3941 100644 --- a/bot/connector-whatsapp-cloud/src/main/kotlin/model/send/media/WhatsAppCloudSendBotImageMessage.kt +++ b/bot/connector-whatsapp-cloud/src/main/kotlin/model/send/message/WhatsAppCloudSendBotImageMessage.kt @@ -14,16 +14,13 @@ * limitations under the License. */ -package ai.tock.bot.connector.whatsapp.cloud.model.send.media +package ai.tock.bot.connector.whatsapp.cloud.model.send.message -import ai.tock.bot.connector.whatsapp.cloud.model.send.message.WhatsAppCloudBotRecipientType -import ai.tock.bot.connector.whatsapp.cloud.model.send.message.WhatsAppCloudSendBotMessage -import ai.tock.bot.connector.whatsapp.cloud.model.send.message.WhatsAppCoudBotMessageType +import ai.tock.bot.connector.whatsapp.cloud.model.send.message.content.WhatsAppCloudBotImage data class WhatsAppCloudSendBotImageMessage( - override val messagingProduct: String, - override val to: String?, - override val recipientType: WhatsAppCloudBotRecipientType? -) : WhatsAppCloudSendBotMessage(WhatsAppCoudBotMessageType.image) { - -} + override val messagingProduct: String, + val image: WhatsAppCloudBotImage, + override val recipientType: WhatsAppCloudBotRecipientType, + override val to: String, +) : WhatsAppCloudSendBotMessage(WhatsAppCloudBotMessageType.image) diff --git a/bot/connector-whatsapp-cloud/src/main/kotlin/model/send/message/WhatsAppCloudSendBotInteractiveMessage.kt b/bot/connector-whatsapp-cloud/src/main/kotlin/model/send/message/WhatsAppCloudSendBotInteractiveMessage.kt index 8067aa24e8..a81df1e8f6 100644 --- a/bot/connector-whatsapp-cloud/src/main/kotlin/model/send/message/WhatsAppCloudSendBotInteractiveMessage.kt +++ b/bot/connector-whatsapp-cloud/src/main/kotlin/model/send/message/WhatsAppCloudSendBotInteractiveMessage.kt @@ -23,4 +23,4 @@ data class WhatsAppCloudSendBotInteractiveMessage( val interactive: WhatsAppCloudBotInteractive, override val recipientType: WhatsAppCloudBotRecipientType, override val to: String, -) : WhatsAppCloudSendBotMessage(WhatsAppCoudBotMessageType.interactive) +) : WhatsAppCloudSendBotMessage(WhatsAppCloudBotMessageType.interactive) diff --git a/bot/connector-whatsapp-cloud/src/main/kotlin/model/send/message/WhatsAppCloudSendBotLocationMessage.kt b/bot/connector-whatsapp-cloud/src/main/kotlin/model/send/message/WhatsAppCloudSendBotLocationMessage.kt index 75876c7b96..c995cac305 100644 --- a/bot/connector-whatsapp-cloud/src/main/kotlin/model/send/message/WhatsAppCloudSendBotLocationMessage.kt +++ b/bot/connector-whatsapp-cloud/src/main/kotlin/model/send/message/WhatsAppCloudSendBotLocationMessage.kt @@ -23,4 +23,4 @@ data class WhatsAppCloudSendBotLocationMessage( val location: WhatsAppCloudBotLocation, override val recipientType: WhatsAppCloudBotRecipientType, override val to: String, -) : WhatsAppCloudSendBotMessage(WhatsAppCoudBotMessageType.location) +) : WhatsAppCloudSendBotMessage(WhatsAppCloudBotMessageType.location) diff --git a/bot/connector-whatsapp-cloud/src/main/kotlin/model/send/message/WhatsAppCloudSendBotMessage.kt b/bot/connector-whatsapp-cloud/src/main/kotlin/model/send/message/WhatsAppCloudSendBotMessage.kt index 032bbcd8cc..b7d1639bc2 100644 --- a/bot/connector-whatsapp-cloud/src/main/kotlin/model/send/message/WhatsAppCloudSendBotMessage.kt +++ b/bot/connector-whatsapp-cloud/src/main/kotlin/model/send/message/WhatsAppCloudSendBotMessage.kt @@ -30,9 +30,10 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo JsonSubTypes.Type(value = WhatsAppCloudSendBotInteractiveMessage::class, name = "interactive"), JsonSubTypes.Type(value = WhatsAppCloudSendBotLocationMessage::class, name = "location"), JsonSubTypes.Type(value = WhatsAppCloudSendBotTemplateMessage::class, name = "template"), - ) + JsonSubTypes.Type(value = WhatsAppCloudSendBotImageMessage::class, name = "image"), + ) -abstract class WhatsAppCloudSendBotMessage(val type: WhatsAppCoudBotMessageType) { +abstract class WhatsAppCloudSendBotMessage(val type: WhatsAppCloudBotMessageType) { @get:JsonProperty("messaging_product") abstract val messagingProduct:String diff --git a/bot/connector-whatsapp-cloud/src/main/kotlin/model/send/message/WhatsAppCloudSendBotTemplateMessage.kt b/bot/connector-whatsapp-cloud/src/main/kotlin/model/send/message/WhatsAppCloudSendBotTemplateMessage.kt index d62f20c9eb..e92ab1a19e 100644 --- a/bot/connector-whatsapp-cloud/src/main/kotlin/model/send/message/WhatsAppCloudSendBotTemplateMessage.kt +++ b/bot/connector-whatsapp-cloud/src/main/kotlin/model/send/message/WhatsAppCloudSendBotTemplateMessage.kt @@ -23,4 +23,4 @@ data class WhatsAppCloudSendBotTemplateMessage( val template: WhatsAppCloudBotTemplate, override val recipientType: WhatsAppCloudBotRecipientType, override val to: String, -) : WhatsAppCloudSendBotMessage(WhatsAppCoudBotMessageType.template) +) : WhatsAppCloudSendBotMessage(WhatsAppCloudBotMessageType.template) diff --git a/bot/connector-whatsapp-cloud/src/main/kotlin/model/send/message/WhatsAppCloudSendBotTextMessage.kt b/bot/connector-whatsapp-cloud/src/main/kotlin/model/send/message/WhatsAppCloudSendBotTextMessage.kt index a5cf55a2ff..f9259eac9e 100644 --- a/bot/connector-whatsapp-cloud/src/main/kotlin/model/send/message/WhatsAppCloudSendBotTextMessage.kt +++ b/bot/connector-whatsapp-cloud/src/main/kotlin/model/send/message/WhatsAppCloudSendBotTextMessage.kt @@ -26,4 +26,4 @@ data class WhatsAppCloudSendBotTextMessage ( override val to: String, @get:JsonProperty("preview_url") val previewUrl: Boolean = false, -) : WhatsAppCloudSendBotMessage(WhatsAppCoudBotMessageType.text) +) : WhatsAppCloudSendBotMessage(WhatsAppCloudBotMessageType.text) diff --git a/bot/connector-whatsapp-cloud/src/main/kotlin/model/send/message/content/WhatsAppCloudBotImage.kt b/bot/connector-whatsapp-cloud/src/main/kotlin/model/send/message/content/WhatsAppCloudBotImage.kt new file mode 100644 index 0000000000..3f005b10dc --- /dev/null +++ b/bot/connector-whatsapp-cloud/src/main/kotlin/model/send/message/content/WhatsAppCloudBotImage.kt @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2017/2021 e-voyageurs technologies + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ai.tock.bot.connector.whatsapp.cloud.model.send.message.content + +data class WhatsAppCloudBotImage( + var id: String, + val link: String?, + val caption: String? +) diff --git a/bot/connector-whatsapp-cloud/src/main/kotlin/model/send/message/content/WhatsAppCloudBotImageMessage.kt b/bot/connector-whatsapp-cloud/src/main/kotlin/model/send/message/content/WhatsAppCloudBotImageMessage.kt new file mode 100644 index 0000000000..451d4fa420 --- /dev/null +++ b/bot/connector-whatsapp-cloud/src/main/kotlin/model/send/message/content/WhatsAppCloudBotImageMessage.kt @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2017/2021 e-voyageurs technologies + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ai.tock.bot.connector.whatsapp.cloud.model.send.message.content + +import ai.tock.bot.connector.whatsapp.cloud.model.send.message.* +import ai.tock.bot.engine.config.UploadedFilesService.attachmentType +import ai.tock.bot.engine.message.Attachment +import ai.tock.bot.engine.message.GenericMessage + +data class WhatsAppCloudBotImageMessage ( + override val messagingProduct: String, + val image: WhatsAppCloudBotImage, + override val recipientType: WhatsAppCloudBotRecipientType, + override val userId: String? = null, +) : WhatsAppCloudBotMessage(WhatsAppCloudBotMessageType.image, userId) { + override fun toSendBotMessage(recipientId: String): WhatsAppCloudSendBotMessage = + WhatsAppCloudSendBotImageMessage( + messagingProduct, + image, + recipientType, + recipientId + ) + + override fun toGenericMessage(): GenericMessage = + GenericMessage( + texts = mapOf(GenericMessage.TEXT_PARAM to "image"), + attachments = listOf(Attachment(image.id, attachmentType(image.id))) + ) +} \ No newline at end of file diff --git a/bot/connector-whatsapp-cloud/src/main/kotlin/model/send/message/content/WhatsAppCloudBotInteractiveMessage.kt b/bot/connector-whatsapp-cloud/src/main/kotlin/model/send/message/content/WhatsAppCloudBotInteractiveMessage.kt index b1b4bbcc8f..7d5c501dbf 100644 --- a/bot/connector-whatsapp-cloud/src/main/kotlin/model/send/message/content/WhatsAppCloudBotInteractiveMessage.kt +++ b/bot/connector-whatsapp-cloud/src/main/kotlin/model/send/message/content/WhatsAppCloudBotInteractiveMessage.kt @@ -25,7 +25,7 @@ data class WhatsAppCloudBotInteractiveMessage ( val interactive: WhatsAppCloudBotInteractive, override val recipientType: WhatsAppCloudBotRecipientType, override val userId: String? = null, -): WhatsAppCloudBotMessage(WhatsAppCoudBotMessageType.interactive, userId) { +): WhatsAppCloudBotMessage(WhatsAppCloudBotMessageType.interactive, userId) { override fun toGenericMessage(): GenericMessage? { val texts = mapOf(GenericMessage.TEXT_PARAM to (interactive.body?.text ?: "")) return GenericMessage( diff --git a/bot/connector-whatsapp-cloud/src/main/kotlin/model/send/message/content/WhatsAppCloudBotLocationMessage.kt b/bot/connector-whatsapp-cloud/src/main/kotlin/model/send/message/content/WhatsAppCloudBotLocationMessage.kt index 87c3e7c116..aaa51c0623 100644 --- a/bot/connector-whatsapp-cloud/src/main/kotlin/model/send/message/content/WhatsAppCloudBotLocationMessage.kt +++ b/bot/connector-whatsapp-cloud/src/main/kotlin/model/send/message/content/WhatsAppCloudBotLocationMessage.kt @@ -20,7 +20,7 @@ import ai.tock.bot.connector.whatsapp.cloud.model.send.message.WhatsAppCloudBotM import ai.tock.bot.connector.whatsapp.cloud.model.send.message.WhatsAppCloudBotRecipientType import ai.tock.bot.connector.whatsapp.cloud.model.send.message.WhatsAppCloudSendBotLocationMessage import ai.tock.bot.connector.whatsapp.cloud.model.send.message.WhatsAppCloudSendBotMessage -import ai.tock.bot.connector.whatsapp.cloud.model.send.message.WhatsAppCoudBotMessageType +import ai.tock.bot.connector.whatsapp.cloud.model.send.message.WhatsAppCloudBotMessageType import ai.tock.bot.engine.message.GenericMessage data class WhatsAppCloudBotLocationMessage( @@ -28,7 +28,7 @@ data class WhatsAppCloudBotLocationMessage( val location: WhatsAppCloudBotLocation, override val recipientType: WhatsAppCloudBotRecipientType, override val userId: String? = null, -) : WhatsAppCloudBotMessage(WhatsAppCoudBotMessageType.location, userId) { +) : WhatsAppCloudBotMessage(WhatsAppCloudBotMessageType.location, userId) { override fun toSendBotMessage(recipientId: String): WhatsAppCloudSendBotMessage = WhatsAppCloudSendBotLocationMessage( messagingProduct, diff --git a/bot/connector-whatsapp-cloud/src/main/kotlin/model/send/message/content/WhatsAppCloudBotTemplateMessage.kt b/bot/connector-whatsapp-cloud/src/main/kotlin/model/send/message/content/WhatsAppCloudBotTemplateMessage.kt index 2edbef16d0..306999bc15 100644 --- a/bot/connector-whatsapp-cloud/src/main/kotlin/model/send/message/content/WhatsAppCloudBotTemplateMessage.kt +++ b/bot/connector-whatsapp-cloud/src/main/kotlin/model/send/message/content/WhatsAppCloudBotTemplateMessage.kt @@ -20,7 +20,7 @@ import ai.tock.bot.connector.whatsapp.cloud.model.send.message.WhatsAppCloudBotM import ai.tock.bot.connector.whatsapp.cloud.model.send.message.WhatsAppCloudBotRecipientType import ai.tock.bot.connector.whatsapp.cloud.model.send.message.WhatsAppCloudSendBotMessage import ai.tock.bot.connector.whatsapp.cloud.model.send.message.WhatsAppCloudSendBotTemplateMessage -import ai.tock.bot.connector.whatsapp.cloud.model.send.message.WhatsAppCoudBotMessageType +import ai.tock.bot.connector.whatsapp.cloud.model.send.message.WhatsAppCloudBotMessageType import ai.tock.bot.engine.message.GenericMessage data class WhatsAppCloudBotTemplateMessage( @@ -28,7 +28,7 @@ data class WhatsAppCloudBotTemplateMessage( val template: WhatsAppCloudBotTemplate, override val recipientType: WhatsAppCloudBotRecipientType, override val userId: String? = null, -) : WhatsAppCloudBotMessage(WhatsAppCoudBotMessageType.template, userId) { +) : WhatsAppCloudBotMessage(WhatsAppCloudBotMessageType.template, userId) { override fun toSendBotMessage(recipientId: String): WhatsAppCloudSendBotMessage = WhatsAppCloudSendBotTemplateMessage( messagingProduct, diff --git a/bot/connector-whatsapp-cloud/src/main/kotlin/model/send/message/content/WhatsAppCloudBotTextMessage.kt b/bot/connector-whatsapp-cloud/src/main/kotlin/model/send/message/content/WhatsAppCloudBotTextMessage.kt index 0f9e678249..a9a9b0197c 100644 --- a/bot/connector-whatsapp-cloud/src/main/kotlin/model/send/message/content/WhatsAppCloudBotTextMessage.kt +++ b/bot/connector-whatsapp-cloud/src/main/kotlin/model/send/message/content/WhatsAppCloudBotTextMessage.kt @@ -26,7 +26,7 @@ data class WhatsAppCloudBotTextMessage ( val text: TextContent, override val recipientType: WhatsAppCloudBotRecipientType, override val userId: String? = null, -) : WhatsAppCloudBotMessage(WhatsAppCoudBotMessageType.text, userId) { +) : WhatsAppCloudBotMessage(WhatsAppCloudBotMessageType.text, userId) { override fun toSendBotMessage(recipientId: String): WhatsAppCloudSendBotMessage = WhatsAppCloudSendBotTextMessage( messagingProduct, diff --git a/bot/connector-whatsapp-cloud/src/main/kotlin/services/WhatsAppCloudApiService.kt b/bot/connector-whatsapp-cloud/src/main/kotlin/services/WhatsAppCloudApiService.kt index e973755434..6e5e078650 100644 --- a/bot/connector-whatsapp-cloud/src/main/kotlin/services/WhatsAppCloudApiService.kt +++ b/bot/connector-whatsapp-cloud/src/main/kotlin/services/WhatsAppCloudApiService.kt @@ -26,10 +26,11 @@ import ai.tock.bot.connector.whatsapp.cloud.model.send.manageTemplate.ResponseCr import ai.tock.bot.connector.whatsapp.cloud.model.send.manageTemplate.WhatsAppCloudTemplate import ai.tock.bot.connector.whatsapp.cloud.model.send.media.FileType import ai.tock.bot.connector.whatsapp.cloud.model.send.media.MediaResponse +import ai.tock.bot.connector.whatsapp.cloud.model.send.message.WhatsAppCloudSendBotTemplateMessage import ai.tock.bot.connector.whatsapp.cloud.model.send.message.WhatsAppCloudSendBotInteractiveMessage +import ai.tock.bot.connector.whatsapp.cloud.model.send.message.WhatsAppCloudSendBotImageMessage import ai.tock.bot.connector.whatsapp.cloud.model.send.message.WhatsAppCloudSendBotLocationMessage import ai.tock.bot.connector.whatsapp.cloud.model.send.message.WhatsAppCloudSendBotMessage -import ai.tock.bot.connector.whatsapp.cloud.model.send.message.WhatsAppCloudSendBotTemplateMessage import ai.tock.bot.connector.whatsapp.cloud.model.send.message.WhatsAppCloudSendBotTextMessage import ai.tock.bot.connector.whatsapp.cloud.model.send.message.content.Component import ai.tock.bot.connector.whatsapp.cloud.model.send.message.content.HeaderParameter @@ -68,8 +69,11 @@ class WhatsAppCloudApiService(private val apiClient: WhatsAppCloudApiClient) { try { when (messageRequest) { is WhatsAppCloudSendBotTextMessage, + is WhatsAppCloudSendBotLocationMessage -> handleSimpleMessage(phoneNumberId, token, messageRequest) + is WhatsAppCloudSendBotImageMessage -> handleImageMessage(phoneNumberId, token, messageRequest) + is WhatsAppCloudSendBotInteractiveMessage -> handleInteractiveMessage( phoneNumberId, token, @@ -83,6 +87,13 @@ class WhatsAppCloudApiService(private val apiClient: WhatsAppCloudApiClient) { } } + private fun handleImageMessage(phoneNumberId: String, token: String, messageRequest: WhatsAppCloudSendBotImageMessage) { + replaceWithRealMessageImageId(messageRequest, phoneNumberId, token) + send(messageRequest) { + apiClient.graphApi.sendMessage(phoneNumberId, token, messageRequest).execute() + } + } + private fun handleSimpleMessage(phoneNumberId: String, token: String, messageRequest: WhatsAppCloudSendBotMessage) { send(messageRequest) { apiClient.graphApi.sendMessage(phoneNumberId, token, messageRequest).execute() @@ -302,6 +313,27 @@ class WhatsAppCloudApiService(private val apiClient: WhatsAppCloudApiClient) { } } + private fun replaceWithRealMessageImageId( + messageRequest: WhatsAppCloudSendBotImageMessage, + phoneNumberId: String, + token: String + ) { + val client = OkHttpClient.Builder().apply(TockProxyAuthenticator::install).build() + + var res = sendMedia( + client, + phoneNumberId, + token, + messageRequest.image.id, + FileType.PNG.type + ) + + val image = messageRequest.image + val newImageId = res.id + image.id = newImageId + } + + private fun replaceWithRealImageId( messageRequest: WhatsAppCloudSendBotTemplateMessage, phoneNumberId: String,