mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
Update API methods and types for Telegram Bot API 9.5
This commit is contained in:
parent
73710acb4c
commit
251df4b193
42 changed files with 575 additions and 72 deletions
|
|
@ -1,2 +1,2 @@
|
|||
__version__ = "3.25.0"
|
||||
__api_version__ = "9.4"
|
||||
__version__ = "3.26.0"
|
||||
__api_version__ = "9.5"
|
||||
|
|
|
|||
|
|
@ -144,6 +144,7 @@ from ..methods import (
|
|||
SetBusinessAccountUsername,
|
||||
SetChatAdministratorCustomTitle,
|
||||
SetChatDescription,
|
||||
SetChatMemberTag,
|
||||
SetChatMenuButton,
|
||||
SetChatPermissions,
|
||||
SetChatPhoto,
|
||||
|
|
@ -2021,6 +2022,7 @@ class Bot:
|
|||
can_pin_messages: bool | None = None,
|
||||
can_manage_topics: bool | None = None,
|
||||
can_manage_direct_messages: bool | None = None,
|
||||
can_manage_tags: bool | None = None,
|
||||
request_timeout: int | None = None,
|
||||
) -> bool:
|
||||
"""
|
||||
|
|
@ -2046,6 +2048,7 @@ class Bot:
|
|||
:param can_pin_messages: Pass :code:`True` if the administrator can pin messages; for supergroups only
|
||||
:param can_manage_topics: Pass :code:`True` if the user is allowed to create, rename, close, and reopen forum topics; for supergroups only
|
||||
:param can_manage_direct_messages: Pass :code:`True` if the administrator can manage direct messages within the channel and decline suggested posts; for channels only
|
||||
:param can_manage_tags: Pass :code:`True` if the administrator can edit the tags of regular members; for groups and supergroups only
|
||||
:param request_timeout: Request timeout
|
||||
:return: Returns :code:`True` on success.
|
||||
"""
|
||||
|
|
@ -2069,6 +2072,7 @@ class Bot:
|
|||
can_pin_messages=can_pin_messages,
|
||||
can_manage_topics=can_manage_topics,
|
||||
can_manage_direct_messages=can_manage_direct_messages,
|
||||
can_manage_tags=can_manage_tags,
|
||||
)
|
||||
return await self(call, request_timeout=request_timeout)
|
||||
|
||||
|
|
@ -5560,7 +5564,7 @@ class Bot:
|
|||
:param chat_id: Unique identifier for the target chat
|
||||
:param message_id: Unique identifier for the target message
|
||||
:param checklist: A JSON-serialized object for the new checklist
|
||||
:param reply_markup: A JSON-serialized object for the new inline keyboard for the message
|
||||
:param reply_markup: A JSON-serialized object for the new `inline keyboard <https://core.telegram.org/bots/features#inline-keyboards>`_ for the message
|
||||
:param request_timeout: Request timeout
|
||||
:return: On success, the edited :class:`aiogram.types.message.Message` is returned.
|
||||
"""
|
||||
|
|
@ -5614,7 +5618,7 @@ class Bot:
|
|||
:param protect_content: Protects the contents of the sent message from forwarding and saving
|
||||
:param message_effect_id: Unique identifier of the message effect to be added to the message
|
||||
:param reply_parameters: A JSON-serialized object for description of the message to reply to
|
||||
:param reply_markup: A JSON-serialized object for an inline keyboard
|
||||
:param reply_markup: A JSON-serialized object for an `inline keyboard <https://core.telegram.org/bots/features#inline-keyboards>`_
|
||||
:param request_timeout: Request timeout
|
||||
:return: On success, the sent :class:`aiogram.types.message.Message` is returned.
|
||||
"""
|
||||
|
|
@ -5823,7 +5827,7 @@ class Bot:
|
|||
request_timeout: int | None = None,
|
||||
) -> bool:
|
||||
"""
|
||||
Use this method to stream a partial message to a user while the message is being generated; supported only for bots with forum topic mode enabled. Returns :code:`True` on success.
|
||||
Use this method to stream a partial message to a user while the message is being generated. Returns :code:`True` on success.
|
||||
|
||||
Source: https://core.telegram.org/bots/api#sendmessagedraft
|
||||
|
||||
|
|
@ -5908,3 +5912,29 @@ class Bot:
|
|||
photo=photo,
|
||||
)
|
||||
return await self(call, request_timeout=request_timeout)
|
||||
|
||||
async def set_chat_member_tag(
|
||||
self,
|
||||
chat_id: ChatIdUnion,
|
||||
user_id: int,
|
||||
tag: str | None = None,
|
||||
request_timeout: int | None = None,
|
||||
) -> bool:
|
||||
"""
|
||||
Use this method to set a tag for a regular member in a group or a supergroup. The bot must be an administrator in the chat for this to work and must have the *can_manage_tags* administrator right. Returns :code:`True` on success.
|
||||
|
||||
Source: https://core.telegram.org/bots/api#setchatmembertag
|
||||
|
||||
:param chat_id: Unique identifier for the target chat or username of the target supergroup (in the format :code:`@supergroupusername`)
|
||||
:param user_id: Unique identifier of the target user
|
||||
:param tag: New tag for the member; 0-16 characters, emoji are not allowed
|
||||
:param request_timeout: Request timeout
|
||||
:return: Returns :code:`True` on success.
|
||||
"""
|
||||
|
||||
call = SetChatMemberTag(
|
||||
chat_id=chat_id,
|
||||
user_id=user_id,
|
||||
tag=tag,
|
||||
)
|
||||
return await self(call, request_timeout=request_timeout)
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ class ContentType(str, Enum):
|
|||
|
||||
UNKNOWN = "unknown"
|
||||
ANY = "any"
|
||||
SENDER_TAG = "sender_tag"
|
||||
TEXT = "text"
|
||||
ANIMATION = "animation"
|
||||
AUDIO = "audio"
|
||||
|
|
|
|||
|
|
@ -27,3 +27,4 @@ class MessageEntityType(str, Enum):
|
|||
TEXT_LINK = "text_link"
|
||||
TEXT_MENTION = "text_mention"
|
||||
CUSTOM_EMOJI = "custom_emoji"
|
||||
DATE_TIME = "date_time"
|
||||
|
|
|
|||
|
|
@ -126,6 +126,7 @@ from .set_business_account_profile_photo import SetBusinessAccountProfilePhoto
|
|||
from .set_business_account_username import SetBusinessAccountUsername
|
||||
from .set_chat_administrator_custom_title import SetChatAdministratorCustomTitle
|
||||
from .set_chat_description import SetChatDescription
|
||||
from .set_chat_member_tag import SetChatMemberTag
|
||||
from .set_chat_menu_button import SetChatMenuButton
|
||||
from .set_chat_permissions import SetChatPermissions
|
||||
from .set_chat_photo import SetChatPhoto
|
||||
|
|
@ -295,6 +296,7 @@ __all__ = (
|
|||
"SetBusinessAccountUsername",
|
||||
"SetChatAdministratorCustomTitle",
|
||||
"SetChatDescription",
|
||||
"SetChatMemberTag",
|
||||
"SetChatMenuButton",
|
||||
"SetChatPermissions",
|
||||
"SetChatPhoto",
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ class EditMessageChecklist(TelegramMethod[Message]):
|
|||
checklist: InputChecklist
|
||||
"""A JSON-serialized object for the new checklist"""
|
||||
reply_markup: InlineKeyboardMarkup | None = None
|
||||
"""A JSON-serialized object for the new inline keyboard for the message"""
|
||||
"""A JSON-serialized object for the new `inline keyboard <https://core.telegram.org/bots/features#inline-keyboards>`_ for the message"""
|
||||
|
||||
if TYPE_CHECKING:
|
||||
# DO NOT EDIT MANUALLY!!!
|
||||
|
|
|
|||
|
|
@ -52,6 +52,8 @@ class PromoteChatMember(TelegramMethod[bool]):
|
|||
"""Pass :code:`True` if the user is allowed to create, rename, close, and reopen forum topics; for supergroups only"""
|
||||
can_manage_direct_messages: bool | None = None
|
||||
"""Pass :code:`True` if the administrator can manage direct messages within the channel and decline suggested posts; for channels only"""
|
||||
can_manage_tags: bool | None = None
|
||||
"""Pass :code:`True` if the administrator can edit the tags of regular members; for groups and supergroups only"""
|
||||
|
||||
if TYPE_CHECKING:
|
||||
# DO NOT EDIT MANUALLY!!!
|
||||
|
|
@ -78,6 +80,7 @@ class PromoteChatMember(TelegramMethod[bool]):
|
|||
can_pin_messages: bool | None = None,
|
||||
can_manage_topics: bool | None = None,
|
||||
can_manage_direct_messages: bool | None = None,
|
||||
can_manage_tags: bool | None = None,
|
||||
**__pydantic_kwargs: Any,
|
||||
) -> None:
|
||||
# DO NOT EDIT MANUALLY!!!
|
||||
|
|
@ -103,5 +106,6 @@ class PromoteChatMember(TelegramMethod[bool]):
|
|||
can_pin_messages=can_pin_messages,
|
||||
can_manage_topics=can_manage_topics,
|
||||
can_manage_direct_messages=can_manage_direct_messages,
|
||||
can_manage_tags=can_manage_tags,
|
||||
**__pydantic_kwargs,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ class SendChecklist(TelegramMethod[Message]):
|
|||
reply_parameters: ReplyParameters | None = None
|
||||
"""A JSON-serialized object for description of the message to reply to"""
|
||||
reply_markup: InlineKeyboardMarkup | None = None
|
||||
"""A JSON-serialized object for an inline keyboard"""
|
||||
"""A JSON-serialized object for an `inline keyboard <https://core.telegram.org/bots/features#inline-keyboards>`_"""
|
||||
|
||||
if TYPE_CHECKING:
|
||||
# DO NOT EDIT MANUALLY!!!
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ from .base import TelegramMethod
|
|||
|
||||
class SendMessageDraft(TelegramMethod[bool]):
|
||||
"""
|
||||
Use this method to stream a partial message to a user while the message is being generated; supported only for bots with forum topic mode enabled. Returns :code:`True` on success.
|
||||
Use this method to stream a partial message to a user while the message is being generated. Returns :code:`True` on success.
|
||||
|
||||
Source: https://core.telegram.org/bots/api#sendmessagedraft
|
||||
"""
|
||||
|
|
|
|||
40
aiogram/methods/set_chat_member_tag.py
Normal file
40
aiogram/methods/set_chat_member_tag.py
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
from ..types import ChatIdUnion
|
||||
from .base import TelegramMethod
|
||||
|
||||
|
||||
class SetChatMemberTag(TelegramMethod[bool]):
|
||||
"""
|
||||
Use this method to set a tag for a regular member in a group or a supergroup. The bot must be an administrator in the chat for this to work and must have the *can_manage_tags* administrator right. Returns :code:`True` on success.
|
||||
|
||||
Source: https://core.telegram.org/bots/api#setchatmembertag
|
||||
"""
|
||||
|
||||
__returning__ = bool
|
||||
__api_method__ = "setChatMemberTag"
|
||||
|
||||
chat_id: ChatIdUnion
|
||||
"""Unique identifier for the target chat or username of the target supergroup (in the format :code:`@supergroupusername`)"""
|
||||
user_id: int
|
||||
"""Unique identifier of the target user"""
|
||||
tag: str | None = None
|
||||
"""New tag for the member; 0-16 characters, emoji are not allowed"""
|
||||
|
||||
if TYPE_CHECKING:
|
||||
# DO NOT EDIT MANUALLY!!!
|
||||
# This section was auto-generated via `butcher`
|
||||
|
||||
def __init__(
|
||||
__pydantic__self__,
|
||||
*,
|
||||
chat_id: ChatIdUnion,
|
||||
user_id: int,
|
||||
tag: str | None = None,
|
||||
**__pydantic_kwargs: Any,
|
||||
) -> None:
|
||||
# DO NOT EDIT MANUALLY!!!
|
||||
# This method was auto-generated via `butcher`
|
||||
# Is needed only for type checking and IDE support without any additional plugins
|
||||
|
||||
super().__init__(chat_id=chat_id, user_id=user_id, tag=tag, **__pydantic_kwargs)
|
||||
|
|
@ -1018,6 +1018,7 @@ class Chat(TelegramObject):
|
|||
can_pin_messages: bool | None = None,
|
||||
can_manage_topics: bool | None = None,
|
||||
can_manage_direct_messages: bool | None = None,
|
||||
can_manage_tags: bool | None = None,
|
||||
**kwargs: Any,
|
||||
) -> PromoteChatMember:
|
||||
"""
|
||||
|
|
@ -1047,6 +1048,7 @@ class Chat(TelegramObject):
|
|||
:param can_pin_messages: Pass :code:`True` if the administrator can pin messages; for supergroups only
|
||||
:param can_manage_topics: Pass :code:`True` if the user is allowed to create, rename, close, and reopen forum topics; for supergroups only
|
||||
:param can_manage_direct_messages: Pass :code:`True` if the administrator can manage direct messages within the channel and decline suggested posts; for channels only
|
||||
:param can_manage_tags: Pass :code:`True` if the administrator can edit the tags of regular members; for groups and supergroups only
|
||||
:return: instance of method :class:`aiogram.methods.promote_chat_member.PromoteChatMember`
|
||||
"""
|
||||
# DO NOT EDIT MANUALLY!!!
|
||||
|
|
@ -1073,6 +1075,7 @@ class Chat(TelegramObject):
|
|||
can_pin_messages=can_pin_messages,
|
||||
can_manage_topics=can_manage_topics,
|
||||
can_manage_direct_messages=can_manage_direct_messages,
|
||||
can_manage_tags=can_manage_tags,
|
||||
**kwargs,
|
||||
).as_(self._bot)
|
||||
|
||||
|
|
|
|||
|
|
@ -47,6 +47,8 @@ class ChatAdministratorRights(TelegramObject):
|
|||
"""*Optional*. :code:`True`, if the user is allowed to create, rename, close, and reopen forum topics; for supergroups only"""
|
||||
can_manage_direct_messages: bool | None = None
|
||||
"""*Optional*. :code:`True`, if the administrator can manage direct messages of the channel and decline suggested posts; for channels only"""
|
||||
can_manage_tags: bool | None = None
|
||||
"""*Optional*. :code:`True`, if the administrator can edit the tags of regular members; for groups and supergroups only. If omitted defaults to the value of can_pin_messages."""
|
||||
|
||||
if TYPE_CHECKING:
|
||||
# DO NOT EDIT MANUALLY!!!
|
||||
|
|
@ -71,6 +73,7 @@ class ChatAdministratorRights(TelegramObject):
|
|||
can_pin_messages: bool | None = None,
|
||||
can_manage_topics: bool | None = None,
|
||||
can_manage_direct_messages: bool | None = None,
|
||||
can_manage_tags: bool | None = None,
|
||||
**__pydantic_kwargs: Any,
|
||||
) -> None:
|
||||
# DO NOT EDIT MANUALLY!!!
|
||||
|
|
@ -94,5 +97,6 @@ class ChatAdministratorRights(TelegramObject):
|
|||
can_pin_messages=can_pin_messages,
|
||||
can_manage_topics=can_manage_topics,
|
||||
can_manage_direct_messages=can_manage_direct_messages,
|
||||
can_manage_tags=can_manage_tags,
|
||||
**__pydantic_kwargs,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -54,6 +54,8 @@ class ChatMemberAdministrator(ChatMember):
|
|||
"""*Optional*. :code:`True`, if the user is allowed to create, rename, close, and reopen forum topics; for supergroups only"""
|
||||
can_manage_direct_messages: bool | None = None
|
||||
"""*Optional*. :code:`True`, if the administrator can manage direct messages of the channel and decline suggested posts; for channels only"""
|
||||
can_manage_tags: bool | None = None
|
||||
"""*Optional*. :code:`True`, if the administrator can edit the tags of regular members; for groups and supergroups only. If omitted defaults to the value of can_pin_messages."""
|
||||
custom_title: str | None = None
|
||||
"""*Optional*. Custom title for this user"""
|
||||
|
||||
|
|
@ -83,6 +85,7 @@ class ChatMemberAdministrator(ChatMember):
|
|||
can_pin_messages: bool | None = None,
|
||||
can_manage_topics: bool | None = None,
|
||||
can_manage_direct_messages: bool | None = None,
|
||||
can_manage_tags: bool | None = None,
|
||||
custom_title: str | None = None,
|
||||
**__pydantic_kwargs: Any,
|
||||
) -> None:
|
||||
|
|
@ -110,6 +113,7 @@ class ChatMemberAdministrator(ChatMember):
|
|||
can_pin_messages=can_pin_messages,
|
||||
can_manage_topics=can_manage_topics,
|
||||
can_manage_direct_messages=can_manage_direct_messages,
|
||||
can_manage_tags=can_manage_tags,
|
||||
custom_title=custom_title,
|
||||
**__pydantic_kwargs,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -21,6 +21,8 @@ class ChatMemberMember(ChatMember):
|
|||
"""The member's status in the chat, always 'member'"""
|
||||
user: User
|
||||
"""Information about the user"""
|
||||
tag: str | None = None
|
||||
"""*Optional*. Tag of the member"""
|
||||
until_date: DateTime | None = None
|
||||
"""*Optional*. Date when the user's subscription will expire; Unix time"""
|
||||
|
||||
|
|
@ -33,6 +35,7 @@ class ChatMemberMember(ChatMember):
|
|||
*,
|
||||
status: Literal[ChatMemberStatus.MEMBER] = ChatMemberStatus.MEMBER,
|
||||
user: User,
|
||||
tag: str | None = None,
|
||||
until_date: DateTime | None = None,
|
||||
**__pydantic_kwargs: Any,
|
||||
) -> None:
|
||||
|
|
@ -40,4 +43,6 @@ class ChatMemberMember(ChatMember):
|
|||
# This method was auto-generated via `butcher`
|
||||
# Is needed only for type checking and IDE support without any additional plugins
|
||||
|
||||
super().__init__(status=status, user=user, until_date=until_date, **__pydantic_kwargs)
|
||||
super().__init__(
|
||||
status=status, user=user, tag=tag, until_date=until_date, **__pydantic_kwargs
|
||||
)
|
||||
|
|
|
|||
|
|
@ -43,6 +43,8 @@ class ChatMemberRestricted(ChatMember):
|
|||
""":code:`True`, if the user is allowed to send animations, games, stickers and use inline bots"""
|
||||
can_add_web_page_previews: bool
|
||||
""":code:`True`, if the user is allowed to add web page previews to their messages"""
|
||||
can_edit_tag: bool
|
||||
""":code:`True`, if the user is allowed to edit their own tag"""
|
||||
can_change_info: bool
|
||||
""":code:`True`, if the user is allowed to change the chat title, photo and other settings"""
|
||||
can_invite_users: bool
|
||||
|
|
@ -53,6 +55,8 @@ class ChatMemberRestricted(ChatMember):
|
|||
""":code:`True`, if the user is allowed to create forum topics"""
|
||||
until_date: DateTime
|
||||
"""Date when restrictions will be lifted for this user; Unix time. If 0, then the user is restricted forever"""
|
||||
tag: str | None = None
|
||||
"""*Optional*. Tag of the member"""
|
||||
|
||||
if TYPE_CHECKING:
|
||||
# DO NOT EDIT MANUALLY!!!
|
||||
|
|
@ -74,11 +78,13 @@ class ChatMemberRestricted(ChatMember):
|
|||
can_send_polls: bool,
|
||||
can_send_other_messages: bool,
|
||||
can_add_web_page_previews: bool,
|
||||
can_edit_tag: bool,
|
||||
can_change_info: bool,
|
||||
can_invite_users: bool,
|
||||
can_pin_messages: bool,
|
||||
can_manage_topics: bool,
|
||||
until_date: DateTime,
|
||||
tag: str | None = None,
|
||||
**__pydantic_kwargs: Any,
|
||||
) -> None:
|
||||
# DO NOT EDIT MANUALLY!!!
|
||||
|
|
@ -99,10 +105,12 @@ class ChatMemberRestricted(ChatMember):
|
|||
can_send_polls=can_send_polls,
|
||||
can_send_other_messages=can_send_other_messages,
|
||||
can_add_web_page_previews=can_add_web_page_previews,
|
||||
can_edit_tag=can_edit_tag,
|
||||
can_change_info=can_change_info,
|
||||
can_invite_users=can_invite_users,
|
||||
can_pin_messages=can_pin_messages,
|
||||
can_manage_topics=can_manage_topics,
|
||||
until_date=until_date,
|
||||
tag=tag,
|
||||
**__pydantic_kwargs,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -32,6 +32,8 @@ class ChatPermissions(MutableTelegramObject):
|
|||
"""*Optional*. :code:`True`, if the user is allowed to send animations, games, stickers and use inline bots"""
|
||||
can_add_web_page_previews: bool | None = None
|
||||
"""*Optional*. :code:`True`, if the user is allowed to add web page previews to their messages"""
|
||||
can_edit_tag: bool | None = None
|
||||
"""*Optional*. :code:`True`, if the user is allowed to edit their own tag"""
|
||||
can_change_info: bool | None = None
|
||||
"""*Optional*. :code:`True`, if the user is allowed to change the chat title, photo and other settings. Ignored in public supergroups"""
|
||||
can_invite_users: bool | None = None
|
||||
|
|
@ -58,6 +60,7 @@ class ChatPermissions(MutableTelegramObject):
|
|||
can_send_polls: bool | None = None,
|
||||
can_send_other_messages: bool | None = None,
|
||||
can_add_web_page_previews: bool | None = None,
|
||||
can_edit_tag: bool | None = None,
|
||||
can_change_info: bool | None = None,
|
||||
can_invite_users: bool | None = None,
|
||||
can_pin_messages: bool | None = None,
|
||||
|
|
@ -79,6 +82,7 @@ class ChatPermissions(MutableTelegramObject):
|
|||
can_send_polls=can_send_polls,
|
||||
can_send_other_messages=can_send_other_messages,
|
||||
can_add_web_page_previews=can_add_web_page_previews,
|
||||
can_edit_tag=can_edit_tag,
|
||||
can_change_info=can_change_info,
|
||||
can_invite_users=can_invite_users,
|
||||
can_pin_messages=can_pin_messages,
|
||||
|
|
|
|||
|
|
@ -15,8 +15,6 @@ class GameHighScore(TelegramObject):
|
|||
|
||||
If you've got any questions, please check out our `https://core.telegram.org/bots/faq <https://core.telegram.org/bots/faq>`_ **Bot FAQ »**
|
||||
|
||||
-
|
||||
|
||||
Source: https://core.telegram.org/bots/api#gamehighscore
|
||||
"""
|
||||
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ class InlineQueryResultDocument(InlineQueryResult):
|
|||
description: str | None = None
|
||||
"""*Optional*. Short description of the result"""
|
||||
reply_markup: InlineKeyboardMarkup | None = None
|
||||
"""*Optional*. Inline keyboard attached to the message"""
|
||||
"""*Optional*. `Inline keyboard <https://core.telegram.org/bots/features#inline-keyboards>`_ attached to the message"""
|
||||
input_message_content: InputMessageContentUnion | None = None
|
||||
"""*Optional*. Content of the message to be sent instead of the file"""
|
||||
thumbnail_url: str | None = None
|
||||
|
|
|
|||
|
|
@ -157,6 +157,8 @@ class Message(MaybeInaccessibleMessage):
|
|||
"""*Optional*. If the sender of the message boosted the chat, the number of boosts added by the user"""
|
||||
sender_business_bot: User | None = None
|
||||
"""*Optional*. The bot that actually sent the message on behalf of the business account. Available only for outgoing messages sent on behalf of the connected business account."""
|
||||
sender_tag: str | None = None
|
||||
"""*Optional*. Tag or custom title of the sender of the message; for supergroups only"""
|
||||
business_connection_id: str | None = None
|
||||
"""*Optional*. Unique identifier of the business connection from which the message was received. If non-empty, the message belongs to a chat of the corresponding business account that is independent from any potential bot chat which might share the same identifier."""
|
||||
forward_origin: MessageOriginUnion | None = None
|
||||
|
|
@ -186,7 +188,7 @@ class Message(MaybeInaccessibleMessage):
|
|||
is_paid_post: bool | None = None
|
||||
"""*Optional*. :code:`True`, if the message is a paid post. Note that such posts must not be deleted for 24 hours to receive the payment and can't be edited."""
|
||||
media_group_id: str | None = None
|
||||
"""*Optional*. The unique identifier of a media message group this message belongs to"""
|
||||
"""*Optional*. The unique identifier inside this chat of a media message group this message belongs to"""
|
||||
author_signature: str | None = None
|
||||
"""*Optional*. Signature of the post author for messages in channels, or the custom title of an anonymous group administrator"""
|
||||
paid_star_count: int | None = None
|
||||
|
|
@ -348,7 +350,7 @@ class Message(MaybeInaccessibleMessage):
|
|||
web_app_data: WebAppData | None = None
|
||||
"""*Optional*. Service message: data sent by a Web App"""
|
||||
reply_markup: InlineKeyboardMarkup | None = None
|
||||
"""*Optional*. Inline keyboard attached to the message. :code:`login_url` buttons are represented as ordinary :code:`url` buttons."""
|
||||
"""*Optional*. `Inline keyboard <https://core.telegram.org/bots/features#inline-keyboards>`_ attached to the message. :code:`login_url` buttons are represented as ordinary :code:`url` buttons."""
|
||||
forward_date: DateTime | None = Field(None, json_schema_extra={"deprecated": True})
|
||||
"""*Optional*. For forwarded messages, date the original message was sent in Unix time
|
||||
|
||||
|
|
@ -401,6 +403,7 @@ class Message(MaybeInaccessibleMessage):
|
|||
sender_chat: Chat | None = None,
|
||||
sender_boost_count: int | None = None,
|
||||
sender_business_bot: User | None = None,
|
||||
sender_tag: str | None = None,
|
||||
business_connection_id: str | None = None,
|
||||
forward_origin: MessageOriginUnion | None = None,
|
||||
is_topic_message: bool | None = None,
|
||||
|
|
@ -520,6 +523,7 @@ class Message(MaybeInaccessibleMessage):
|
|||
sender_chat=sender_chat,
|
||||
sender_boost_count=sender_boost_count,
|
||||
sender_business_bot=sender_business_bot,
|
||||
sender_tag=sender_tag,
|
||||
business_connection_id=business_connection_id,
|
||||
forward_origin=forward_origin,
|
||||
is_topic_message=is_topic_message,
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ class MessageEntity(MutableTelegramObject):
|
|||
"""
|
||||
|
||||
type: str
|
||||
"""Type of the entity. Currently, can be 'mention' (:code:`@username`), 'hashtag' (:code:`#hashtag` or :code:`#hashtag@chatusername`), 'cashtag' (:code:`$USD` or :code:`$USD@chatusername`), 'bot_command' (:code:`/start@jobs_bot`), 'url' (:code:`https://telegram.org`), 'email' (:code:`do-not-reply@telegram.org`), 'phone_number' (:code:`+1-212-555-0123`), 'bold' (**bold text**), 'italic' (*italic text*), 'underline' (underlined text), 'strikethrough' (strikethrough text), 'spoiler' (spoiler message), 'blockquote' (block quotation), 'expandable_blockquote' (collapsed-by-default block quotation), 'code' (monowidth string), 'pre' (monowidth block), 'text_link' (for clickable text URLs), 'text_mention' (for users `without usernames <https://telegram.org/blog/edit#new-mentions>`_), 'custom_emoji' (for inline custom emoji stickers)"""
|
||||
"""Type of the entity. Currently, can be 'mention' (:code:`@username`), 'hashtag' (:code:`#hashtag` or :code:`#hashtag@chatusername`), 'cashtag' (:code:`$USD` or :code:`$USD@chatusername`), 'bot_command' (:code:`/start@jobs_bot`), 'url' (:code:`https://telegram.org`), 'email' (:code:`do-not-reply@telegram.org`), 'phone_number' (:code:`+1-212-555-0123`), 'bold' (**bold text**), 'italic' (*italic text*), 'underline' (underlined text), 'strikethrough' (strikethrough text), 'spoiler' (spoiler message), 'blockquote' (block quotation), 'expandable_blockquote' (collapsed-by-default block quotation), 'code' (monowidth string), 'pre' (monowidth block), 'text_link' (for clickable text URLs), 'text_mention' (for users `without usernames <https://telegram.org/blog/edit#new-mentions>`_), 'custom_emoji' (for inline custom emoji stickers), or 'date_time' (for formatted date and time)"""
|
||||
offset: int
|
||||
"""Offset in `UTF-16 code units <https://core.telegram.org/api/entities#entity-length>`_ to the start of the entity"""
|
||||
length: int
|
||||
|
|
@ -30,6 +30,10 @@ class MessageEntity(MutableTelegramObject):
|
|||
"""*Optional*. For 'pre' only, the programming language of the entity text"""
|
||||
custom_emoji_id: str | None = None
|
||||
"""*Optional*. For 'custom_emoji' only, unique identifier of the custom emoji. Use :class:`aiogram.methods.get_custom_emoji_stickers.GetCustomEmojiStickers` to get full information about the sticker"""
|
||||
unix_time: int | None = None
|
||||
"""*Optional*. For 'date_time' only, the Unix time associated with the entity"""
|
||||
date_time_format: str | None = None
|
||||
"""*Optional*. For 'date_time' only, the string that defines the formatting of the date and time. See `date-time entity formatting <https://core.telegram.org/bots/api#date-time-entity-formatting>`_ for more details."""
|
||||
|
||||
if TYPE_CHECKING:
|
||||
# DO NOT EDIT MANUALLY!!!
|
||||
|
|
@ -45,6 +49,8 @@ class MessageEntity(MutableTelegramObject):
|
|||
user: User | None = None,
|
||||
language: str | None = None,
|
||||
custom_emoji_id: str | None = None,
|
||||
unix_time: int | None = None,
|
||||
date_time_format: str | None = None,
|
||||
**__pydantic_kwargs: Any,
|
||||
) -> None:
|
||||
# DO NOT EDIT MANUALLY!!!
|
||||
|
|
@ -59,6 +65,8 @@ class MessageEntity(MutableTelegramObject):
|
|||
user=user,
|
||||
language=language,
|
||||
custom_emoji_id=custom_emoji_id,
|
||||
unix_time=unix_time,
|
||||
date_time_format=date_time_format,
|
||||
**__pydantic_kwargs,
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ from __future__ import annotations
|
|||
|
||||
import textwrap
|
||||
from collections.abc import Generator, Iterable, Iterator
|
||||
from datetime import datetime
|
||||
from typing import Any, ClassVar
|
||||
|
||||
from typing_extensions import Self
|
||||
|
|
@ -534,6 +535,26 @@ class ExpandableBlockQuote(Text):
|
|||
type = MessageEntityType.EXPANDABLE_BLOCKQUOTE
|
||||
|
||||
|
||||
class DateTime(Text):
|
||||
type = MessageEntityType.DATE_TIME
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
*body: NodeType,
|
||||
unix_time: int | datetime,
|
||||
date_time_format: str | None = None,
|
||||
**params: Any,
|
||||
) -> None:
|
||||
if isinstance(unix_time, datetime):
|
||||
unix_time = int(unix_time.timestamp())
|
||||
super().__init__(
|
||||
*body,
|
||||
unix_time=unix_time,
|
||||
date_time_format=date_time_format,
|
||||
**params,
|
||||
)
|
||||
|
||||
|
||||
NODE_TYPES: dict[str | None, type[Text]] = {
|
||||
Text.type: Text,
|
||||
HashTag.type: HashTag,
|
||||
|
|
@ -554,6 +575,7 @@ NODE_TYPES: dict[str | None, type[Text]] = {
|
|||
CustomEmoji.type: CustomEmoji,
|
||||
BlockQuote.type: BlockQuote,
|
||||
ExpandableBlockQuote.type: ExpandableBlockQuote,
|
||||
DateTime.type: DateTime,
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,9 +3,11 @@ from __future__ import annotations
|
|||
import html
|
||||
import re
|
||||
from abc import ABC, abstractmethod
|
||||
from datetime import date, datetime, time
|
||||
from typing import TYPE_CHECKING, cast
|
||||
|
||||
from aiogram.enums import MessageEntityType
|
||||
from aiogram.utils.link import create_tg_link
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from collections.abc import Generator
|
||||
|
|
@ -78,6 +80,12 @@ class TextDecoration(ABC):
|
|||
return self.link(value=text, link=cast(str, entity.url))
|
||||
if entity.type == MessageEntityType.CUSTOM_EMOJI:
|
||||
return self.custom_emoji(value=text, custom_emoji_id=cast(str, entity.custom_emoji_id))
|
||||
if entity.type == MessageEntityType.DATE_TIME:
|
||||
return self.date_time(
|
||||
value=text,
|
||||
unix_time=cast(int, entity.unix_time),
|
||||
date_time_format=entity.date_time_format,
|
||||
)
|
||||
|
||||
# This case is not possible because of `if` above, but if any new entity is added to
|
||||
# API it will be here too
|
||||
|
|
@ -180,54 +188,105 @@ class TextDecoration(ABC):
|
|||
def expandable_blockquote(self, value: str) -> str:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def date_time(
|
||||
self,
|
||||
value: str,
|
||||
unix_time: int | datetime,
|
||||
date_time_format: str | None = None,
|
||||
) -> str:
|
||||
pass
|
||||
|
||||
|
||||
class HtmlDecoration(TextDecoration):
|
||||
BOLD_TAG = "b"
|
||||
ITALIC_TAG = "i"
|
||||
UNDERLINE_TAG = "u"
|
||||
STRIKETHROUGH_TAG = "s"
|
||||
CODE_TAG = "code"
|
||||
PRE_TAG = "pre"
|
||||
LINK_TAG = "a"
|
||||
SPOILER_TAG = "tg-spoiler"
|
||||
EMOJI_TAG = "tg-emoji"
|
||||
DATE_TIME_TAG = "tg-time"
|
||||
BLOCKQUOTE_TAG = "blockquote"
|
||||
|
||||
def _tag(
|
||||
self,
|
||||
tag: str,
|
||||
content: str,
|
||||
*,
|
||||
attrs: dict[str, str] | None = None,
|
||||
flags: list[str] | None = None,
|
||||
) -> str:
|
||||
prepared_attrs: list[str] = []
|
||||
if attrs:
|
||||
prepared_attrs.extend(f'{k}="{v}"' for k, v in attrs.items())
|
||||
if flags:
|
||||
prepared_attrs.extend(f"{flag}" for flag in flags)
|
||||
|
||||
attrs_str = " ".join(prepared_attrs)
|
||||
if attrs_str:
|
||||
attrs_str = " " + attrs_str
|
||||
|
||||
return f"<{tag}{attrs_str}>{content}</{tag}>"
|
||||
|
||||
def link(self, value: str, link: str) -> str:
|
||||
return f'<a href="{link}">{value}</a>'
|
||||
return self._tag(self.LINK_TAG, value, attrs={"href": link})
|
||||
|
||||
def bold(self, value: str) -> str:
|
||||
return f"<{self.BOLD_TAG}>{value}</{self.BOLD_TAG}>"
|
||||
return self._tag(self.BOLD_TAG, value)
|
||||
|
||||
def italic(self, value: str) -> str:
|
||||
return f"<{self.ITALIC_TAG}>{value}</{self.ITALIC_TAG}>"
|
||||
return self._tag(self.ITALIC_TAG, value)
|
||||
|
||||
def code(self, value: str) -> str:
|
||||
return f"<code>{value}</code>"
|
||||
return self._tag(self.CODE_TAG, value)
|
||||
|
||||
def pre(self, value: str) -> str:
|
||||
return f"<pre>{value}</pre>"
|
||||
return self._tag(self.PRE_TAG, value)
|
||||
|
||||
def pre_language(self, value: str, language: str) -> str:
|
||||
return f'<pre><code class="language-{language}">{value}</code></pre>'
|
||||
return self._tag(
|
||||
self.PRE_TAG,
|
||||
self._tag(self.CODE_TAG, value, attrs={"language": f"language-{language}"}),
|
||||
)
|
||||
|
||||
def underline(self, value: str) -> str:
|
||||
return f"<{self.UNDERLINE_TAG}>{value}</{self.UNDERLINE_TAG}>"
|
||||
return self._tag(self.UNDERLINE_TAG, value)
|
||||
|
||||
def strikethrough(self, value: str) -> str:
|
||||
return f"<{self.STRIKETHROUGH_TAG}>{value}</{self.STRIKETHROUGH_TAG}>"
|
||||
return self._tag(self.STRIKETHROUGH_TAG, value)
|
||||
|
||||
def spoiler(self, value: str) -> str:
|
||||
return f"<{self.SPOILER_TAG}>{value}</{self.SPOILER_TAG}>"
|
||||
return self._tag(self.SPOILER_TAG, value)
|
||||
|
||||
def quote(self, value: str) -> str:
|
||||
return html.escape(value, quote=False)
|
||||
|
||||
def custom_emoji(self, value: str, custom_emoji_id: str) -> str:
|
||||
return f'<{self.EMOJI_TAG} emoji-id="{custom_emoji_id}">{value}</{self.EMOJI_TAG}>'
|
||||
return self._tag(self.EMOJI_TAG, value, attrs={"emoji_id": custom_emoji_id})
|
||||
|
||||
def blockquote(self, value: str) -> str:
|
||||
return f"<{self.BLOCKQUOTE_TAG}>{value}</{self.BLOCKQUOTE_TAG}>"
|
||||
return self._tag(self.BLOCKQUOTE_TAG, value)
|
||||
|
||||
def expandable_blockquote(self, value: str) -> str:
|
||||
return f"<{self.BLOCKQUOTE_TAG} expandable>{value}</{self.BLOCKQUOTE_TAG}>"
|
||||
return self._tag(self.BLOCKQUOTE_TAG, value, flags=["expandable"])
|
||||
|
||||
def date_time(
|
||||
self,
|
||||
value: str,
|
||||
unix_time: int | datetime,
|
||||
date_time_format: str | None = None,
|
||||
) -> str:
|
||||
if isinstance(unix_time, datetime):
|
||||
unix_time = int(unix_time.timestamp())
|
||||
|
||||
args = {"unix": str(unix_time)}
|
||||
if date_time_format:
|
||||
args["format"] = date_time_format
|
||||
|
||||
return self._tag(self.DATE_TIME_TAG, value, attrs=args)
|
||||
|
||||
|
||||
class MarkdownDecoration(TextDecoration):
|
||||
|
|
@ -264,7 +323,8 @@ class MarkdownDecoration(TextDecoration):
|
|||
return re.sub(pattern=self.MARKDOWN_QUOTE_PATTERN, repl=r"\\\1", string=value)
|
||||
|
||||
def custom_emoji(self, value: str, custom_emoji_id: str) -> str:
|
||||
return f"!{self.link(value=value, link=f'tg://emoji?id={custom_emoji_id}')}"
|
||||
link = create_tg_link("emoji", emoji_id=custom_emoji_id)
|
||||
return f"!{self.link(value=value, link=link)}"
|
||||
|
||||
def blockquote(self, value: str) -> str:
|
||||
return "\n".join(f">{line}" for line in value.splitlines())
|
||||
|
|
@ -272,6 +332,22 @@ class MarkdownDecoration(TextDecoration):
|
|||
def expandable_blockquote(self, value: str) -> str:
|
||||
return "\n".join(f">{line}" for line in value.splitlines()) + "||"
|
||||
|
||||
def date_time(
|
||||
self,
|
||||
value: str,
|
||||
unix_time: int | datetime,
|
||||
date_time_format: str | None = None,
|
||||
) -> str:
|
||||
if isinstance(unix_time, datetime):
|
||||
unix_time = int(unix_time.timestamp())
|
||||
|
||||
link_params = {"unix": str(unix_time)}
|
||||
if date_time_format:
|
||||
link_params["format"] = date_time_format
|
||||
link = create_tg_link("time", **link_params)
|
||||
|
||||
return f"!{self.link(value, link=link)}"
|
||||
|
||||
|
||||
html_decoration = HtmlDecoration()
|
||||
markdown_decoration = MarkdownDecoration()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue