TelegramBotAPI examples
Runnable examples for TelegramBotAPI 38.0.0, covering Telegram Bot API 10.4 and 10.5. This branch uses dev.inmo:tgbotapi:38.0.0-t1 from Maven Local. Each module has a README with its behavior, setup, permissions, and launch arguments.
Running an example
If 38.0.0-t1 is missing from Maven Local, run ./gradlew -Plibrary_version=38.0.0-t1 publishToMavenLocal
in the TelegramBotAPI 38.0.0 checkout.
When updating an existing examples checkout, run ./gradlew kotlinUpgradeYarnLock if Kotlin/JS reports
that the local yarn.lock has changed.
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 show debug and testServer where supported. Pass them as bare words inside --args. Omit debug for normal logging and testServer to use Telegram's production Bot API.
InlineQueriesBot accepts configureInline to enable inline mode. EphemeralMessagesBot accepts inlineCallbacks or defaultCallbacks to select how Telegram delivers button presses. Telegram saves these settings across runs. Inline query setup · Ephemeral callback modes
Native targets on Linux require libcurl development files, for example:
sudo apt install libcurl4-gnutls-dev
Modules
| Module | What it demonstrates | Launch shortcut |
|---|---|---|
| BoostsInfoBot | Requests a channel, lists the requesting user's boosts, and logs boost updates. | ./gradlew :BoostsInfoBot:run --args="<BOT_TOKEN> debug" |
| BotSubscriptionsBot | Observes recurring Telegram Stars subscription state updates. | ./gradlew :BotSubscriptionsBot:run --args="<BOT_TOKEN> debug testServer" |
| BusinessConnectionsBot | Manages a connected business account, including deletion of regular gifts by owned ID. | ./gradlew :BusinessConnectionsBot:run --args="<BOT_TOKEN> debug" |
| ChatAvatarSetter | Sets a chat photo from an image sent to the bot. | ./gradlew :ChatAvatarSetter:run --args="<BOT_TOKEN>" |
| ChatManagementBot | Exercises member permissions, administrator queries, reaction deletion, and bot-to-bot messages. | ./gradlew :ChatManagementBot:run --args="<BOT_TOKEN> debug testServer" |
| ChecklistsBot | Receives and renders checklist messages and checklist service events. | ./gradlew :ChecklistsBot:run --args="<BOT_TOKEN> debug testServer" |
| CommunitiesBot | Handles chat/community membership and user-from-community join events. | ./gradlew :CommunitiesBot:run --args="<BOT_TOKEN> debug testServer" |
| CustomBot | Provides a diagnostics playground for contexts, request logging, profile audio, and Stars balance. | ./gradlew :CustomBot:run --args="<BOT_TOKEN> debug testServer" |
| DeepLinksBot | Generates deep links and owner invitations, handles start payloads, and inspects chat share themes. | ./gradlew :DeepLinksBot:run --args="<BOT_TOKEN>" |
| DraftsBot | Streams empty or stoppable message drafts and handles generation-stopped updates. | ./gradlew :DraftsBot:run --args="<BOT_TOKEN>" |
| EphemeralMessagesBot | Sends ephemeral replies to callbacks and edits photos and Live Photos for a single recipient. | ./gradlew :EphemeralMessagesBot:run --args="<BOT_TOKEN> debug testServer" |
| FSMBot | Implements a conversational finite-state machine with chat-scoped in-memory state. | ./gradlew :FSMBot:run --args="<BOT_TOKEN>" |
| FilesLoaderBot | Downloads incoming media to disk and sends it back to the chat. | ./gradlew :FilesLoaderBot:run --args="<BOT_TOKEN> <OUTPUT_DIRECTORY>" |
| ForwardInfoSenderBot | Reports the forward-origin metadata of received content. | ./gradlew :ForwardInfoSenderBot:run --args="<BOT_TOKEN>" |
| GiftsBot | Lists owned gifts, looks up unique gifts by name, and displays gift events. | ./gradlew :GiftsBot:run --args="<BOT_TOKEN> debug testServer" |
| GiveawaysBot | Logs giveaway creation, completion, and winner events. | ./gradlew :GiveawaysBot:run --args="<BOT_TOKEN> debug testServer" |
| GuestQueryBot | Handles guest queries in chats where the bot is not a member. | ./gradlew :GuestQueryBot:run --args="<BOT_TOKEN> debug testServer" |
| HelloBot | Greets users, groups, channels, or business chats when mentioned. | ./gradlew :HelloBot:run --args="<BOT_TOKEN>" |
| InlineQueriesBot | Configures inline mode, answers paginated queries, and supplies a deep-link result. | ./gradlew :InlineQueriesBot:runJvm --args="<BOT_TOKEN>" |
| JoinRequestQueriesBot | Queues or approves join requests, optionally delegating the decision to a Web App. | ./gradlew :JoinRequestQueriesBot:run --args="<BOT_TOKEN> https://example.com/verify debug testServer" |
| KeyboardsBot | Demonstrates reply, inline, disabled, forced-reply, paged, and inline-mode keyboards. | ./gradlew :KeyboardsBot:jvm_launcher:run --args="<BOT_TOKEN> debug" |
| LinkPreviewsBot | Sends the same link using multiple link-preview configurations. | ./gradlew :LinkPreviewsBot:run --args="<BOT_TOKEN> debug" |
| LiveLocationsBot | Sends, updates, cancels, and stops a live-location message. | ./gradlew :LiveLocationsBot:run --args="<BOT_TOKEN>" |
| LivePhotosBot | Receives, uploads, groups, edits, and sells Telegram Live Photos. | ./gradlew :LivePhotosBot:run --args="<BOT_TOKEN> debug testServer" |
| ManagedBotsBot | Creates and administers managed bots and inspects personal-channel messages. | ./gradlew :ManagedBotsBot:run --args="<BOT_TOKEN> debug testServer" |
| MemberUpdatedWatcherBot | Logs and reports bot/member status transitions in chats. | ./gradlew :MemberUpdatedWatcherBot:run --args="<BOT_TOKEN> debug" |
| MyBot | Replaces or removes the bot's global profile photo and prints diagnostics. | ./gradlew :MyBot:run --args="<BOT_TOKEN> debug testServer" |
| PollsBot | Sends regular polls, quizzes, poll media, and handles poll updates. | ./gradlew :PollsBot:run --args="<BOT_TOKEN> debug" |
| RandomFileSenderBot | Picks random local files and sends them individually or as media groups. | ./gradlew :RandomFileSenderBot:runJvm --args="<BOT_TOKEN> <FILES_DIRECTORY>" |
| ReactionsInfoBot | Handles per-user reaction changes and anonymous reaction-count updates. | ./gradlew :ReactionsInfoBot:run --args="<BOT_TOKEN> debug" |
| ResenderBot | Recreates received content while preserving reply, quote, effect, and business context. | ./gradlew :ResenderBot:jvm_launcher:run --args="<BOT_TOKEN> debug" |
| RichMessagesBot | Builds expandable quotations with paragraphs and lists, and replies to rich-text selections. | ./gradlew :RichMessagesBot:run --args="<BOT_TOKEN> debug testServer" |
| RightsChangerBot | Changes member and administrator rights, and demonstrates linked third-party verification descriptions. | ./gradlew :RightsChangerBot:run --args="<BOT_TOKEN> <ALLOWED_USER_ID> debug" |
| SlotMachineDetectorBot | Detects slot-machine dice and decodes their reel values. | ./gradlew :SlotMachineDetectorBot:run --args="<BOT_TOKEN>" |
| StarTransactionsBot | Handles Stars payments, paid-message waivers, TON wallet cards, and transfer events. | ./gradlew :StarTransactionsBot:run --args="<BOT_TOKEN> <ADMIN_USER_ID> debug testServer" |
| StickerInfoBot | Looks up sticker-set metadata for stickers and custom emoji. | ./gradlew :StickerInfoBot:jvm_launcher:run --args="<BOT_TOKEN>" |
| StickerSetHandler | Creates and manages a sticker set owned by each private-chat user. | ./gradlew :StickerSetHandler:run --args="<BOT_TOKEN>" |
| SuggestedPosts | Handles channel direct messages and the suggested-post lifecycle. | ./gradlew :SuggestedPosts:run --args="<BOT_TOKEN> debug testServer" |
| TagsBot | Sets chat-member tags, delegates tag management, and reads sender tags. | ./gradlew :TagsBot:run --args="<BOT_TOKEN> debug testServer" |
| TopicsHandling | Exercises forum-topic and private-chat-topic actions and events. | ./gradlew :TopicsHandling:run --args="<BOT_TOKEN>" |
| UserChatShared | Requests users or chats through reply keyboards and handles the shared results. | ./gradlew :UserChatShared:run --args="<BOT_TOKEN> debug" |
| WebApp | Serves a Compose Web client and demonstrates Telegram Web App integration. | ./gradlew :WebApp:runJvm --args="<BOT_TOKEN> https://webapp.example 8080 debug testServer" |
| WebHooks | Receives Telegram updates through a Ktor webhook server instead of long polling. | ./gradlew :WebHooks:run --args="<BOT_TOKEN> https://bot.example.com debug" |
| WidgetsBot | Sends interactive HTML dice directly or inline, answers widget queries, and updates individual or shared rolls. | ./gradlew :WidgetsBot:run --args="<BOT_TOKEN> debug testServer" |
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.