mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
Bot API 6.7 (#1168)
* Added 6.7 features * Update after release * Added tests * Added changelog
This commit is contained in:
parent
aad2de4324
commit
1538bc2e2d
34 changed files with 754 additions and 51 deletions
|
|
@ -71,6 +71,7 @@ from ..methods import (
|
|||
GetMyCommands,
|
||||
GetMyDefaultAdministratorRights,
|
||||
GetMyDescription,
|
||||
GetMyName,
|
||||
GetMyShortDescription,
|
||||
GetStickerSet,
|
||||
GetUpdates,
|
||||
|
|
@ -115,6 +116,7 @@ from ..methods import (
|
|||
SetMyCommands,
|
||||
SetMyDefaultAdministratorRights,
|
||||
SetMyDescription,
|
||||
SetMyName,
|
||||
SetMyShortDescription,
|
||||
SetPassportDataErrors,
|
||||
SetStickerEmojiList,
|
||||
|
|
@ -140,6 +142,7 @@ from ..types import (
|
|||
BotCommand,
|
||||
BotCommandScope,
|
||||
BotDescription,
|
||||
BotName,
|
||||
BotShortDescription,
|
||||
Chat,
|
||||
ChatAdministratorRights,
|
||||
|
|
@ -158,6 +161,7 @@ from ..types import (
|
|||
GameHighScore,
|
||||
InlineKeyboardMarkup,
|
||||
InlineQueryResult,
|
||||
InlineQueryResultsButton,
|
||||
InputFile,
|
||||
InputMedia,
|
||||
InputMediaAudio,
|
||||
|
|
@ -481,8 +485,9 @@ class Bot(ContextInstanceMixin["Bot"]):
|
|||
cache_time: Optional[int] = None,
|
||||
is_personal: Optional[bool] = None,
|
||||
next_offset: Optional[str] = None,
|
||||
switch_pm_text: Optional[str] = None,
|
||||
button: Optional[InlineQueryResultsButton] = None,
|
||||
switch_pm_parameter: Optional[str] = None,
|
||||
switch_pm_text: Optional[str] = None,
|
||||
request_timeout: Optional[int] = None,
|
||||
) -> bool:
|
||||
"""
|
||||
|
|
@ -495,10 +500,11 @@ class Bot(ContextInstanceMixin["Bot"]):
|
|||
:param inline_query_id: Unique identifier for the answered query
|
||||
:param results: A JSON-serialized array of results for the inline query
|
||||
:param cache_time: The maximum amount of time in seconds that the result of the inline query may be cached on the server. Defaults to 300.
|
||||
:param is_personal: Pass :code:`True` if results may be cached on the server side only for the user that sent the query. By default, results may be returned to any user who sends the same query
|
||||
:param is_personal: Pass :code:`True` if results may be cached on the server side only for the user that sent the query. By default, results may be returned to any user who sends the same query.
|
||||
:param next_offset: Pass the offset that a client should send in the next query with the same text to receive more results. Pass an empty string if there are no more results or if you don't support pagination. Offset length can't exceed 64 bytes.
|
||||
:param switch_pm_text: If passed, clients will display a button with specified text that switches the user to a private chat with the bot and sends the bot a start message with the parameter *switch_pm_parameter*
|
||||
:param button: A JSON-serialized object describing a button to be shown above inline query results
|
||||
:param switch_pm_parameter: `Deep-linking <https://core.telegram.org/bots/features#deep-linking>`_ parameter for the /start message sent to the bot when user presses the switch button. 1-64 characters, only :code:`A-Z`, :code:`a-z`, :code:`0-9`, :code:`_` and :code:`-` are allowed.
|
||||
:param switch_pm_text: If passed, clients will display a button with specified text that switches the user to a private chat with the bot and sends the bot a start message with the parameter *switch_pm_parameter*
|
||||
:param request_timeout: Request timeout
|
||||
:return: On success, :code:`True` is returned.
|
||||
"""
|
||||
|
|
@ -509,8 +515,9 @@ class Bot(ContextInstanceMixin["Bot"]):
|
|||
cache_time=cache_time,
|
||||
is_personal=is_personal,
|
||||
next_offset=next_offset,
|
||||
switch_pm_text=switch_pm_text,
|
||||
button=button,
|
||||
switch_pm_parameter=switch_pm_parameter,
|
||||
switch_pm_text=switch_pm_text,
|
||||
)
|
||||
return await self(call, request_timeout=request_timeout)
|
||||
|
||||
|
|
@ -3913,3 +3920,46 @@ class Bot(ContextInstanceMixin["Bot"]):
|
|||
title=title,
|
||||
)
|
||||
return await self(call, request_timeout=request_timeout)
|
||||
|
||||
async def get_my_name(
|
||||
self,
|
||||
language_code: Optional[str] = None,
|
||||
request_timeout: Optional[int] = None,
|
||||
) -> BotName:
|
||||
"""
|
||||
Use this method to get the current bot name for the given user language. Returns :class:`aiogram.types.bot_name.BotName` on success.
|
||||
|
||||
Source: https://core.telegram.org/bots/api#getmyname
|
||||
|
||||
:param language_code: A two-letter ISO 639-1 language code or an empty string
|
||||
:param request_timeout: Request timeout
|
||||
:return: Returns :class:`aiogram.types.bot_name.BotName` on success.
|
||||
"""
|
||||
|
||||
call = GetMyName(
|
||||
language_code=language_code,
|
||||
)
|
||||
return await self(call, request_timeout=request_timeout)
|
||||
|
||||
async def set_my_name(
|
||||
self,
|
||||
name: Optional[str] = None,
|
||||
language_code: Optional[str] = None,
|
||||
request_timeout: Optional[int] = None,
|
||||
) -> bool:
|
||||
"""
|
||||
Use this method to change the bot's name. Returns :code:`True` on success.
|
||||
|
||||
Source: https://core.telegram.org/bots/api#setmyname
|
||||
|
||||
:param name: New bot name; 0-64 characters. Pass an empty string to remove the dedicated name for the given language.
|
||||
:param language_code: A two-letter ISO 639-1 language code. If empty, the name will be shown to all users for whose language there is no dedicated name.
|
||||
:param request_timeout: Request timeout
|
||||
:return: Returns :code:`True` on success.
|
||||
"""
|
||||
|
||||
call = SetMyName(
|
||||
name=name,
|
||||
language_code=language_code,
|
||||
)
|
||||
return await self(call, request_timeout=request_timeout)
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@ from .get_me import GetMe
|
|||
from .get_my_commands import GetMyCommands
|
||||
from .get_my_default_administrator_rights import GetMyDefaultAdministratorRights
|
||||
from .get_my_description import GetMyDescription
|
||||
from .get_my_name import GetMyName
|
||||
from .get_my_short_description import GetMyShortDescription
|
||||
from .get_sticker_set import GetStickerSet
|
||||
from .get_updates import GetUpdates
|
||||
|
|
@ -92,6 +93,7 @@ from .set_game_score import SetGameScore
|
|||
from .set_my_commands import SetMyCommands
|
||||
from .set_my_default_administrator_rights import SetMyDefaultAdministratorRights
|
||||
from .set_my_description import SetMyDescription
|
||||
from .set_my_name import SetMyName
|
||||
from .set_my_short_description import SetMyShortDescription
|
||||
from .set_passport_data_errors import SetPassportDataErrors
|
||||
from .set_sticker_emoji_list import SetStickerEmojiList
|
||||
|
|
@ -161,6 +163,7 @@ __all__ = (
|
|||
"GetMyCommands",
|
||||
"GetMyDefaultAdministratorRights",
|
||||
"GetMyDescription",
|
||||
"GetMyName",
|
||||
"GetMyShortDescription",
|
||||
"GetStickerSet",
|
||||
"GetUpdates",
|
||||
|
|
@ -207,6 +210,7 @@ __all__ = (
|
|||
"SetMyCommands",
|
||||
"SetMyDefaultAdministratorRights",
|
||||
"SetMyDescription",
|
||||
"SetMyName",
|
||||
"SetMyShortDescription",
|
||||
"SetPassportDataErrors",
|
||||
"SetStickerEmojiList",
|
||||
|
|
|
|||
|
|
@ -2,7 +2,9 @@ from __future__ import annotations
|
|||
|
||||
from typing import TYPE_CHECKING, List, Optional
|
||||
|
||||
from ..types import InlineQueryResult
|
||||
from pydantic import Field
|
||||
|
||||
from ..types import InlineQueryResult, InlineQueryResultsButton
|
||||
from .base import TelegramMethod
|
||||
|
||||
|
||||
|
|
@ -25,10 +27,18 @@ class AnswerInlineQuery(TelegramMethod[bool]):
|
|||
cache_time: Optional[int] = None
|
||||
"""The maximum amount of time in seconds that the result of the inline query may be cached on the server. Defaults to 300."""
|
||||
is_personal: Optional[bool] = None
|
||||
"""Pass :code:`True` if results may be cached on the server side only for the user that sent the query. By default, results may be returned to any user who sends the same query"""
|
||||
"""Pass :code:`True` if results may be cached on the server side only for the user that sent the query. By default, results may be returned to any user who sends the same query."""
|
||||
next_offset: Optional[str] = None
|
||||
"""Pass the offset that a client should send in the next query with the same text to receive more results. Pass an empty string if there are no more results or if you don't support pagination. Offset length can't exceed 64 bytes."""
|
||||
switch_pm_text: Optional[str] = None
|
||||
"""If passed, clients will display a button with specified text that switches the user to a private chat with the bot and sends the bot a start message with the parameter *switch_pm_parameter*"""
|
||||
switch_pm_parameter: Optional[str] = None
|
||||
"""`Deep-linking <https://core.telegram.org/bots/features#deep-linking>`_ parameter for the /start message sent to the bot when user presses the switch button. 1-64 characters, only :code:`A-Z`, :code:`a-z`, :code:`0-9`, :code:`_` and :code:`-` are allowed."""
|
||||
button: Optional[InlineQueryResultsButton] = None
|
||||
"""A JSON-serialized object describing a button to be shown above inline query results"""
|
||||
switch_pm_parameter: Optional[str] = Field(None, deprecated=True)
|
||||
"""`Deep-linking <https://core.telegram.org/bots/features#deep-linking>`_ parameter for the /start message sent to the bot when user presses the switch button. 1-64 characters, only :code:`A-Z`, :code:`a-z`, :code:`0-9`, :code:`_` and :code:`-` are allowed.
|
||||
|
||||
.. deprecated:: API:6.7
|
||||
https://core.telegram.org/bots/api-changelog#april-21-2023"""
|
||||
switch_pm_text: Optional[str] = Field(None, deprecated=True)
|
||||
"""If passed, clients will display a button with specified text that switches the user to a private chat with the bot and sends the bot a start message with the parameter *switch_pm_parameter*
|
||||
|
||||
.. deprecated:: API:6.7
|
||||
https://core.telegram.org/bots/api-changelog#april-21-2023"""
|
||||
|
|
|
|||
18
aiogram/methods/get_my_name.py
Normal file
18
aiogram/methods/get_my_name.py
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
from typing import Optional
|
||||
|
||||
from ..types import BotName
|
||||
from .base import TelegramMethod
|
||||
|
||||
|
||||
class GetMyName(TelegramMethod[BotName]):
|
||||
"""
|
||||
Use this method to get the current bot name for the given user language. Returns :class:`aiogram.types.bot_name.BotName` on success.
|
||||
|
||||
Source: https://core.telegram.org/bots/api#getmyname
|
||||
"""
|
||||
|
||||
__returning__ = BotName
|
||||
__api_method__ = "getMyName"
|
||||
|
||||
language_code: Optional[str] = None
|
||||
"""A two-letter ISO 639-1 language code or an empty string"""
|
||||
19
aiogram/methods/set_my_name.py
Normal file
19
aiogram/methods/set_my_name.py
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
from typing import Optional
|
||||
|
||||
from .base import TelegramMethod
|
||||
|
||||
|
||||
class SetMyName(TelegramMethod[bool]):
|
||||
"""
|
||||
Use this method to change the bot's name. Returns :code:`True` on success.
|
||||
|
||||
Source: https://core.telegram.org/bots/api#setmyname
|
||||
"""
|
||||
|
||||
__returning__ = bool
|
||||
__api_method__ = "setMyName"
|
||||
|
||||
name: Optional[str] = None
|
||||
"""New bot name; 0-64 characters. Pass an empty string to remove the dedicated name for the given language."""
|
||||
language_code: Optional[str] = None
|
||||
"""A two-letter ISO 639-1 language code. If empty, the name will be shown to all users for whose language there is no dedicated name."""
|
||||
|
|
@ -15,6 +15,7 @@ from .bot_command_scope_chat_administrators import BotCommandScopeChatAdministra
|
|||
from .bot_command_scope_chat_member import BotCommandScopeChatMember
|
||||
from .bot_command_scope_default import BotCommandScopeDefault
|
||||
from .bot_description import BotDescription
|
||||
from .bot_name import BotName
|
||||
from .bot_short_description import BotShortDescription
|
||||
from .callback_game import CallbackGame
|
||||
from .callback_query import CallbackQuery
|
||||
|
|
@ -77,6 +78,7 @@ from .inline_query_result_photo import InlineQueryResultPhoto
|
|||
from .inline_query_result_venue import InlineQueryResultVenue
|
||||
from .inline_query_result_video import InlineQueryResultVideo
|
||||
from .inline_query_result_voice import InlineQueryResultVoice
|
||||
from .inline_query_results_button import InlineQueryResultsButton
|
||||
from .input_contact_message_content import InputContactMessageContent
|
||||
from .input_file import BufferedInputFile, FSInputFile, InputFile, URLInputFile
|
||||
from .input_invoice_message_content import InputInvoiceMessageContent
|
||||
|
|
@ -139,6 +141,7 @@ from .shipping_query import ShippingQuery
|
|||
from .sticker import Sticker
|
||||
from .sticker_set import StickerSet
|
||||
from .successful_payment import SuccessfulPayment
|
||||
from .switch_inline_query_chosen_chat import SwitchInlineQueryChosenChat
|
||||
from .update import Update
|
||||
from .user import User
|
||||
from .user_profile_photos import UserProfilePhotos
|
||||
|
|
@ -169,6 +172,7 @@ __all__ = (
|
|||
"BotCommandScopeChatMember",
|
||||
"BotCommandScopeDefault",
|
||||
"BotDescription",
|
||||
"BotName",
|
||||
"BotShortDescription",
|
||||
"BufferedInputFile",
|
||||
"CallbackGame",
|
||||
|
|
@ -234,6 +238,7 @@ __all__ = (
|
|||
"InlineQueryResultVenue",
|
||||
"InlineQueryResultVideo",
|
||||
"InlineQueryResultVoice",
|
||||
"InlineQueryResultsButton",
|
||||
"InputContactMessageContent",
|
||||
"InputFile",
|
||||
"InputInvoiceMessageContent",
|
||||
|
|
@ -294,6 +299,7 @@ __all__ = (
|
|||
"Sticker",
|
||||
"StickerSet",
|
||||
"SuccessfulPayment",
|
||||
"SwitchInlineQueryChosenChat",
|
||||
"TelegramObject",
|
||||
"UNSET_PARSE_MODE",
|
||||
"URLInputFile",
|
||||
|
|
|
|||
12
aiogram/types/bot_name.py
Normal file
12
aiogram/types/bot_name.py
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
from .base import TelegramObject
|
||||
|
||||
|
||||
class BotName(TelegramObject):
|
||||
"""
|
||||
This object represents the bot's name.
|
||||
|
||||
Source: https://core.telegram.org/bots/api#botname
|
||||
"""
|
||||
|
||||
name: str
|
||||
"""The bot's name"""
|
||||
|
|
@ -52,3 +52,5 @@ class ChatMemberUpdated(TelegramObject):
|
|||
"""New information about the chat member"""
|
||||
invite_link: Optional[ChatInviteLink] = None
|
||||
"""*Optional*. Chat invite link, which was used by the user to join the chat; for joining by invite link events only."""
|
||||
via_chat_folder_invite_link: Optional[bool] = None
|
||||
"""*Optional*. True, if the user joined the chat via a chat folder invite link"""
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ from .base import MutableTelegramObject
|
|||
if TYPE_CHECKING:
|
||||
from .callback_game import CallbackGame
|
||||
from .login_url import LoginUrl
|
||||
from .switch_inline_query_chosen_chat import SwitchInlineQueryChosenChat
|
||||
from .web_app_info import WebAppInfo
|
||||
|
||||
|
||||
|
|
@ -31,6 +32,8 @@ class InlineKeyboardButton(MutableTelegramObject):
|
|||
"""*Optional*. If set, pressing the button will prompt the user to select one of their chats, open that chat and insert the bot's username and the specified inline query in the input field. May be empty, in which case just the bot's username will be inserted."""
|
||||
switch_inline_query_current_chat: Optional[str] = None
|
||||
"""*Optional*. If set, pressing the button will insert the bot's username and the specified inline query in the current chat's input field. May be empty, in which case only the bot's username will be inserted."""
|
||||
switch_inline_query_chosen_chat: Optional[SwitchInlineQueryChosenChat] = None
|
||||
"""*Optional*. If set, pressing the button will prompt the user to select one of their chats of the specified type, open that chat and insert the bot's username and the specified inline query in the input field"""
|
||||
callback_game: Optional[CallbackGame] = None
|
||||
"""*Optional*. Description of the game that will be launched when the user presses the button."""
|
||||
pay: Optional[bool] = None
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ from .base import TelegramObject
|
|||
if TYPE_CHECKING:
|
||||
from ..methods import AnswerInlineQuery
|
||||
from .inline_query_result import InlineQueryResult
|
||||
from .inline_query_results_button import InlineQueryResultsButton
|
||||
from .location import Location
|
||||
from .user import User
|
||||
|
||||
|
|
@ -39,8 +40,9 @@ class InlineQuery(TelegramObject):
|
|||
cache_time: Optional[int] = None,
|
||||
is_personal: Optional[bool] = None,
|
||||
next_offset: Optional[str] = None,
|
||||
switch_pm_text: Optional[str] = None,
|
||||
button: Optional[InlineQueryResultsButton] = None,
|
||||
switch_pm_parameter: Optional[str] = None,
|
||||
switch_pm_text: Optional[str] = None,
|
||||
**kwargs: Any,
|
||||
) -> AnswerInlineQuery:
|
||||
"""
|
||||
|
|
@ -57,10 +59,11 @@ class InlineQuery(TelegramObject):
|
|||
|
||||
:param results: A JSON-serialized array of results for the inline query
|
||||
:param cache_time: The maximum amount of time in seconds that the result of the inline query may be cached on the server. Defaults to 300.
|
||||
:param is_personal: Pass :code:`True` if results may be cached on the server side only for the user that sent the query. By default, results may be returned to any user who sends the same query
|
||||
:param is_personal: Pass :code:`True` if results may be cached on the server side only for the user that sent the query. By default, results may be returned to any user who sends the same query.
|
||||
:param next_offset: Pass the offset that a client should send in the next query with the same text to receive more results. Pass an empty string if there are no more results or if you don't support pagination. Offset length can't exceed 64 bytes.
|
||||
:param switch_pm_text: If passed, clients will display a button with specified text that switches the user to a private chat with the bot and sends the bot a start message with the parameter *switch_pm_parameter*
|
||||
:param button: A JSON-serialized object describing a button to be shown above inline query results
|
||||
:param switch_pm_parameter: `Deep-linking <https://core.telegram.org/bots/features#deep-linking>`_ parameter for the /start message sent to the bot when user presses the switch button. 1-64 characters, only :code:`A-Z`, :code:`a-z`, :code:`0-9`, :code:`_` and :code:`-` are allowed.
|
||||
:param switch_pm_text: If passed, clients will display a button with specified text that switches the user to a private chat with the bot and sends the bot a start message with the parameter *switch_pm_parameter*
|
||||
:return: instance of method :class:`aiogram.methods.answer_inline_query.AnswerInlineQuery`
|
||||
"""
|
||||
# DO NOT EDIT MANUALLY!!!
|
||||
|
|
@ -74,7 +77,8 @@ class InlineQuery(TelegramObject):
|
|||
cache_time=cache_time,
|
||||
is_personal=is_personal,
|
||||
next_offset=next_offset,
|
||||
switch_pm_text=switch_pm_text,
|
||||
button=button,
|
||||
switch_pm_parameter=switch_pm_parameter,
|
||||
switch_pm_text=switch_pm_text,
|
||||
**kwargs,
|
||||
)
|
||||
|
|
|
|||
23
aiogram/types/inline_query_results_button.py
Normal file
23
aiogram/types/inline_query_results_button.py
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
|
||||
from .base import TelegramObject
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .web_app_info import WebAppInfo
|
||||
|
||||
|
||||
class InlineQueryResultsButton(TelegramObject):
|
||||
"""
|
||||
This object represents a button to be shown above inline query results. You **must** use exactly one of the optional fields.
|
||||
|
||||
Source: https://core.telegram.org/bots/api#inlinequeryresultsbutton
|
||||
"""
|
||||
|
||||
text: str
|
||||
"""Label text on the button"""
|
||||
web_app: Optional[WebAppInfo] = None
|
||||
"""*Optional*. Description of the `Web App <https://core.telegram.org/bots/webapps>`_ that will be launched when the user presses the button. The Web App will be able to switch back to the inline mode using the method *web_app_switch_inline_query* inside the Web App."""
|
||||
start_parameter: Optional[str] = None
|
||||
"""*Optional*. `Deep-linking <https://core.telegram.org/bots/features#deep-linking>`_ parameter for the /start message sent to the bot when a user presses the button. 1-64 characters, only :code:`A-Z`, :code:`a-z`, :code:`0-9`, :code:`_` and :code:`-` are allowed."""
|
||||
22
aiogram/types/switch_inline_query_chosen_chat.py
Normal file
22
aiogram/types/switch_inline_query_chosen_chat.py
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
from typing import Optional
|
||||
|
||||
from .base import TelegramObject
|
||||
|
||||
|
||||
class SwitchInlineQueryChosenChat(TelegramObject):
|
||||
"""
|
||||
This object represents an inline button that switches the current user to inline mode in a chosen chat, with an optional default inline query.
|
||||
|
||||
Source: https://core.telegram.org/bots/api#switchinlinequerychosenchat
|
||||
"""
|
||||
|
||||
query: Optional[str] = None
|
||||
"""*Optional*. The default inline query to be inserted in the input field. If left empty, only the bot's username will be inserted"""
|
||||
allow_user_chats: Optional[bool] = None
|
||||
"""*Optional*. True, if private chats with users can be chosen"""
|
||||
allow_bot_chats: Optional[bool] = None
|
||||
"""*Optional*. True, if private chats with bots can be chosen"""
|
||||
allow_group_chats: Optional[bool] = None
|
||||
"""*Optional*. True, if group and supergroup chats can be chosen"""
|
||||
allow_channel_chats: Optional[bool] = None
|
||||
"""*Optional*. True, if channel chats can be chosen"""
|
||||
|
|
@ -1,9 +1,14 @@
|
|||
from typing import Optional
|
||||
|
||||
from aiogram.types import TelegramObject
|
||||
|
||||
|
||||
class WriteAccessAllowed(TelegramObject):
|
||||
"""
|
||||
This object represents a service message about a user allowing a bot added to the attachment menu to write messages. Currently holds no information.
|
||||
This object represents a service message about a user allowing a bot to write messages after adding the bot to the attachment menu or launching a Web App from a link.
|
||||
|
||||
Source: https://core.telegram.org/bots/api#writeaccessallowed
|
||||
"""
|
||||
|
||||
web_app_name: Optional[str] = None
|
||||
"""*Optional*. Name of the Web App which was launched from a link"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue