-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #68 from KjellBerlin/Introduce-slack-message-sending
Introduce Slack message sending
- Loading branch information
Showing
10 changed files
with
138 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package com.carbonara.core.slack | ||
|
||
class SlackException(message: String) : RuntimeException(message) |
76 changes: 76 additions & 0 deletions
76
src/main/kotlin/com/carbonara/core/slack/SlackMessageService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package com.carbonara.core.slack | ||
|
||
import com.slack.api.Slack | ||
import com.slack.api.methods.kotlin_extension.request.chat.blocks | ||
import mu.KotlinLogging | ||
import org.springframework.beans.factory.annotation.Value | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class SlackMessageService { | ||
|
||
@Value("\${slack.token}") | ||
lateinit var slackToken: String | ||
|
||
@Value("\${slack.channel}") | ||
lateinit var slackChannel: String | ||
|
||
fun sendNewOrderMessage( | ||
customerName: String, | ||
orderId: String, | ||
address: String, | ||
googleMapsLink: String, | ||
productNames: List<String> | ||
) { | ||
val slack = Slack.getInstance() | ||
val response = slack.methods(slackToken).chatPostMessage { req -> req | ||
.channel(slackChannel) | ||
.blocks { | ||
section { | ||
fields { | ||
markdownText("*Customer Name:*\n$customerName") | ||
markdownText("*OrderId:*\n$orderId") | ||
} | ||
} | ||
section { | ||
fields { | ||
markdownText("*Address:*\n$address\n$googleMapsLink") | ||
markdownText("*Products:*\n${productNames.joinToString(", ")}") | ||
} | ||
} | ||
actions { | ||
button { | ||
text("ACCEPT", emoji = true) | ||
style("primary") | ||
value("processing_order") | ||
} | ||
button { | ||
text("DELIVERY_IN_PROGRESS", emoji = true) | ||
style("primary") | ||
value("delivery_in_progress") | ||
} | ||
button { | ||
text("DELIVERED", emoji = true) | ||
style("primary") | ||
value("delivered") | ||
} | ||
button { | ||
text("CANCELLED", emoji = true) | ||
style("danger") | ||
value("cancelled") | ||
} | ||
} | ||
divider() | ||
} | ||
} | ||
|
||
if (!response.isOk) { | ||
log.error("Slack API error: ${response.error}") | ||
throw SlackException("Failed to send slack message for orderId: $orderId. Error: ${response.error}") | ||
} | ||
} | ||
|
||
companion object { | ||
private val log = KotlinLogging.logger {} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters