Skip to content

Slack

Leverages Slack’s native JVM client and Kotlin DSL to make Slack interaction easy.

Also offers channel mapping functionality so you can refer to channels by name instead of ID.

Install kairo-slack-feature. You don’t need to install the Slack client separately — it’s included by default.

build.gradle.kts
dependencies {
implementation("com.highbeam.kairo:kairo-slack-feature")
}

First, add the Feature to your Server.

val features = listOf(
SlackFeature(config.slack),
)

We recommend using kairo-config to configure the Feature.

slack {
token = ${SLACK_TOKEN}
channels {
"general" = "C00SPPX83RS"
}
}

Now send a Slack message!

val slack: SlackClient // Inject this.
slack.chatPostMessage { builder ->
builder.channel(slack.channels.getValue("general"))
builder.blocks {
section {
plainText("Hello, World!")
}
}
}

The channels config maps logical names to Slack channel IDs. Use slack.channels.getValue("name") to look up a channel ID at runtime. This lets you route messages to different channels per environment (for example production versus staging).

SlackClient delegates to Slack’s AsyncMethodsClient, so all Slack API methods are available directly: chatPostMessage, chatUpdate, chatDelete, reactionsAdd, filesUploadV2, and more.