Skip to content

Commit

Permalink
Log slack reply
Browse files Browse the repository at this point in the history
  • Loading branch information
KjellBerlin committed Aug 30, 2024
1 parent 97a4077 commit 0891e05
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/main/kotlin/com/carbonara/core/slack/SlackWebhookController.kt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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<SlackAction>
)

data class SlackAction(
val action_id: String,
val value: String
)

0 comments on commit 0891e05

Please sign in to comment.