Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/unreleased/5196.7keq7yJhXbMb9RyShLHz4D.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ features = "Full Support for Bot API 9.6"

pull_requests = [
{ uid = "5196", author_uid = "harshil21" },
{ uid = "5197", author_uid = "harshil21" },
]
7 changes: 7 additions & 0 deletions docs/source/inclusions/bot_methods.rst
Original file line number Diff line number Diff line change
Expand Up @@ -496,12 +496,19 @@
- Used for getting information about gifts available for sending
* - :meth:`~telegram.Bot.get_chat_gifts`
- Used for getting information about gifts owned and hosted by a chat
* - :meth:`~telegram.Bot.get_managed_bot_token`
- Used for getting the token of a managed bot
* - :meth:`~telegram.Bot.replace_managed_bot_token`
- Used for replacing the token of a managed bot
* - :meth:`~telegram.Bot.get_me`
- Used for getting basic information about the bot
* - :meth:`~telegram.Bot.get_user_gifts`
- Used for getting information about gifts owned and hosted by a user
* - :meth:`~telegram.Bot.save_prepared_inline_message`
- Used for storing a message to be sent by a user of a Mini App
* - :meth:`~telegram.Bot.save_prepared_keyboard_button`
- Used for saving a keyboard button to be used in a Mini App


.. raw:: html

Expand Down
4 changes: 4 additions & 0 deletions docs/source/telegram.at-tree.rst
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,14 @@ Available Types
telegram.keyboardbutton
telegram.keyboardbuttonpolltype
telegram.keyboardbuttonrequestchat
telegram.keyboardbuttonrequestmanagedbot
telegram.keyboardbuttonrequestusers
telegram.linkpreviewoptions
telegram.location
telegram.locationaddress
telegram.loginurl
telegram.managedbotcreated
telegram.managedbotupdated
telegram.maybeinaccessiblemessage
telegram.menubutton
telegram.menubuttoncommands
Expand Down Expand Up @@ -152,6 +155,7 @@ Available Types
telegram.poll
telegram.pollanswer
telegram.polloption
telegram.preparedkeyboardbutton
telegram.proximityalerttriggered
telegram.reactioncount
telegram.reactiontype
Expand Down
1 change: 1 addition & 0 deletions docs/source/telegram.ext.handlers-tree.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Handlers
telegram.ext.conversationhandler
telegram.ext.filters
telegram.ext.inlinequeryhandler
telegram.ext.managedbotupdatedhandler
telegram.ext.messagehandler
telegram.ext.messagereactionhandler
telegram.ext.paidmediapurchasedhandler
Expand Down
6 changes: 6 additions & 0 deletions docs/source/telegram.ext.managedbotupdatedhandler.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ManagedBotUpdatedHandler
========================

.. autoclass:: telegram.ext.ManagedBotUpdatedHandler
:members:
:show-inheritance:
6 changes: 6 additions & 0 deletions docs/source/telegram.keyboardbuttonrequestmanagedbot.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
KeyboardButtonRequestManagedBot
===============================

.. autoclass:: telegram.KeyboardButtonRequestManagedBot
:members:
:show-inheritance:
6 changes: 6 additions & 0 deletions docs/source/telegram.managedbotcreated.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ManagedBotCreated
=================

.. autoclass:: telegram.ManagedBotCreated
:members:
:show-inheritance:
6 changes: 6 additions & 0 deletions docs/source/telegram.managedbotupdated.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ManagedBotUpdated
=================

.. autoclass:: telegram.ManagedBotUpdated
:members:
:show-inheritance:
6 changes: 6 additions & 0 deletions docs/source/telegram.preparedkeyboardbutton.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
PreparedKeyboardButton
======================

