-
Notifications
You must be signed in to change notification settings - Fork 229
Expand file tree
/
Copy pathAppHome.kt
More file actions
38 lines (34 loc) · 1.33 KB
/
AppHome.kt
File metadata and controls
38 lines (34 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package examples.docs
// static imports
import com.slack.api.bolt.App
import com.slack.api.bolt.AppConfig
import com.slack.api.model.block.Blocks.*
import com.slack.api.model.block.composition.BlockCompositions.*
import com.slack.api.model.view.Views.*
import com.slack.api.model.event.AppHomeOpenedEvent
import java.time.ZonedDateTime
fun main() {
val app = App(AppConfig.builder()
.signingSecret("foo")
.singleTeamBotToken("xoxb-xxx")
.build())
// https://docs.slack.dev/reference/events/app_home_opened
app.event(AppHomeOpenedEvent::class.java) { event, ctx ->
// Build a Home tab view
val now = ZonedDateTime.now()
val appHomeView = view {
it.type("home")
.blocks(asBlocks(
section { section -> section.text(markdownText { mt -> mt.text(":wave: Hello, App Home! (Last updated: ${now})") }) },
image { img -> img.imageUrl("https://www.example.com/foo.png") }
))
}
// Update the App Home for the given user
val res = ctx.client().viewsPublish {
it.userId(event.event.user)
.hash(event.event.view?.hash) // To protect against possible race conditions
.view(appHomeView)
}
ctx.ack()
}
}