diff --git a/src/main/kotlin/com/carbonara/core/slack/SlackWebhookController.kt b/src/main/kotlin/com/carbonara/core/slack/SlackWebhookController.kt index 743d3e5..73103ab 100644 --- a/src/main/kotlin/com/carbonara/core/slack/SlackWebhookController.kt +++ b/src/main/kotlin/com/carbonara/core/slack/SlackWebhookController.kt @@ -1,6 +1,7 @@ package com.carbonara.core.slack import com.carbonara.core.order.OrderService +import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper import mu.KotlinLogging import org.springframework.web.bind.annotation.PostMapping import org.springframework.web.bind.annotation.RestController @@ -10,22 +11,33 @@ class SlackDeliveryWebhookController( private val orderService: OrderService ) { - // Potential dos attack endpoint, introduce rate limiting - - // TODO: Handle webhook - @PostMapping("/slack-delivery-status", consumes = ["application/x-www-form-urlencoded"]) suspend fun handleSlackWebhook(requestBody: SlackWebhookRequestBody) { log.info("--Start Slack--") - log.info(requestBody.payload) + + val slackPayload = objectMapper.readValue(requestBody.payload, SlackPayload::class.java) + slackPayload.actions.forEach { action -> + log.info("Action: ${action.action_id}, Value: ${action.value}") + } + log.info("--End Slack--") } companion object { private val log = KotlinLogging.logger {} + private val objectMapper = jacksonObjectMapper() } } data class SlackWebhookRequestBody( val payload: String ) + +data class SlackPayload( + val actions: List +) + +data class SlackAction( + val action_id: String, + val value: String +)