From 0891e056976ab6a5ac35835b017a646e10d23bb5 Mon Sep 17 00:00:00 2001 From: KjellBerlin Date: Fri, 30 Aug 2024 18:19:18 +0200 Subject: [PATCH] Log slack reply --- .../core/slack/SlackWebhookController.kt | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) 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 +)