Skip to content

Commit

Permalink
add correction to message list whatsapp
Browse files Browse the repository at this point in the history
  • Loading branch information
BENKACI Amira authored and vsct-jburet committed Jul 10, 2024
1 parent 256a938 commit c6a7cd3
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,23 @@ internal object WebhookActionConverter {
}

is WhatsAppCloudInteractiveMessage -> {

val messageCopy = getMessageInteractiveCopy(message)
messageCopy.interactive.buttonReply?.id?.let { payload ->

val payloadButtonReply = messageCopy.interactive.buttonReply?.id
val payloadListReply = messageCopy.interactive.listReply?.id

val payload = payloadButtonReply ?: payloadListReply
return payload?.let {
SendChoice.decodeChoice(
payload,
it,
PlayerId(senderId),
applicationId,
PlayerId(applicationId, PlayerType.bot),
messageCopy.referral?.ref
)
}

}

else -> null
Expand All @@ -84,27 +91,33 @@ internal object WebhookActionConverter {
message: WhatsAppCloudInteractiveMessage
)
: WhatsAppCloudInteractiveMessage {
val payload = payloadWhatsApp.getPayloadById(message.interactive.buttonReply!!.id)
return if (payload != null) {
val copyButtonReply = message.interactive.buttonReply.copy(
id = payload,
title = message.interactive.buttonReply.title
)
val copyInteractive =
message.interactive.copy(buttonReply = copyButtonReply, listReply = message.interactive.listReply)
message.copy(
interactive = copyInteractive,
id = message.id,
from = message.from,
timestamp = message.timestamp,
context = message.context,
referral = message.referral,
errors = message.errors
)

} else {
message
}
val buttonReply = message.interactive.buttonReply
val listReply = message.interactive.listReply


val payloadButtonReply = buttonReply?.let { payloadWhatsApp.getPayloadById(it.id) }
val payloadListReply = listReply?.let { payloadWhatsApp.getPayloadById(it.id) }


val copyInteractive = message.interactive.copy(
buttonReply = payloadButtonReply?.let {
buttonReply.copy(id = it, title = buttonReply.title)
},
listReply = payloadListReply?.let {
listReply.copy(id = it, title = listReply.title, description = listReply.description)
}
)

return message.copy(
interactive = copyInteractive,
id = message.id,
from = message.from,
timestamp = message.timestamp,
context = message.context,
referral = message.referral,
errors = message.errors
)
}

private fun getMessageButtonCopy(message: WhatsAppCloudButtonMessage): WhatsAppCloudButtonMessage {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import retrofit2.http.Headers
private const val VERSION = "19.0"


class WhatsAppCloudApiClient(val secretKey: String, val token: String, val phoneNumber: String) {
class WhatsAppCloudApiClient(val token: String, val phoneNumber: String) {

interface GraphApi {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ private val cloudApiClientCache = ConcurrentHashMap<String, WhatsAppCloudApiClie

internal fun createCloudApiClient(connectorConfiguration: ConnectorConfiguration): WhatsAppCloudApiClient =
WhatsAppCloudApiClient(
connectorConfiguration.parameters.getValue(SECRET),
connectorConfiguration.parameters.getValue(TOKEN),
connectorConfiguration.parameters.getValue(WHATSAPP_PHONE_NUMBER_ID),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ object PayloadWhatsAppCloudMongoDAO : PayloadWhatsAppCloudDAO {
return if (isUUID(id)) {
collection.findOneById(id)?.payload
} else {
null
id
}
}

Expand Down

0 comments on commit c6a7cd3

Please sign in to comment.