.. autoclass:: telegram.PreparedKeyboardButton
:members:
:show-inheritance:
7 changes: 7 additions & 0 deletions src/telegram/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,15 @@
"KeyboardButton",
"KeyboardButtonPollType",
"KeyboardButtonRequestChat",
"KeyboardButtonRequestManagedBot",
"KeyboardButtonRequestUsers",
"LabeledPrice",
"LinkPreviewOptions",
"Location",
"LocationAddress",
"LoginUrl",
"ManagedBotCreated",
"ManagedBotUpdated",
"MaskPosition",
"MaybeInaccessibleMessage",
"MenuButton",
Expand Down Expand Up @@ -231,6 +234,7 @@
"PollOption",
"PreCheckoutQuery",
"PreparedInlineMessage",
"PreparedKeyboardButton",
"ProximityAlertTriggered",
"ReactionCount",
"ReactionType",
Expand Down Expand Up @@ -499,8 +503,10 @@
from ._keyboardbutton import KeyboardButton
from ._keyboardbuttonpolltype import KeyboardButtonPollType
from ._keyboardbuttonrequest import KeyboardButtonRequestChat, KeyboardButtonRequestUsers
from ._keyboardbuttonrequestmanagedbot import KeyboardButtonRequestManagedBot
from ._linkpreviewoptions import LinkPreviewOptions
from ._loginurl import LoginUrl
from ._managedbot import ManagedBotCreated, ManagedBotUpdated
from ._menubutton import MenuButton, MenuButtonCommands, MenuButtonDefault, MenuButtonWebApp
from ._message import InaccessibleMessage, MaybeInaccessibleMessage, Message
from ._messageautodeletetimerchanged import MessageAutoDeleteTimerChanged
Expand Down Expand Up @@ -565,6 +571,7 @@
)
from ._payment.successfulpayment import SuccessfulPayment
from ._poll import InputPollOption, Poll, PollAnswer, PollOption
from ._preparedkeyboardbutton import PreparedKeyboardButton
from ._proximityalerttriggered import ProximityAlertTriggered
from ._reaction import (
ReactionCount,
Expand Down
132 changes: 132 additions & 0 deletions src/telegram/_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,15 @@
from telegram._inline.inlinequeryresultsbutton import InlineQueryResultsButton
from telegram._inline.preparedinlinemessage import PreparedInlineMessage
from telegram._inputchecklist import InputChecklist
from telegram._keyboardbutton import KeyboardButton
from telegram._menubutton import MenuButton
from telegram._message import Message
from telegram._messageid import MessageId
from telegram._ownedgift import OwnedGifts
from telegram._payment.stars.staramount import StarAmount
from telegram._payment.stars.startransactions import StarTransactions
from telegram._poll import InputPollOption, Poll
from telegram._preparedkeyboardbutton import PreparedKeyboardButton
from telegram._reaction import ReactionType, ReactionTypeCustomEmoji, ReactionTypeEmoji
from telegram._reply import ReplyParameters
from telegram._sentwebappmessage import SentWebAppMessage
Expand Down Expand Up @@ -12081,6 +12083,130 @@ async def set_chat_member_tag(
api_kwargs=api_kwargs,
)

async def get_managed_bot_token(
self,
user_id: int,
*,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
connect_timeout: ODVInput[float] = DEFAULT_NONE,
pool_timeout: ODVInput[float] = DEFAULT_NONE,
api_kwargs: JSONDict | None = None,
) -> str:
"""
Use this method to get the token of a managed bot.

.. versionadded:: NEXT.VERSION

Args:
user_id (:obj:`int`): User identifier of the managed bot whose token will be returned.

Returns:
:obj:`str`: The token of the managed bot.

Raises:
:class:`telegram.error.TelegramError`
"""
data: JSONDict = {
"user_id": user_id,
}

return await self._post(
"getManagedBotToken",
data,
read_timeout=read_timeout,
write_timeout=write_timeout,
connect_timeout=connect_timeout,
pool_timeout=pool_timeout,
api_kwargs=api_kwargs,
)

async def replace_managed_bot_token(
self,
user_id: int,
*,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
connect_timeout: ODVInput[float] = DEFAULT_NONE,
pool_timeout: ODVInput[float] = DEFAULT_NONE,
api_kwargs: JSONDict | None = None,
) -> str:
"""
Use this method to revoke the current token of a managed bot and generate a new one.

.. versionadded:: NEXT.VERSION

Args:
user_id (:obj:`int`): User identifier of the managed bot whose token will be replaced.

Returns:
:obj:`str`: The new token of the managed bot.

Raises:
:class:`telegram.error.TelegramError`
"""
data: JSONDict = {
"user_id": user_id,
}

return await self._post(
"replaceManagedBotToken",
data,
read_timeout=read_timeout,
write_timeout=write_timeout,
connect_timeout=connect_timeout,
pool_timeout=pool_timeout,
api_kwargs=api_kwargs,
)

async def save_prepared_keyboard_button(
self,
user_id: int,
button: KeyboardButton,
*,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
connect_timeout: ODVInput[float] = DEFAULT_NONE,
pool_timeout: ODVInput[float] = DEFAULT_NONE,
api_kwargs: JSONDict | None = None,
) -> PreparedKeyboardButton:
"""
Stores a keyboard button that can be used by a user within a Mini App.

.. versionadded:: NEXT.VERSION

Args:
user_id (:obj:`int`): Unique identifier of the target user that can use the button.
button (:obj:`telegram.KeyboardButton`): An object describing the
button to be saved. The button must be of the type
:attr:`~telegram.KeyboardButton.request_users`,
:attr:`~telegram.KeyboardButton.request_chat`, or
:attr:`~telegram.KeyboardButton.request_managed_bot`.

Returns:
:class:`telegram.PreparedKeyboardButton`

Raises:
:class:`telegram.error.TelegramError`
"""
data: JSONDict = {
"user_id": user_id,
"button": button,
}

return PreparedKeyboardButton.de_json(
await self._post(
"savePreparedKeyboardButton",
data,
read_timeout=read_timeout,
write_timeout=write_timeout,
connect_timeout=connect_timeout,
pool_timeout=pool_timeout,
api_kwargs=api_kwargs,
),
self,
)

def to_dict(self, recursive: bool = True) -> JSONDict: # noqa: ARG002
"""See :meth:`telegram.TelegramObject.to_dict`."""
data: JSONDict = {"id": self.id, "username": self.username, "first_name": self.first_name}
Expand Down Expand Up @@ -12421,3 +12547,9 @@ def to_dict(self, recursive: bool = True) -> JSONDict: # noqa: ARG002
"""Alias for :meth:`get_user_profile_audios`"""
setChatMemberTag = set_chat_member_tag
"""Alias for :meth:`set_chat_member_tag`"""
getManagedBotToken = get_managed_bot_token
"""Alias for :meth:`get_managed_bot_token`"""
replaceManagedBotToken = replace_managed_bot_token
"""Alias for :meth:`replace_managed_bot_token`"""
savePreparedKeyboardButton = save_prepared_keyboard_button
"""Alias for :meth:`save_prepared_keyboard_button`"""
22 changes: 22 additions & 0 deletions src/telegram/_keyboardbutton.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

from telegram._keyboardbuttonpolltype import KeyboardButtonPollType
from telegram._keyboardbuttonrequest import KeyboardButtonRequestChat, KeyboardButtonRequestUsers
from telegram._keyboardbuttonrequestmanagedbot import KeyboardButtonRequestManagedBot
from telegram._telegramobject import TelegramObject
from telegram._utils.argumentparsing import de_json_optional
from telegram._utils.types import JSONDict
Expand Down Expand Up @@ -120,6 +121,14 @@ class KeyboardButton(TelegramObject):
Premium subscription.

.. versionadded:: 22.7
request_managed_bot (:obj:`telegram.KeyboardButtonRequestManagedBot`, optional): If
specified, pressing the button will ask the user to create and share a bot that will
be managed by the current bot. Available for bots that enabled management of other bots
in the `@BotFather <https://telegram.me/BotFather>` Mini App. Available in private
chats only.

.. versionadded:: NEXT.VERSION


Attributes:
text (:obj:`str`): Text of the button. If none of the fields other than :attr:`text`,
Expand Down Expand Up @@ -167,13 +176,21 @@ class KeyboardButton(TelegramObject):
Premium subscription.

.. versionadded:: 22.7
request_managed_bot (:obj:`telegram.KeyboardButtonRequestManagedBot`): Optional. If
specified, pressing the button will ask the user to create and share a bot that will
be managed by the current bot. Available for bots that enabled management of other bots
in the `@BotFather <https://telegram.me/BotFather>` Mini App. Available in private
chats only.

.. versionadded:: NEXT.VERSION
"""

__slots__ = (
"icon_custom_emoji_id",
"request_chat",
"request_contact",
"request_location",
"request_managed_bot",
"request_poll",
"request_users",
"style",
Expand All @@ -192,6 +209,7 @@ def __init__(
request_users: KeyboardButtonRequestUsers | None = None,
style: str | None = None,
icon_custom_emoji_id: str | None = None,
request_managed_bot: KeyboardButtonRequestManagedBot | None = None,
*,
api_kwargs: JSONDict | None = None,
):
Expand All @@ -208,6 +226,7 @@ def __init__(
self.request_chat: KeyboardButtonRequestChat | None = request_chat
self.style: str | None = style
self.icon_custom_emoji_id: str | None = icon_custom_emoji_id
self.request_managed_bot: KeyboardButtonRequestManagedBot | None = request_managed_bot

self._id_attrs = (
self.text,
Expand Down Expand Up @@ -238,6 +257,9 @@ def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "KeyboardButton":
data.get("request_chat"), KeyboardButtonRequestChat, bot
)
data["web_app"] = de_json_optional(data.get("web_app"), WebAppInfo, bot)
data["request_managed_bot"] = de_json_optional(
data.get("request_managed_bot"), KeyboardButtonRequestManagedBot, bot
)

api_kwargs = {}
# This is a deprecated field that TG still returns for backwards compatibility
Expand Down
Loading
Loading