TelegramBotAPI examples

August 21, 2026 · View on GitHub

Runnable examples for TelegramBotAPI. Each module focuses on a small Telegram Bot API feature and has its own README with detailed behavior, setup, permissions, and optional arguments.

Running an example

Run commands from the repository root and replace placeholders such as <BOT_TOKEN> and <ADMIN_USER_ID>. The table uses JVM launchers for multiplatform modules; their module READMEs also document browser and native targets where available.

The shortcuts include all mode tokens supported by each launcher. Remove debug to disable verbose logging and remove testServer to use Telegram's production Bot API. These are positional values inside --args and intentionally have no leading dashes: the current launchers recognize debug, not --debug, and testServer, not --testServer.

Native targets on Linux require libcurl development files, for example:

sudo apt install libcurl4-gnutls-dev

Modules

ModuleWhat it demonstratesLaunch shortcut
BoostsInfoBotRequests a channel, lists the requesting user's boosts, and logs boost updates../gradlew :BoostsInfoBot:run --args="<BOT_TOKEN> debug"
BotSubscriptionsBotObserves recurring Telegram Stars subscription state updates../gradlew :BotSubscriptionsBot:run --args="<BOT_TOKEN> debug testServer"
BusinessConnectionsBotManages a connected Business account, messages, Stars, gifts, stories, and checklists../gradlew :BusinessConnectionsBot:run --args="<BOT_TOKEN> debug"
ChatAvatarSetterSets a chat photo from an image sent to the bot../gradlew :ChatAvatarSetter:run --args="<BOT_TOKEN>"
ChatManagementBotExercises member permissions, administrator queries, reaction deletion, and bot-to-bot messages../gradlew :ChatManagementBot:run --args="<BOT_TOKEN> debug testServer"
ChecklistsBotReceives and renders checklist messages and checklist service events../gradlew :ChecklistsBot:run --args="<BOT_TOKEN> debug testServer"
CommunitiesBotHandles community join/leave events and inspects a chat's current community../gradlew :CommunitiesBot:run --args="<BOT_TOKEN> debug testServer"
CustomBotProvides a diagnostics playground for contexts, request logging, profile audio, and Stars balance../gradlew :CustomBot:run --args="<BOT_TOKEN> debug testServer"
DeepLinksBotGenerates bot deep links and consumes their start payloads../gradlew :DeepLinksBot:run --args="<BOT_TOKEN>"
DraftsBotStreams message drafts before sending the completed message../gradlew :DraftsBot:run --args="<BOT_TOKEN>"
EphemeralMessagesBotSends ephemeral messages revealed through an inline button../gradlew :EphemeralMessagesBot:run --args="<BOT_TOKEN> debug testServer"
FSMBotImplements a conversational finite-state machine with chat-scoped in-memory state../gradlew :FSMBot:run --args="<BOT_TOKEN>"
FilesLoaderBotDownloads incoming media to disk and sends it back to the chat../gradlew :FilesLoaderBot:run --args="<BOT_TOKEN> <OUTPUT_DIRECTORY>"
ForwardInfoSenderBotReports the forward-origin metadata of received content../gradlew :ForwardInfoSenderBot:run --args="<BOT_TOKEN>"
GiftsBotPaginates and lists gifts owned by a user or chat../gradlew :GiftsBot:run --args="<BOT_TOKEN> debug testServer"
GiveawaysBotLogs giveaway creation, completion, and winner events../gradlew :GiveawaysBot:run --args="<BOT_TOKEN> debug testServer"
GuestQueryBotHandles guest queries in chats where the bot is not a member../gradlew :GuestQueryBot:run --args="<BOT_TOKEN> debug testServer"
HelloBotGreets users, groups, channels, or business chats when mentioned../gradlew :HelloBot:run --args="<BOT_TOKEN>"
InlineQueriesBotAnswers inline queries and supplies a deep-link result../gradlew :InlineQueriesBot:runJvm --args="<BOT_TOKEN>"
JoinRequestQueriesBotQueues or approves join requests, optionally delegating the decision to a Web App../gradlew :JoinRequestQueriesBot:run --args="<BOT_TOKEN> https://example.com/verify debug testServer"
KeyboardsBotDemonstrates reply, inline, callback, paged, copy-text, and inline-mode keyboards../gradlew :KeyboardsBot:jvm_launcher:run --args="<BOT_TOKEN> debug"
LinkPreviewsBotSends the same link using multiple link-preview configurations../gradlew :LinkPreviewsBot:run --args="<BOT_TOKEN> debug"
LiveLocationsBotSends, updates, cancels, and stops a live-location message../gradlew :LiveLocationsBot:run --args="<BOT_TOKEN>"
LivePhotosBotReceives, sends, groups, edits, and sells Telegram Live Photos../gradlew :LivePhotosBot:run --args="<BOT_TOKEN> debug testServer"
ManagedBotsBotCreates and administers managed bots and inspects personal-channel messages../gradlew :ManagedBotsBot:run --args="<BOT_TOKEN> debug testServer"
MemberUpdatedWatcherBotLogs and reports bot/member status transitions in chats../gradlew :MemberUpdatedWatcherBot:run --args="<BOT_TOKEN> debug"
MyBotReplaces or removes the bot's global profile photo and prints diagnostics../gradlew :MyBot:run --args="<BOT_TOKEN> debug testServer"
PollsBotSends regular polls, quizzes, poll media, and handles poll updates../gradlew :PollsBot:run --args="<BOT_TOKEN> debug"
RandomFileSenderBotPicks random local files and sends them individually or as media groups../gradlew :RandomFileSenderBot:runJvm --args="<BOT_TOKEN> <FILES_DIRECTORY>"
ReactionsInfoBotHandles per-user reaction changes and anonymous reaction-count updates../gradlew :ReactionsInfoBot:run --args="<BOT_TOKEN> debug"
ResenderBotRecreates received content while preserving reply, quote, effect, and business context../gradlew :ResenderBot:jvm_launcher:run --args="<BOT_TOKEN> debug"
RichMessagesBotDemonstrates rich HTML/Markdown/blocks, streaming drafts, inline results, and media../gradlew :RichMessagesBot:run --args="<BOT_TOKEN> debug testServer"
RightsChangerBotUses an FSM and inline keyboards to change member and administrator rights../gradlew :RightsChangerBot:run --args="<BOT_TOKEN> <ALLOWED_USER_ID> debug"
SlotMachineDetectorBotDetects slot-machine dice and decodes their reel values../gradlew :SlotMachineDetectorBot:run --args="<BOT_TOKEN>"
StarTransactionsBotDemonstrates Stars invoices, transaction history, paid media, and refunds../gradlew :StarTransactionsBot:run --args="<BOT_TOKEN> <ADMIN_USER_ID> debug testServer"
StickerInfoBotLooks up sticker-set metadata for stickers and custom emoji../gradlew :StickerInfoBot:jvm_launcher:run --args="<BOT_TOKEN>"
StickerSetHandlerCreates and manages a sticker set owned by each private-chat user../gradlew :StickerSetHandler:run --args="<BOT_TOKEN>"
SuggestedPostsHandles channel direct messages and the suggested-post lifecycle../gradlew :SuggestedPosts:run --args="<BOT_TOKEN> debug testServer"
TagsBotSets chat-member tags, delegates tag management, and reads sender tags../gradlew :TagsBot:run --args="<BOT_TOKEN> debug testServer"
TopicsHandlingExercises forum-topic and private-chat-topic actions and events../gradlew :TopicsHandling:run --args="<BOT_TOKEN>"
UserChatSharedRequests users or chats through reply keyboards and handles the shared results../gradlew :UserChatShared:run --args="<BOT_TOKEN> debug"
WebAppServes a Compose Web client and demonstrates Telegram Web App integration../gradlew :WebApp:runJvm --args="<BOT_TOKEN> https://webapp.example 8080 debug testServer"
WebHooksReceives Telegram updates through a Ktor webhook server instead of long polling../gradlew :WebHooks:run --args="<BOT_TOKEN> https://bot.example.com debug"

† These modules currently contain a stale Gradle mainClassName mapping, documented in their module README. The shown command is the intended launch command but will not start until that mapping is corrected.

Repository as a reference

The example structure can be used as a starting point, and the commit history is useful for seeing migrations between TelegramBotAPI versions. For new projects, consider the Telegram Bot template or Kotlin Multiplatform Project template.