ptgb
A complete Telegram Bot API client for Dart

Examples

The example/ folder in the repository has a full, numbered set of runnable Dart programs — from a minimal echo bot up to a “god mode” bot that exercises keyboards, media, payments, stickers, invite links, and webhooks together.

One-time setup

  1. Message @BotFather, send /newbot, and copy the token.
  2. Create .env in the package root: TOKEN=123456:ABC-your-token-here
  3. Run any example from the package root: bash dart run example/01_basic_echo_bot.dart

Reading order

File Covers
ptgb_example.dart The bare minimum: create a Bot, poll, reply.
01_basic_echo_bot.dart Same idea, fully commented line by line.
02_commands_and_text.dart Loading the token from .env, /command routing, setMyCommands.
03_keyboards.dart Inline keyboards, reply keyboards, callback queries.
04_media_and_files.dart Sending photos by URL/path/bytes, albums, downloading received files.
05_polls_dice_reactions.dart Native polls, quizzes, animated dice, message reactions.
06_callback_queries_and_editing.dart A live-editing counter built on editMessageText.
07_chat_and_forum_admin.dart Muting/unmuting members, pinning, forum topics.
08_inline_queries.dart Inline mode (@yourbot ... in any chat).
09_payments_and_stars.dart Selling something with Telegram Stars — invoice → checkout → success.
10_webhook_server.dart Switching from polling to a production-style webhook server.
11_god_mode_bot.dart Everything above, combined into one polished, menu-driven bot.
12_web_app_verification.dart Verifying a Telegram Mini App’s signed initData.
13_invite_links_and_join_requests.dart Invite links that require bot approval.
14_sticker_sets.dart The multi-step flow for creating and adding to a sticker set.
15_error_handling_and_retries.dart Handling TelegramApiException: rate limits, blocked chats, retry/backoff.
16_custom_env_config.dart Overriding the .env filename and key via dotFileName/envKey.
17_rate_limiting.dart Optional global + per-chat RateLimiter passed to Bot().
18_typed_message_helpers.dart Wrapping raw update JSON in typed User/Chat/Message helpers.
19_update_shortcuts_and_any_message.dart Update's direct-access shortcuts and the anyMessage fallback.
20_new_bot_api_concepts.dart Checklists, rich messages, suggested posts, ephemeral messages, guest queries, join-request guard bots.
21_reply_parameters_and_quoting.dart ReplyParameters: replying, quoting an excerpt, replying across chats.
22_link_preview_options.dart LinkPreviewOptions: disabling, resizing, or repositioning link previews.
23_advanced_reactions.dart ReactionType variants and removing reactions with deleteMessageReaction.
24_forwarding_and_copying.dart forwardMessage(s) vs. copyMessage(s).
25_locations_and_venues.dart sendLocation, sendVenue, and live location updates.
26_contacts_and_chat_actions.dart sendContact and the sendChatAction status indicator.
27_chat_permissions_and_promotion.dart ChatPermissions, promoteChatMember, custom admin titles.
28_bot_profile_and_menu.dart setMyName/setMyDescription/setChatMenuButton.
29_default_admin_rights.dart Pre-filling the admin rights checklist with setMyDefaultAdministratorRights.
30_games_and_high_scores.dart sendGame, setGameScore, getGameHighScores.
31_profile_photos_and_downloads.dart getUserProfilePhotos, downloadFileById, the bot's own profile photo.
32_chat_boosts_and_verification.dart getUserChatBoosts and the verifyUser/verifyChat family.
33_gifts.dart getAvailableGifts, sendGift, giftPremiumSubscription.
34_business_account_profile.dart Editing a connected Business Account's name, bio, photo, and gift settings.
35_business_stars_and_messages.dart Business Account Star balance and readBusinessMessage/deleteBusinessMessages.
36_stories.dart postStory, editStory, deleteStory, repostStory.
37_prepared_messages.dart savePreparedInlineMessage and savePreparedKeyboardButton.
38_subscription_invite_links.dart createChatSubscriptionInviteLink and editUserStarSubscription.
39_message_drafts.dart sendMessageDraft and sendRichMessageDraft.
40_custom_emoji_and_sticker_details.dart getStickerSet, getCustomEmojiStickers, sticker metadata edits.

A note on error handling in the examples

Most examples keep things short by not wrapping every call in try/catch. In a real bot, don’t skip this — see Error Handling for why and how.