Create Input Chain
Quick Start
Define a chain inside bot.setFunctionality { }. Set bot.inputListener[user] = "id" to start. The chain advances automatically after each step.
bot.setFunctionality {
onCommand("/start") {
message { "What's your name?" }.send(user, bot)
bot.inputListener[user] = "conversation"
}
inputChain("conversation") {
message { "Nice to meet you, ${message.text}!" }.send(update.getUser(), bot)
message { "What's your favorite food?" }.send(update.getUser(), bot)
}.breakIf({ message.text == "peanut butter" }) {
message { "Oh, too bad, I'm allergic." }.send(update.getUser(), bot)
}.andThen {
message { "Thanks! You said: ${message.text}" }.send(update.getUser(), bot)
}
}
bot.handleUpdates()
Structure
- inputChain("id") { } — First step. Block runs when user sends a message while
inputListener is "id".
- andThen { } — Next step. Chain advances to this step after the previous block runs.
- breakIf(condition, repeat = true, block) — On current step: if condition is true, run block. If
repeat = true, stay on current step (user can re-enter). If repeat = false, do not re-register.
Context
Inside each block, ProcessingContext / ActivityCtx provides:
update — the ProcessedUpdate
message — shortcut for message content (when applicable)
update.getUser() — user reference
When to Use
- Input chain: Simple linear flows, no typed state, quick setup
- Wizard: Complex validation, typed state,
Transition.JumpTo/Retry, state managers
Reference
- InputChainBuilder.kt
- README.md — inputChain example
Converted and distributed by TomeVault — claim your Tome and manage your conversions.
1---2name: vendelieu-telegram-bot-create-input-chain3description: Create Input Chain4---56# Create Input Chain78## Quick Start910Define a chain inside `bot.setFunctionality { }`. Set `bot.inputListener[user] = "id"` to start. The chain advances automatically after each step.1112```kotlin13bot.setFunctionality {14 onCommand("/start") {15 message { "What's your name?" }.send(user, bot)16 bot.inputListener[user] = "conversation"17 }18 inputChain("conversation") {19 message { "Nice to meet you, ${message.text}!" }.send(update.getUser(), bot)20 message { "What's your favorite food?" }.send(update.getUser(), bot)21 }.breakIf({ message.text == "peanut butter" }) {22 message { "Oh, too bad, I'm allergic." }.send(update.getUser(), bot)23 }.andThen {24 message { "Thanks! You said: ${message.text}" }.send(update.getUser(), bot)25 }26}27bot.handleUpdates()28```2930## Structure3132- **inputChain("id") { }** — First step. Block runs when user sends a message while `inputListener` is `"id"`.33- **andThen { }** — Next step. Chain advances to this step after the previous block runs.34- **breakIf(condition, repeat = true, block)** — On current step: if condition is true, run block. If `repeat = true`, stay on current step (user can re-enter). If `repeat = false`, do not re-register.3536## Context3738Inside each block, `ProcessingContext` / `ActivityCtx` provides:3940- `update` — the ProcessedUpdate41- `message` — shortcut for message content (when applicable)42- `update.getUser()` — user reference4344## When to Use4546- **Input chain**: Simple linear flows, no typed state, quick setup47- **Wizard**: Complex validation, typed state, `Transition.JumpTo`/`Retry`, state managers4849## Reference5051- [InputChainBuilder.kt](telegram-bot/src/commonMain/kotlin/eu/vendeli/tgbot/core/InputChainBuilder.kt)52- [README.md](README.md) — inputChain example5354---55> Converted and distributed by [TomeVault](https://tomevault.io/claim/vendelieu) — claim your Tome and manage your conversions.56<!-- tomevault:4.0:skill_md:2026-04-11 -->