Skip to content

API 9.6: Managed Bots - #5197

Merged
harshil21 merged 15 commits into
api-9.6-centralfrom
api-9.6-managed-bots
May 7, 2026
Merged

API 9.6: Managed Bots#5197
harshil21 merged 15 commits into
api-9.6-centralfrom
api-9.6-managed-bots

Conversation

@harshil21

Copy link
Copy Markdown
Member

Completes the first section of Bot API 9.6 - Managed bots

Check-list for PRs

  • Added .. versionadded:: NEXT.VERSION, .. versionchanged:: NEXT.VERSION, .. deprecated:: NEXT.VERSION or ``.. versionremoved:: NEXT.VERSION` to the docstrings for user facing changes (for methods/class descriptions, arguments and attributes)
  • Created new or adapted existing unit tests
  • Documented code changes according to the CSI standard
  • Added myself alphabetically to AUTHORS.rst (optional)
  • Added new classes & modules to the docs and all suitable __all__ s
  • Checked the Stability Policy in case of deprecations or changes to documented behavior

If the PR contains API changes (otherwise, you can ignore this passage)

  • Checked the Bot API specific sections of the Stability Policy

  • Created a PR to remove functionality deprecated in the previous Bot API release (see here)

  • New Classes

    • Added self._id_attrs and corresponding documentation
    • __init__ accepts api_kwargs as keyword-only
  • Added New Shortcuts

    • In telegram.Chat & telegram.User for all methods that accept chat/user_id
    • In telegram.Message for all methods that accept chat_id and message_id
    • For new telegram.Message shortcuts: Added quote argument if methods accept reply_to_message_id
    • In telegram.CallbackQuery for all methods that accept either chat_id and message_id or inline_message_id
  • If Relevant

    • Added new constants at telegram.constants and shortcuts to them as class variables
    • Linked new and existing constants in docstrings instead of hard-coded numbers and strings
    • Added new message types to telegram.Message.effective_attachment
    • Added new handlers for new update types
    • Added new filters for new message (sub)types
    • Added or updated documentation for the changed class(es) and/or method(s)
    • Added the new method(s) to _extbot.py
    • Added or updated bot_methods.rst
    • Updated the Bot API version number in all places: README.rst (including the badge) and telegram.constants.BOT_API_VERSION_INFO
    • Added logic for arbitrary callback data in telegram.ext.ExtBot for new methods that either accept a reply_markup in some form or have a return type that is/contains telegram.Message

@harshil21
harshil21 requested a review from Copilot April 4, 2026 11:10
@harshil21 harshil21 added the ⚙️ bot-api affected functionality: bot-api label Apr 4, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds initial support for Telegram Bot API 9.6 “Managed Bots” to the library by introducing new API objects, update/handler support, bot methods, filters, and accompanying docs/tests.

Changes:

  • Introduces new Telegram objects: ManagedBotCreated, ManagedBotUpdated, KeyboardButtonRequestManagedBot, and PreparedKeyboardButton.
  • Adds new bot API methods + ExtBot wrappers: get_managed_bot_token, replace_managed_bot_token, save_prepared_keyboard_button.
  • Integrates managed-bot update handling via Update.managed_bot, ManagedBotUpdatedHandler, and a filters.StatusUpdate.MANAGED_BOT_CREATED filter.

Reviewed changes

Copilot reviewed 35 out of 35 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
tests/test_user.py Extends User test coverage for can_manage_bots.
tests/test_update.py Adds managed_bot update test cases (effective_* coverage updated).
tests/test_preparedkeyboardbutton.py New tests for PreparedKeyboardButton.
tests/test_message.py Adds managed_bot_created message payload coverage.
tests/test_managedbot.py New tests for ManagedBotCreated/ManagedBotUpdated.
tests/test_keyboardbuttonrequestmanagedbot.py New tests for KeyboardButtonRequestManagedBot.
tests/test_keyboardbutton.py Extends KeyboardButton tests for request_managed_bot.
tests/test_bot.py Adds request-parameter assertions for new bot methods.
tests/ext/test_managedbotupdatedhandler.py New tests for ManagedBotUpdatedHandler.
tests/ext/test_filters.py Adds filter test coverage for MANAGED_BOT_CREATED.
tests/auxil/dummy_objects.py Adds dummy object entry for PreparedKeyboardButton.
tests/_files/test_photo.py Broadens accepted thumb.file_size values.
src/telegram/ext/filters.py Adds StatusUpdate.MANAGED_BOT_CREATED and includes it in StatusUpdate.ALL.
src/telegram/ext/_handlers/managedbotupdatedhandler.py Implements new ManagedBotUpdatedHandler.
src/telegram/ext/_extbot.py Adds ExtBot wrappers for managed-bot methods and save_prepared_keyboard_button.
src/telegram/ext/init.py Exposes ManagedBotUpdatedHandler in telegram.ext.
src/telegram/constants.py Adds MessageType.MANAGED_BOT_CREATED and UpdateType.MANAGED_BOT.
src/telegram/_user.py Adds User.can_manage_bots.
src/telegram/_update.py Adds Update.managed_bot parsing and effective_user support.
src/telegram/_preparedkeyboardbutton.py New PreparedKeyboardButton TelegramObject.
src/telegram/_message.py Adds Message.managed_bot_created parsing.
src/telegram/_managedbot.py New ManagedBotCreated and ManagedBotUpdated TelegramObjects.
src/telegram/_keyboardbuttonrequestmanagedbot.py New KeyboardButtonRequestManagedBot TelegramObject.
src/telegram/_keyboardbutton.py Adds KeyboardButton.request_managed_bot parsing/storage.
src/telegram/_bot.py Adds core bot methods for managed-bot tokens and saving prepared keyboard buttons.
src/telegram/init.py Exposes new objects from the top-level telegram package.
docs/source/telegram.preparedkeyboardbutton.rst Adds API docs page for PreparedKeyboardButton.
docs/source/telegram.managedbotupdated.rst Adds API docs page for ManagedBotUpdated.
docs/source/telegram.managedbotcreated.rst Adds API docs page for ManagedBotCreated.
docs/source/telegram.keyboardbuttonrequestmanagedbot.rst Adds API docs page for KeyboardButtonRequestManagedBot.
docs/source/telegram.ext.managedbotupdatedhandler.rst Adds API docs page for ManagedBotUpdatedHandler.
docs/source/telegram.ext.handlers-tree.rst Registers the new handler docs page in the handlers tree.
docs/source/telegram.at-tree.rst Registers new types docs pages in the available-types tree.
docs/source/inclusions/bot_methods.rst Updates bot methods listing for new API methods.

Comment thread src/telegram/_bot.py Outdated
Comment thread src/telegram/_bot.py Outdated
Comment thread tests/test_update.py
Comment thread tests/test_update.py
Comment thread src/telegram/ext/_handlers/managedbotupdatedhandler.py Outdated
Comment thread docs/source/inclusions/bot_methods.rst Outdated
@harshil21
harshil21 requested review from Poolitzer and aelkheir April 9, 2026 02:29

@aelkheir aelkheir left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!
Haven't reviewed the tests yet.

Comment thread src/telegram/_keyboardbuttonrequestmanagedbot.py Outdated
Comment thread src/telegram/_managedbot.py Outdated
Comment thread src/telegram/_user.py
Comment thread src/telegram/_update.py Outdated
Comment thread src/telegram/_update.py Outdated
Comment thread src/telegram/_update.py Outdated
self._user_ids = parse_chat_id(user_id)
self._usernames = parse_username(username)

def check_update(self, update: object) -> bool:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if normal user ids don't collide with bot user ids, would it be sensible to extend this to check against update.managed_bot.bot also?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if that would be useful, but I added it anyway.

@Poolitzer Poolitzer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM also just one nitpick

Comment thread src/telegram/_update.py Outdated
@harshil21
harshil21 merged commit 8b5c9ef into api-9.6-central May 7, 2026
26 of 27 checks passed
@harshil21
harshil21 deleted the api-9.6-managed-bots branch May 7, 2026 10:06
@github-actions github-actions Bot locked and limited conversation to collaborators May 15, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

⚙️ bot-api affected functionality: bot-api

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants