OpenParable
Skip to content
← Back to skills

Setup Bot Handlers

Agent Building
setup-bot-handlers

Setup Bot Handlers is an Agent Skill for agent building published in the vendelieu/telegram-bot repository on GitHub: a SKILL.md instruction file an AI agent can load to do this task.

Sets up bot handlers using DSL or annotations. Use when configuring command handlers, input handlers, common handlers, update handlers, or fallback handlers for the telegram-bot library.

View on GitHub ↗
QUICK START

How to use this skill

Bring this guide into your coding agent with a prompt tailored to the tool you use.

  1. Open your project in Codex.
  2. Copy and paste the prompt below.
  3. Review files and risks before approving any action.
Prompt to paste
Inspect the Agent Skill at https://github.com/vendelieu/telegram-bot/blob/HEAD/.cursor/skills/setup-bot-handlers/SKILL.md and all supporting files. Report provenance, permissions, scripts, dependencies, and security risks. Propose an exact installation into .agents/skills/setup-bot-handlers, but wait for my approval before writing files or running scripts.

Copying this prompt does not install or run the skill. Review third-party files before use.

Setup Bot Handlers

Two Approaches

  • DSL: bot.setFunctionality { ... } — define handlers inline
  • Annotations: @CommandHandler, @InputHandler, etc. — KSP generates activities; use with bot.handleUpdates() (loads handlers via META-INF)

DSL Handlers

Inside bot.setFunctionality { }:

HandlerPurpose
onCommand("/start") { }Commands (e.g. /start)
onInput("id") { }Single-step input; route via bot.inputListener[user] = "id"
inputChain("id") { }.andThen { }Multi-step input chain
common("text") { } or common(Regex("...")) { }Text/regex match (lower priority than commands)
onUpdate(UpdateType.X) { }All updates of given type
whenNotHandled { }Fallback for unprocessed updates

Typed Update Handlers

Use typed wrappers for ActivityCtx<XxxUpdate>:

  • onMessage { } — MessageUpdate
  • onCallbackQuery { } — CallbackQueryUpdate
  • onInlineQuery { } — InlineQueryUpdate
  • onEditedMessage { }, onChannelPost { }, onChatMember { }, etc.

Input Listener

Route the next user message to an input handler or chain:

bot.inputListener[user] = "conversation"
// or
bot.inputListener.set(user) { "conversation-2step" }

Annotation Handlers

AnnotationPurpose
@CommandHandler(["/start"])Command handler
@CommandHandler.CallbackQuery(["/data"])Callback query with optional autoAnswer
@InputHandler(["id"])Input handler
@CommonHandler.Text(["value"]) or @CommonHandler.Regex("...")Text/regex match
@UpdateHandler([UpdateType.MESSAGE, ...])Update type handler
@UnprocessedHandlerFallback

Guards

Add pre-processing checks:

  • DSL: guard = UserPresentGuard::class (or DefaultGuard::class)
  • Annotation: @Guard(UserPresentGuard::class) or @Guard(guard = UserPresentGuard::class)

Supported by: CommandHandler, CommandHandler.CallbackQuery, InputHandler.

Rate Limits

  • DSL: rateLimits = RateLimits.NOT_LIMITED or custom
  • Annotation: @RateLimits(period = 60_000, rate = 5) — 5 requests per 60 seconds
  • Default: no limit

Supported by: CommandHandler, CallbackQuery, InputHandler, CommonHandler.

ArgParser

Custom argument parsing for commands and callback data:

  • Annotation: @ArgParser(argParser = CustomArgParser::class)
  • Supported by: CommandHandler, CallbackQuery, CommonHandler
  • Default: DefaultArgParser

Annotation Reference

AnnotationParametersDefault
@CommandHandlervalue (commands), scope (UpdateType[])scope: MESSAGE
@CommandHandler.CallbackQueryvalue (callback data prefixes), autoAnswer (bool)autoAnswer: false
@InputHandlervalue (input identifiers)—
@CommonHandler.Textvalue, filters, priority, scopefilters: [], priority: 0, scope: MESSAGE
@CommonHandler.Regexvalue (pattern), options, filters, priority, scopeoptions: [], filters: [], priority: 0, scope: MESSAGE
@UpdateHandlertype (UpdateType[])—
@UnprocessedHandler——
@Guardguard (KClass)DefaultGuard
@ArgParserargParser (KClass)DefaultArgParser
@RateLimitsperiod (ms), rate (requests)0, 0

Reference