Dev 3.x api 4.8 (#317)

* AIOG-T-20 Bot API 4.8

* AIOG-T-20 Update aliases

* AIOG-T-20 Add parse mode passing in sendPoll method

* AIOG-T-20 Small changes in docs

* AIOG-T-20 Revert overriding remove keyboard default value and add tests

* AIOG-T-20 Bot API 4.8
This commit is contained in:
Alex Root Junior 2020-05-02 23:01:32 +03:00 committed by GitHub
parent 15bcc0ba9f
commit 6be0b36305
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
104 changed files with 312 additions and 175 deletions

View file

@ -1,3 +1,4 @@
from ._meta import VERSION
from .api import methods, types
from .api.client import session
from .api.client.bot import Bot
@ -28,5 +29,5 @@ __all__ = (
"handler",
)
__version__ = "3.0.0a3"
__api_version__ = "4.7"
__version__ = VERSION
__api_version__ = "4.8"

View file

@ -224,7 +224,7 @@ class Bot(ContextInstanceMixin["Bot"]):
with an offset higher than its update_id. The negative offset can be
specified to retrieve updates starting from -offset update from the end of
the updates queue. All previous updates will forgotten.
:param limit: Limits the number of updates to be retrieved. Values between 1100 are
:param limit: Limits the number of updates to be retrieved. Values between 1-100 are
accepted. Defaults to 100.
:param timeout: Timeout in seconds for long polling. Defaults to 0, i.e. usual short
polling. Should be positive, short polling should be used for testing
@ -355,8 +355,8 @@ class Bot(ContextInstanceMixin["Bot"]):
:param chat_id: Unique identifier for the target chat or username of the target channel
(in the format @channelusername)
:param text: Text of the message to be sent, 1-4096 characters after entities parsing
:param parse_mode: Send Markdown or HTML, if you want Telegram apps to show bold, italic,
fixed-width text or inline URLs in your bot's message.
:param parse_mode: Mode for parsing entities in the message text. See formatting options
for more details.
:param disable_web_page_preview: Disables link previews for links in this message
:param disable_notification: Sends the message silently. Users will receive a notification
with no sound.
@ -431,8 +431,8 @@ class Bot(ContextInstanceMixin["Bot"]):
multipart/form-data.
:param caption: Photo caption (may also be used when resending photos by file_id), 0-1024
characters after entities parsing
:param parse_mode: Send Markdown or HTML, if you want Telegram apps to show bold, italic,
fixed-width text or inline URLs in the media caption.
:param parse_mode: Mode for parsing entities in the photo caption. See formatting options
for more details.
:param disable_notification: Sends the message silently. Users will receive a notification
with no sound.
:param reply_to_message_id: If the message is a reply, ID of the original message
@ -484,8 +484,8 @@ class Bot(ContextInstanceMixin["Bot"]):
for Telegram to get an audio file from the Internet, or upload a new one
using multipart/form-data.
:param caption: Audio caption, 0-1024 characters after entities parsing
:param parse_mode: Send Markdown or HTML, if you want Telegram apps to show bold, italic,
fixed-width text or inline URLs in the media caption.
:param parse_mode: Mode for parsing entities in the audio caption. See formatting options
for more details.
:param duration: Duration of the audio in seconds
:param performer: Performer
:param title: Track name
@ -554,8 +554,8 @@ class Bot(ContextInstanceMixin["Bot"]):
multipart/form-data under <file_attach_name>.
:param caption: Document caption (may also be used when resending documents by file_id),
0-1024 characters after entities parsing
:param parse_mode: Send Markdown or HTML, if you want Telegram apps to show bold, italic,
fixed-width text or inline URLs in the media caption.
:param parse_mode: Mode for parsing entities in the document caption. See formatting
options for more details.
:param disable_notification: Sends the message silently. Users will receive a notification
with no sound.
:param reply_to_message_id: If the message is a reply, ID of the original message
@ -618,8 +618,8 @@ class Bot(ContextInstanceMixin["Bot"]):
multipart/form-data under <file_attach_name>.
:param caption: Video caption (may also be used when resending videos by file_id), 0-1024
characters after entities parsing
:param parse_mode: Send Markdown or HTML, if you want Telegram apps to show bold, italic,
fixed-width text or inline URLs in the media caption.
:param parse_mode: Mode for parsing entities in the video caption. See formatting options
for more details.
:param supports_streaming: Pass True, if the uploaded video is suitable for streaming
:param disable_notification: Sends the message silently. Users will receive a notification
with no sound.
@ -686,8 +686,8 @@ class Bot(ContextInstanceMixin["Bot"]):
multipart/form-data under <file_attach_name>.
:param caption: Animation caption (may also be used when resending animation by file_id),
0-1024 characters after entities parsing
:param parse_mode: Send Markdown or HTML, if you want Telegram apps to show bold, italic,
fixed-width text or inline URLs in the media caption.
:param parse_mode: Mode for parsing entities in the animation caption. See formatting
options for more details.
:param disable_notification: Sends the message silently. Users will receive a notification
with no sound.
:param reply_to_message_id: If the message is a reply, ID of the original message
@ -740,8 +740,8 @@ class Bot(ContextInstanceMixin["Bot"]):
Telegram to get a file from the Internet, or upload a new one using
multipart/form-data.
:param caption: Voice message caption, 0-1024 characters after entities parsing
:param parse_mode: Send Markdown or HTML, if you want Telegram apps to show bold, italic,
fixed-width text or inline URLs in the media caption.
:param parse_mode: Mode for parsing entities in the voice message caption. See formatting
options for more details.
:param duration: Duration of the voice message in seconds
:param disable_notification: Sends the message silently. Users will receive a notification
with no sound.
@ -833,7 +833,7 @@ class Bot(ContextInstanceMixin["Bot"]):
:param chat_id: Unique identifier for the target chat or username of the target channel
(in the format @channelusername)
:param media: A JSON-serialized array describing photos and videos to be sent, must
include 210 items
include 2-10 items
:param disable_notification: Sends the messages silently. Users will receive a
notification with no sound.
:param reply_to_message_id: If the messages are a reply, ID of the original message
@ -1068,6 +1068,10 @@ class Bot(ContextInstanceMixin["Bot"]):
type: Optional[str] = None,
allows_multiple_answers: Optional[bool] = None,
correct_option_id: Optional[int] = None,
explanation: Optional[str] = None,
explanation_parse_mode: Optional[str] = None,
open_period: Optional[int] = None,
close_date: Optional[Union[datetime.datetime, datetime.timedelta, int]] = None,
is_closed: Optional[bool] = None,
disable_notification: Optional[bool] = None,
reply_to_message_id: Optional[int] = None,
@ -1091,6 +1095,16 @@ class Bot(ContextInstanceMixin["Bot"]):
polls in quiz mode, defaults to False
:param correct_option_id: 0-based identifier of the correct answer option, required for
polls in quiz mode
:param explanation: Text that is shown when a user chooses an incorrect answer or taps on
the lamp icon in a quiz-style poll, 0-200 characters with at most 2
line feeds after entities parsing
:param explanation_parse_mode: Mode for parsing entities in the explanation. See
formatting options for more details.
:param open_period: Amount of time in seconds the poll will be active after creation,
5-600. Can't be used together with close_date.
:param close_date: Point in time (Unix timestamp) when the poll will be automatically
closed. Must be at least 5 and no more than 600 seconds in the future.
Can't be used together with open_period.
:param is_closed: Pass True, if the poll needs to be immediately closed. This can be
useful for poll preview.
:param disable_notification: Sends the message silently. Users will receive a notification
@ -1109,6 +1123,10 @@ class Bot(ContextInstanceMixin["Bot"]):
type=type,
allows_multiple_answers=allows_multiple_answers,
correct_option_id=correct_option_id,
explanation=explanation,
explanation_parse_mode=explanation_parse_mode,
open_period=open_period,
close_date=close_date,
is_closed=is_closed,
disable_notification=disable_notification,
reply_to_message_id=reply_to_message_id,
@ -1119,6 +1137,7 @@ class Bot(ContextInstanceMixin["Bot"]):
async def send_dice(
self,
chat_id: Union[int, str],
emoji: Optional[str] = None,
disable_notification: Optional[bool] = None,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[
@ -1134,6 +1153,8 @@ class Bot(ContextInstanceMixin["Bot"]):
:param chat_id: Unique identifier for the target chat or username of the target channel
(in the format @channelusername)
:param emoji: Emoji on which the dice throw animation is based. Currently, must be one of
'' or ''. Defauts to ''
:param disable_notification: Sends the message silently. Users will receive a notification
with no sound.
:param reply_to_message_id: If the message is a reply, ID of the original message
@ -1144,6 +1165,7 @@ class Bot(ContextInstanceMixin["Bot"]):
"""
call = SendDice(
chat_id=chat_id,
emoji=emoji,
disable_notification=disable_notification,
reply_to_message_id=reply_to_message_id,
reply_markup=reply_markup,
@ -1188,7 +1210,7 @@ class Bot(ContextInstanceMixin["Bot"]):
:param user_id: Unique identifier of the target user
:param offset: Sequential number of the first photo to be returned. By default, all photos
are returned.
:param limit: Limits the number of photos to be retrieved. Values between 1100 are
:param limit: Limits the number of photos to be retrieved. Values between 1-100 are
accepted. Defaults to 100.
:return: Returns a UserProfilePhotos object.
"""
@ -1218,7 +1240,7 @@ class Bot(ContextInstanceMixin["Bot"]):
self,
chat_id: Union[int, str],
user_id: int,
until_date: Optional[Union[int, datetime.datetime, datetime.timedelta]] = None,
until_date: Optional[Union[datetime.datetime, datetime.timedelta, int]] = None,
) -> bool:
"""
Use this method to kick a user from a group, a supergroup or a channel. In the case of
@ -1262,7 +1284,7 @@ class Bot(ContextInstanceMixin["Bot"]):
chat_id: Union[int, str],
user_id: int,
permissions: ChatPermissions,
until_date: Optional[Union[int, datetime.datetime, datetime.timedelta]] = None,
until_date: Optional[Union[datetime.datetime, datetime.timedelta, int]] = None,
) -> bool:
"""
Use this method to restrict a user in a supergroup. The bot must be an administrator in
@ -1322,7 +1344,7 @@ class Bot(ContextInstanceMixin["Bot"]):
:param can_pin_messages: Pass True, if the administrator can pin messages, supergroups
only
:param can_promote_members: Pass True, if the administrator can add new administrators
with a subset of his own privileges or demote administrators
with a subset of their own privileges or demote administrators
that he has promoted, directly or indirectly (promoted by
administrators that were appointed by him)
:return: Returns True on success.
@ -1387,7 +1409,7 @@ class Bot(ContextInstanceMixin["Bot"]):
appropriate admin rights. Returns the new invite link as String on success.
Note: Each administrator in a chat generates their own invite links. Bots can't use invite
links generated by other administrators. If you want your bot to work with invite links,
it will need to generate its own link using exportChatInviteLink after this the link
it will need to generate its own link using exportChatInviteLink after this the link
will become available to the bot via the getChat method. If your bot needs to generate a
new invite link replacing its previous one, use exportChatInviteLink again.
@ -1644,7 +1666,7 @@ class Bot(ContextInstanceMixin["Bot"]):
:param show_alert: If true, an alert will be shown by the client instead of a notification
at the top of the chat screen. Defaults to false.
:param url: URL that will be opened by the user's client. If you have created a Game and
accepted the conditions via @Botfather, specify the URL that opens your game
accepted the conditions via @Botfather, specify the URL that opens your game
note that this will only work if the query comes from a callback_game button.
:param cache_time: The maximum amount of time in seconds that the result of the callback
query may be cached client-side. Telegram apps will support caching
@ -1714,8 +1736,8 @@ class Bot(ContextInstanceMixin["Bot"]):
message to edit
:param inline_message_id: Required if chat_id and message_id are not specified. Identifier
of the inline message
:param parse_mode: Send Markdown or HTML, if you want Telegram apps to show bold, italic,
fixed-width text or inline URLs in your bot's message.
:param parse_mode: Mode for parsing entities in the message text. See formatting options
for more details.
:param disable_web_page_preview: Disables link previews for links in this message
:param reply_markup: A JSON-serialized object for an inline keyboard.
:return: On success, if edited message is sent by the bot, the edited Message is returned,
@ -1755,8 +1777,8 @@ class Bot(ContextInstanceMixin["Bot"]):
:param inline_message_id: Required if chat_id and message_id are not specified. Identifier
of the inline message
:param caption: New caption of the message, 0-1024 characters after entities parsing
:param parse_mode: Send Markdown or HTML, if you want Telegram apps to show bold, italic,
fixed-width text or inline URLs in the media caption.
:param parse_mode: Mode for parsing entities in the message caption. See formatting
options for more details.
:param reply_markup: A JSON-serialized object for an inline keyboard.
:return: On success, if edited message is sent by the bot, the edited Message is returned,
otherwise True is returned.
@ -1953,7 +1975,7 @@ class Bot(ContextInstanceMixin["Bot"]):
Source: https://core.telegram.org/bots/api#uploadstickerfile
:param user_id: User identifier of sticker file owner
:param png_sticker: Png image with the sticker, must be up to 512 kilobytes in size,
:param png_sticker: PNG image with the sticker, must be up to 512 kilobytes in size,
dimensions must not exceed 512px, and either width or height must be
exactly 512px.
:return: Returns the uploaded File on success.
@ -2016,8 +2038,8 @@ class Bot(ContextInstanceMixin["Bot"]):
self,
user_id: int,
name: str,
png_sticker: Union[InputFile, str],
emojis: str,
png_sticker: Optional[Union[InputFile, str]] = None,
tgs_sticker: Optional[InputFile] = None,
mask_position: Optional[MaskPosition] = None,
) -> bool:
@ -2031,13 +2053,13 @@ class Bot(ContextInstanceMixin["Bot"]):
:param user_id: User identifier of sticker set owner
:param name: Sticker set name
:param emojis: One or more emoji corresponding to the sticker
:param png_sticker: PNG image with the sticker, must be up to 512 kilobytes in size,
dimensions must not exceed 512px, and either width or height must be
exactly 512px. Pass a file_id as a String to send a file that already
exists on the Telegram servers, pass an HTTP URL as a String for
Telegram to get a file from the Internet, or upload a new one using
multipart/form-data.
:param emojis: One or more emoji corresponding to the sticker
:param tgs_sticker: TGS animation with the sticker, uploaded using multipart/form-data.
See https://core.telegram.org/animated_stickers#technical-requirements
for technical requirements
@ -2048,8 +2070,8 @@ class Bot(ContextInstanceMixin["Bot"]):
call = AddStickerToSet(
user_id=user_id,
name=name,
png_sticker=png_sticker,
emojis=emojis,
png_sticker=png_sticker,
tgs_sticker=tgs_sticker,
mask_position=mask_position,
)
@ -2443,9 +2465,9 @@ class Bot(ContextInstanceMixin["Bot"]):
) -> List[GameHighScore]:
"""
Use this method to get data for high score tables. Will return the score of the specified
user and several of his neighbors in a game. On success, returns an Array of GameHighScore
objects.
This method will currently return scores for the target user, plus two of his closest
user and several of their neighbors in a game. On success, returns an Array of
GameHighScore objects.
This method will currently return scores for the target user, plus two of their closest
neighbors on each side. Will also return the top three users if the user and his neighbors
are not among them. Please note that this behavior is subject to change.
@ -2458,11 +2480,11 @@ class Bot(ContextInstanceMixin["Bot"]):
message
:param inline_message_id: Required if chat_id and message_id are not specified. Identifier
of the inline message
:return: Will return the score of the specified user and several of his neighbors in a
:return: Will return the score of the specified user and several of their neighbors in a
game. On success, returns an Array of GameHighScore objects. This method will
currently return scores for the target user, plus two of his closest neighbors on
each side. Will also return the top three users if the user and his neighbors are
not among them.
currently return scores for the target user, plus two of their closest neighbors
on each side. Will also return the top three users if the user and his neighbors
are not among them.
"""
call = GetGameHighScores(
user_id=user_id,

View file

@ -20,13 +20,13 @@ class AddStickerToSet(TelegramMethod[bool]):
"""User identifier of sticker set owner"""
name: str
"""Sticker set name"""
png_sticker: Union[InputFile, str]
emojis: str
"""One or more emoji corresponding to the sticker"""
png_sticker: Optional[Union[InputFile, str]] = None
"""PNG image with the sticker, must be up to 512 kilobytes in size, dimensions must not exceed
512px, and either width or height must be exactly 512px. Pass a file_id as a String to send
a file that already exists on the Telegram servers, pass an HTTP URL as a String for
Telegram to get a file from the Internet, or upload a new one using multipart/form-data."""
emojis: str
"""One or more emoji corresponding to the sticker"""
tgs_sticker: Optional[InputFile] = None
"""TGS animation with the sticker, uploaded using multipart/form-data. See
https://core.telegram.org/animated_stickers#technical-requirements for technical

View file

@ -27,7 +27,7 @@ class AnswerCallbackQuery(TelegramMethod[bool]):
chat screen. Defaults to false."""
url: Optional[str] = None
"""URL that will be opened by the user's client. If you have created a Game and accepted the
conditions via @Botfather, specify the URL that opens your game note that this will only
conditions via @Botfather, specify the URL that opens your game note that this will only
work if the query comes from a callback_game button."""
cache_time: Optional[int] = None
"""The maximum amount of time in seconds that the result of the callback query may be cached

View file

@ -105,19 +105,19 @@ def prepare_media_file(data: Dict[str, Any], files: Dict[str, InputFile]) -> Non
data["media"]["media"] = f"attach://{tag}"
def prepare_parse_mode(root: Any) -> None:
def prepare_parse_mode(root: Any, parse_mode_property: str = "parse_mode") -> None:
if isinstance(root, list):
for item in root:
prepare_parse_mode(item)
prepare_parse_mode(item, parse_mode_property=parse_mode_property)
return
if root.get("parse_mode"):
if root.get(parse_mode_property):
return
from ..client.bot import Bot
bot = Bot.get_current(no_error=True)
if bot and bot.parse_mode:
root["parse_mode"] = bot.parse_mode
root[parse_mode_property] = bot.parse_mode
return
return

View file

@ -24,8 +24,7 @@ class EditMessageCaption(TelegramMethod[Union[Message, bool]]):
caption: Optional[str] = None
"""New caption of the message, 0-1024 characters after entities parsing"""
parse_mode: Optional[str] = None
"""Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or
inline URLs in the media caption."""
"""Mode for parsing entities in the message caption. See formatting options for more details."""
reply_markup: Optional[InlineKeyboardMarkup] = None
"""A JSON-serialized object for an inline keyboard."""

View file

@ -24,8 +24,7 @@ class EditMessageText(TelegramMethod[Union[Message, bool]]):
inline_message_id: Optional[str] = None
"""Required if chat_id and message_id are not specified. Identifier of the inline message"""
parse_mode: Optional[str] = None
"""Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or
inline URLs in your bot's message."""
"""Mode for parsing entities in the message text. See formatting options for more details."""
disable_web_page_preview: Optional[bool] = None
"""Disables link previews for links in this message"""
reply_markup: Optional[InlineKeyboardMarkup] = None

View file

@ -10,7 +10,7 @@ class ExportChatInviteLink(TelegramMethod[str]):
appropriate admin rights. Returns the new invite link as String on success.
Note: Each administrator in a chat generates their own invite links. Bots can't use invite
links generated by other administrators. If you want your bot to work with invite links, it
will need to generate its own link using exportChatInviteLink after this the link will
will need to generate its own link using exportChatInviteLink after this the link will
become available to the bot via the getChat method. If your bot needs to generate a new invite
link replacing its previous one, use exportChatInviteLink again.

View file

@ -7,8 +7,9 @@ from .base import Request, TelegramMethod
class GetGameHighScores(TelegramMethod[List[GameHighScore]]):
"""
Use this method to get data for high score tables. Will return the score of the specified user
and several of his neighbors in a game. On success, returns an Array of GameHighScore objects.
This method will currently return scores for the target user, plus two of his closest
and several of their neighbors in a game. On success, returns an Array of GameHighScore
objects.
This method will currently return scores for the target user, plus two of their closest
neighbors on each side. Will also return the top three users if the user and his neighbors are
not among them. Please note that this behavior is subject to change.

View file

@ -25,7 +25,7 @@ class GetUpdates(TelegramMethod[List[Update]]):
specified to retrieve updates starting from -offset update from the end of the updates
queue. All previous updates will forgotten."""
limit: Optional[int] = None
"""Limits the number of updates to be retrieved. Values between 1100 are accepted. Defaults
"""Limits the number of updates to be retrieved. Values between 1-100 are accepted. Defaults
to 100."""
timeout: Optional[int] = None
"""Timeout in seconds for long polling. Defaults to 0, i.e. usual short polling. Should be

View file

@ -19,7 +19,7 @@ class GetUserProfilePhotos(TelegramMethod[UserProfilePhotos]):
offset: Optional[int] = None
"""Sequential number of the first photo to be returned. By default, all photos are returned."""
limit: Optional[int] = None
"""Limits the number of photos to be retrieved. Values between 1100 are accepted. Defaults to
"""Limits the number of photos to be retrieved. Values between 1-100 are accepted. Defaults to
100."""
def build_request(self) -> Request:

View file

@ -21,7 +21,7 @@ class KickChatMember(TelegramMethod[bool]):
the format @channelusername)"""
user_id: int
"""Unique identifier of the target user"""
until_date: Optional[Union[int, datetime.datetime, datetime.timedelta]] = None
until_date: Optional[Union[datetime.datetime, datetime.timedelta, int]] = None
"""Date when the user will be unbanned, unix time. If user is banned for more than 366 days or
less than 30 seconds from the current time they are considered to be banned forever"""

View file

@ -35,7 +35,7 @@ class PromoteChatMember(TelegramMethod[bool]):
can_pin_messages: Optional[bool] = None
"""Pass True, if the administrator can pin messages, supergroups only"""
can_promote_members: Optional[bool] = None
"""Pass True, if the administrator can add new administrators with a subset of his own
"""Pass True, if the administrator can add new administrators with a subset of their own
privileges or demote administrators that he has promoted, directly or indirectly (promoted
by administrators that were appointed by him)"""

View file

@ -23,7 +23,7 @@ class RestrictChatMember(TelegramMethod[bool]):
"""Unique identifier of the target user"""
permissions: ChatPermissions
"""New user permissions"""
until_date: Optional[Union[int, datetime.datetime, datetime.timedelta]] = None
until_date: Optional[Union[datetime.datetime, datetime.timedelta, int]] = None
"""Date when restrictions will be lifted for the user, unix time. If user is restricted for
more than 366 days or less than 30 seconds from the current time, they are considered to be
restricted forever"""

View file

@ -46,8 +46,8 @@ class SendAnimation(TelegramMethod[Message]):
"""Animation caption (may also be used when resending animation by file_id), 0-1024 characters
after entities parsing"""
parse_mode: Optional[str] = None
"""Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or
inline URLs in the media caption."""
"""Mode for parsing entities in the animation caption. See formatting options for more
details."""
disable_notification: Optional[bool] = None
"""Sends the message silently. Users will receive a notification with no sound."""
reply_to_message_id: Optional[int] = None

View file

@ -34,8 +34,7 @@ class SendAudio(TelegramMethod[Message]):
caption: Optional[str] = None
"""Audio caption, 0-1024 characters after entities parsing"""
parse_mode: Optional[str] = None
"""Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or
inline URLs in the media caption."""
"""Mode for parsing entities in the audio caption. See formatting options for more details."""
duration: Optional[int] = None
"""Duration of the audio in seconds"""
performer: Optional[str] = None

View file

@ -24,6 +24,9 @@ class SendDice(TelegramMethod[Message]):
chat_id: Union[int, str]
"""Unique identifier for the target chat or username of the target channel (in the format
@channelusername)"""
emoji: Optional[str] = None
"""Emoji on which the dice throw animation is based. Currently, must be one of '' or ''.
Defauts to ''"""
disable_notification: Optional[bool] = None
"""Sends the message silently. Users will receive a notification with no sound."""
reply_to_message_id: Optional[int] = None

View file

@ -40,8 +40,7 @@ class SendDocument(TelegramMethod[Message]):
"""Document caption (may also be used when resending documents by file_id), 0-1024 characters
after entities parsing"""
parse_mode: Optional[str] = None
"""Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or
inline URLs in the media caption."""
"""Mode for parsing entities in the document caption. See formatting options for more details."""
disable_notification: Optional[bool] = None
"""Sends the message silently. Users will receive a notification with no sound."""
reply_to_message_id: Optional[int] = None

View file

@ -18,7 +18,7 @@ class SendMediaGroup(TelegramMethod[List[Message]]):
"""Unique identifier for the target chat or username of the target channel (in the format
@channelusername)"""
media: List[Union[InputMediaPhoto, InputMediaVideo]]
"""A JSON-serialized array describing photos and videos to be sent, must include 210 items"""
"""A JSON-serialized array describing photos and videos to be sent, must include 2-10 items"""
disable_notification: Optional[bool] = None
"""Sends the messages silently. Users will receive a notification with no sound."""
reply_to_message_id: Optional[int] = None

View file

@ -25,8 +25,7 @@ class SendMessage(TelegramMethod[Message]):
text: str
"""Text of the message to be sent, 1-4096 characters after entities parsing"""
parse_mode: Optional[str] = None
"""Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or
inline URLs in your bot's message."""
"""Mode for parsing entities in the message text. See formatting options for more details."""
disable_web_page_preview: Optional[bool] = None
"""Disables link previews for links in this message"""
disable_notification: Optional[bool] = None

View file

@ -31,8 +31,7 @@ class SendPhoto(TelegramMethod[Message]):
"""Photo caption (may also be used when resending photos by file_id), 0-1024 characters after
entities parsing"""
parse_mode: Optional[str] = None
"""Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or
inline URLs in the media caption."""
"""Mode for parsing entities in the photo caption. See formatting options for more details."""
disable_notification: Optional[bool] = None
"""Sends the message silently. Users will receive a notification with no sound."""
reply_to_message_id: Optional[int] = None

View file

@ -1,3 +1,4 @@
import datetime
from typing import Any, Dict, List, Optional, Union
from ..types import (
@ -7,7 +8,7 @@ from ..types import (
ReplyKeyboardMarkup,
ReplyKeyboardRemove,
)
from .base import Request, TelegramMethod
from .base import Request, TelegramMethod, prepare_parse_mode
class SendPoll(TelegramMethod[Message]):
@ -35,6 +36,17 @@ class SendPoll(TelegramMethod[Message]):
False"""
correct_option_id: Optional[int] = None
"""0-based identifier of the correct answer option, required for polls in quiz mode"""
explanation: Optional[str] = None
"""Text that is shown when a user chooses an incorrect answer or taps on the lamp icon in a
quiz-style poll, 0-200 characters with at most 2 line feeds after entities parsing"""
explanation_parse_mode: Optional[str] = None
"""Mode for parsing entities in the explanation. See formatting options for more details."""
open_period: Optional[int] = None
"""Amount of time in seconds the poll will be active after creation, 5-600. Can't be used
together with close_date."""
close_date: Optional[Union[datetime.datetime, datetime.timedelta, int]] = None
"""Point in time (Unix timestamp) when the poll will be automatically closed. Must be at least
5 and no more than 600 seconds in the future. Can't be used together with open_period."""
is_closed: Optional[bool] = None
"""Pass True, if the poll needs to be immediately closed. This can be useful for poll preview."""
disable_notification: Optional[bool] = None
@ -49,5 +61,6 @@ class SendPoll(TelegramMethod[Message]):
def build_request(self) -> Request:
data: Dict[str, Any] = self.dict()
prepare_parse_mode(data, parse_mode_property="explanation_parse_mode")
return Request(method="sendPoll", data=data)

View file

@ -46,8 +46,7 @@ class SendVideo(TelegramMethod[Message]):
"""Video caption (may also be used when resending videos by file_id), 0-1024 characters after
entities parsing"""
parse_mode: Optional[str] = None
"""Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or
inline URLs in the media caption."""
"""Mode for parsing entities in the video caption. See formatting options for more details."""
supports_streaming: Optional[bool] = None
"""Pass True, if the uploaded video is suitable for streaming"""
disable_notification: Optional[bool] = None

View file

@ -34,8 +34,8 @@ class SendVoice(TelegramMethod[Message]):
caption: Optional[str] = None
"""Voice message caption, 0-1024 characters after entities parsing"""
parse_mode: Optional[str] = None
"""Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or
inline URLs in the media caption."""
"""Mode for parsing entities in the voice message caption. See formatting options for more
details."""
duration: Optional[int] = None
"""Duration of the voice message in seconds"""
disable_notification: Optional[bool] = None

View file

@ -17,7 +17,7 @@ class UploadStickerFile(TelegramMethod[File]):
user_id: int
"""User identifier of sticker file owner"""
png_sticker: InputFile
"""Png image with the sticker, must be up to 512 kilobytes in size, dimensions must not exceed
"""PNG image with the sticker, must be up to 512 kilobytes in size, dimensions must not exceed
512px, and either width or height must be exactly 512px."""
def build_request(self) -> Request:

View file

@ -10,7 +10,7 @@ from .chat_permissions import ChatPermissions
from .chat_photo import ChatPhoto
from .chosen_inline_result import ChosenInlineResult
from .contact import Contact
from .dice import Dice
from .dice import Dice, DiceEmoji
from .document import Document
from .encrypted_credentials import EncryptedCredentials
from .encrypted_passport_element import EncryptedPassportElement
@ -124,6 +124,7 @@ __all__ = (
"PollAnswer",
"Poll",
"Dice",
"DiceEmoji",
"UserProfilePhotos",
"File",
"ReplyKeyboardMarkup",

View file

@ -23,7 +23,7 @@ class ChatMember(TelegramObject):
'left' or 'kicked'"""
custom_title: Optional[str] = None
"""Owner and administrators only. Custom title for this user"""
until_date: Optional[Union[int, datetime.datetime, datetime.timedelta]] = None
until_date: Optional[Union[datetime.datetime, datetime.timedelta, int]] = None
"""Restricted and kicked only. Date when restrictions will be lifted for this user; unix time"""
can_be_edited: Optional[bool] = None
"""Administrators only. True, if the bot is allowed to edit administrator privileges of that
@ -39,7 +39,7 @@ class ChatMember(TelegramObject):
"""Administrators only. True, if the administrator can restrict, ban or unban chat members"""
can_promote_members: Optional[bool] = None
"""Administrators only. True, if the administrator can add new administrators with a subset of
his own privileges or demote administrators that he has promoted, directly or indirectly
their own privileges or demote administrators that he has promoted, directly or indirectly
(promoted by administrators that were appointed by the user)"""
can_change_info: Optional[bool] = None
"""Administrators and restricted only. True, if the user is allowed to change the chat title,

View file

@ -5,11 +5,19 @@ from .base import TelegramObject
class Dice(TelegramObject):
"""
This object represents a dice with random value from 1 to 6. (Yes, we're aware of the 'proper'
singular of die. But it's awkward, and we decided to help it change. One dice at a time!)
This object represents a dice with a random value from 1 to 6 for currently supported base
emoji. (Yes, we're aware of the 'proper' singular of die. But it's awkward, and we decided to
help it change. One dice at a time!)
Source: https://core.telegram.org/bots/api#dice
"""
emoji: str
"""Emoji on which the dice throw animation is based"""
value: int
"""Value of the dice, 1-6"""
"""Value of the dice, 1-6 for currently supported base emoji"""
class DiceEmoji:
DICE = "🎲"
DART = "🎯"

View file

@ -32,7 +32,7 @@ class InlineKeyboardButton(MutableTelegramObject):
be empty, in which case just the bots username will be inserted."""
switch_inline_query_current_chat: Optional[str] = None
"""If set, pressing the button will insert the bots username and the specified inline query
in the current chat's input field. Can be empty, in which case only the bots username will
in the current chats input field. Can be empty, in which case only the bot's username will
be inserted."""
callback_game: Optional[CallbackGame] = None
"""Description of the game that will be launched when the user presses the button."""

View file

@ -33,8 +33,7 @@ class InlineQueryResultAudio(InlineQueryResult):
caption: Optional[str] = None
"""Caption, 0-1024 characters after entities parsing"""
parse_mode: Optional[str] = None
"""Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or
inline URLs in the media caption."""
"""Mode for parsing entities in the audio caption. See formatting options for more details."""
performer: Optional[str] = None
"""Performer"""
audio_duration: Optional[int] = None

View file

@ -31,8 +31,7 @@ class InlineQueryResultCachedAudio(InlineQueryResult):
caption: Optional[str] = None
"""Caption, 0-1024 characters after entities parsing"""
parse_mode: Optional[str] = None
"""Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or
inline URLs in the media caption."""
"""Mode for parsing entities in the audio caption. See formatting options for more details."""
reply_markup: Optional[InlineKeyboardMarkup] = None
"""Inline keyboard attached to the message"""
input_message_content: Optional[InputMessageContent] = None

View file

@ -35,8 +35,7 @@ class InlineQueryResultCachedDocument(InlineQueryResult):
caption: Optional[str] = None
"""Caption of the document to be sent, 0-1024 characters after entities parsing"""
parse_mode: Optional[str] = None
"""Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or
inline URLs in the media caption."""
"""Mode for parsing entities in the document caption. See formatting options for more details."""
reply_markup: Optional[InlineKeyboardMarkup] = None
"""Inline keyboard attached to the message"""
input_message_content: Optional[InputMessageContent] = None

View file

@ -31,8 +31,7 @@ class InlineQueryResultCachedGif(InlineQueryResult):
caption: Optional[str] = None
"""Caption of the GIF file to be sent, 0-1024 characters after entities parsing"""
parse_mode: Optional[str] = None
"""Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or
inline URLs in the media caption."""
"""Mode for parsing entities in the caption. See formatting options for more details."""
reply_markup: Optional[InlineKeyboardMarkup] = None
"""Inline keyboard attached to the message"""
input_message_content: Optional[InputMessageContent] = None

View file

@ -32,8 +32,7 @@ class InlineQueryResultCachedMpeg4Gif(InlineQueryResult):
caption: Optional[str] = None
"""Caption of the MPEG-4 file to be sent, 0-1024 characters after entities parsing"""
parse_mode: Optional[str] = None
"""Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or
inline URLs in the media caption."""
"""Mode for parsing entities in the caption. See formatting options for more details."""
reply_markup: Optional[InlineKeyboardMarkup] = None
"""Inline keyboard attached to the message"""
input_message_content: Optional[InputMessageContent] = None

View file

@ -33,8 +33,7 @@ class InlineQueryResultCachedPhoto(InlineQueryResult):
caption: Optional[str] = None
"""Caption of the photo to be sent, 0-1024 characters after entities parsing"""
parse_mode: Optional[str] = None
"""Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or
inline URLs in the media caption."""
"""Mode for parsing entities in the photo caption. See formatting options for more details."""
reply_markup: Optional[InlineKeyboardMarkup] = None
"""Inline keyboard attached to the message"""
input_message_content: Optional[InputMessageContent] = None

View file

@ -33,8 +33,7 @@ class InlineQueryResultCachedVideo(InlineQueryResult):
caption: Optional[str] = None
"""Caption of the video to be sent, 0-1024 characters after entities parsing"""
parse_mode: Optional[str] = None
"""Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or
inline URLs in the media caption."""
"""Mode for parsing entities in the video caption. See formatting options for more details."""
reply_markup: Optional[InlineKeyboardMarkup] = None
"""Inline keyboard attached to the message"""
input_message_content: Optional[InputMessageContent] = None

View file

@ -33,8 +33,8 @@ class InlineQueryResultCachedVoice(InlineQueryResult):
caption: Optional[str] = None
"""Caption, 0-1024 characters after entities parsing"""
parse_mode: Optional[str] = None
"""Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or
inline URLs in the media caption."""
"""Mode for parsing entities in the voice message caption. See formatting options for more
details."""
reply_markup: Optional[InlineKeyboardMarkup] = None
"""Inline keyboard attached to the message"""
input_message_content: Optional[InputMessageContent] = None

View file

@ -36,8 +36,7 @@ class InlineQueryResultDocument(InlineQueryResult):
caption: Optional[str] = None
"""Caption of the document to be sent, 0-1024 characters after entities parsing"""
parse_mode: Optional[str] = None
"""Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or
inline URLs in the media caption."""
"""Mode for parsing entities in the document caption. See formatting options for more details."""
description: Optional[str] = None
"""Short description of the result"""
reply_markup: Optional[InlineKeyboardMarkup] = None

View file

@ -39,8 +39,7 @@ class InlineQueryResultGif(InlineQueryResult):
caption: Optional[str] = None
"""Caption of the GIF file to be sent, 0-1024 characters after entities parsing"""
parse_mode: Optional[str] = None
"""Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or
inline URLs in the media caption."""
"""Mode for parsing entities in the caption. See formatting options for more details."""
reply_markup: Optional[InlineKeyboardMarkup] = None
"""Inline keyboard attached to the message"""
input_message_content: Optional[InputMessageContent] = None

View file

@ -40,8 +40,7 @@ class InlineQueryResultMpeg4Gif(InlineQueryResult):
caption: Optional[str] = None
"""Caption of the MPEG-4 file to be sent, 0-1024 characters after entities parsing"""
parse_mode: Optional[str] = None
"""Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or
inline URLs in the media caption."""
"""Mode for parsing entities in the caption. See formatting options for more details."""
reply_markup: Optional[InlineKeyboardMarkup] = None
"""Inline keyboard attached to the message"""
input_message_content: Optional[InputMessageContent] = None

View file

@ -39,8 +39,7 @@ class InlineQueryResultPhoto(InlineQueryResult):
caption: Optional[str] = None
"""Caption of the photo to be sent, 0-1024 characters after entities parsing"""
parse_mode: Optional[str] = None
"""Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or
inline URLs in the media caption."""
"""Mode for parsing entities in the photo caption. See formatting options for more details."""
reply_markup: Optional[InlineKeyboardMarkup] = None
"""Inline keyboard attached to the message"""
input_message_content: Optional[InputMessageContent] = None

View file

@ -37,8 +37,7 @@ class InlineQueryResultVideo(InlineQueryResult):
caption: Optional[str] = None
"""Caption of the video to be sent, 0-1024 characters after entities parsing"""
parse_mode: Optional[str] = None
"""Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or
inline URLs in the media caption."""
"""Mode for parsing entities in the video caption. See formatting options for more details."""
video_width: Optional[int] = None
"""Video width"""
video_height: Optional[int] = None

View file

@ -34,8 +34,8 @@ class InlineQueryResultVoice(InlineQueryResult):
caption: Optional[str] = None
"""Caption, 0-1024 characters after entities parsing"""
parse_mode: Optional[str] = None
"""Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or
inline URLs in the media caption."""
"""Mode for parsing entities in the voice message caption. See formatting options for more
details."""
voice_duration: Optional[int] = None
"""Recording duration in seconds"""
reply_markup: Optional[InlineKeyboardMarkup] = None

View file

@ -34,8 +34,8 @@ class InputMediaAnimation(InputMedia):
caption: Optional[str] = None
"""Caption of the animation to be sent, 0-1024 characters after entities parsing"""
parse_mode: Optional[str] = None
"""Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or
inline URLs in the media caption."""
"""Mode for parsing entities in the animation caption. See formatting options for more
details."""
width: Optional[int] = None
"""Animation width"""
height: Optional[int] = None

View file

@ -34,8 +34,7 @@ class InputMediaAudio(InputMedia):
caption: Optional[str] = None
"""Caption of the audio to be sent, 0-1024 characters after entities parsing"""
parse_mode: Optional[str] = None
"""Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or
inline URLs in the media caption."""
"""Mode for parsing entities in the audio caption. See formatting options for more details."""
duration: Optional[int] = None
"""Duration of the audio in seconds"""
performer: Optional[str] = None

View file

@ -34,5 +34,4 @@ class InputMediaDocument(InputMedia):
caption: Optional[str] = None
"""Caption of the document to be sent, 0-1024 characters after entities parsing"""
parse_mode: Optional[str] = None
"""Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or
inline URLs in the media caption."""
"""Mode for parsing entities in the document caption. See formatting options for more details."""

View file

@ -27,5 +27,4 @@ class InputMediaPhoto(InputMedia):
caption: Optional[str] = None
"""Caption of the photo to be sent, 0-1024 characters after entities parsing"""
parse_mode: Optional[str] = None
"""Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or
inline URLs in the media caption."""
"""Mode for parsing entities in the photo caption. See formatting options for more details."""

View file

@ -34,8 +34,7 @@ class InputMediaVideo(InputMedia):
caption: Optional[str] = None
"""Caption of the video to be sent, 0-1024 characters after entities parsing"""
parse_mode: Optional[str] = None
"""Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or
inline URLs in the media caption."""
"""Mode for parsing entities in the video caption. See formatting options for more details."""
width: Optional[int] = None
"""Video width"""
height: Optional[int] = None

View file

@ -15,7 +15,6 @@ class InputTextMessageContent(InputMessageContent):
message_text: str
"""Text of the message to be sent, 1-4096 characters"""
parse_mode: Optional[str] = None
"""Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or
inline URLs in your bot's message."""
"""Mode for parsing entities in the message text. See formatting options for more details."""
disable_web_page_preview: Optional[bool] = None
"""Disables link previews for links in the sent message"""

View file

@ -1007,6 +1007,10 @@ class Message(TelegramObject):
type: Optional[str] = None,
allows_multiple_answers: Optional[bool] = None,
correct_option_id: Optional[int] = None,
explanation: Optional[str] = None,
explanation_parse_mode: Optional[str] = None,
open_period: Optional[int] = None,
close_date: Optional[Union[datetime.datetime, datetime.timedelta, int]] = None,
is_closed: Optional[bool] = None,
disable_notification: Optional[bool] = None,
reply_markup: Optional[
@ -1022,6 +1026,10 @@ class Message(TelegramObject):
:param type:
:param allows_multiple_answers:
:param correct_option_id:
:param explanation:
:param explanation_parse_mode:
:param open_period:
:param close_date:
:param is_closed:
:param disable_notification:
:param reply_markup:
@ -1037,6 +1045,10 @@ class Message(TelegramObject):
type=type,
allows_multiple_answers=allows_multiple_answers,
correct_option_id=correct_option_id,
explanation=explanation,
explanation_parse_mode=explanation_parse_mode,
open_period=open_period,
close_date=close_date,
is_closed=is_closed,
disable_notification=disable_notification,
reply_to_message_id=self.message_id,
@ -1051,6 +1063,10 @@ class Message(TelegramObject):
type: Optional[str] = None,
allows_multiple_answers: Optional[bool] = None,
correct_option_id: Optional[int] = None,
explanation: Optional[str] = None,
explanation_parse_mode: Optional[str] = None,
open_period: Optional[int] = None,
close_date: Optional[Union[datetime.datetime, datetime.timedelta, int]] = None,
is_closed: Optional[bool] = None,
disable_notification: Optional[bool] = None,
reply_markup: Optional[
@ -1066,6 +1082,10 @@ class Message(TelegramObject):
:param type:
:param allows_multiple_answers:
:param correct_option_id:
:param explanation:
:param explanation_parse_mode:
:param open_period:
:param close_date:
:param is_closed:
:param disable_notification:
:param reply_markup:
@ -1081,6 +1101,10 @@ class Message(TelegramObject):
type=type,
allows_multiple_answers=allows_multiple_answers,
correct_option_id=correct_option_id,
explanation=explanation,
explanation_parse_mode=explanation_parse_mode,
open_period=open_period,
close_date=close_date,
is_closed=is_closed,
disable_notification=disable_notification,
reply_to_message_id=None,
@ -1089,6 +1113,7 @@ class Message(TelegramObject):
def reply_dice(
self,
emoji: Optional[str] = None,
disable_notification: Optional[bool] = None,
reply_markup: Optional[
Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply]
@ -1097,6 +1122,7 @@ class Message(TelegramObject):
"""
Reply with dice
:param emoji:
:param disable_notification:
:param reply_markup:
:return:
@ -1105,6 +1131,7 @@ class Message(TelegramObject):
return SendDice(
chat_id=self.chat.id,
emoji=emoji,
disable_notification=disable_notification,
reply_to_message_id=self.message_id,
reply_markup=reply_markup,
@ -1112,6 +1139,7 @@ class Message(TelegramObject):
def answer_dice(
self,
emoji: Optional[str] = None,
disable_notification: Optional[bool] = None,
reply_markup: Optional[
Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply]
@ -1120,6 +1148,7 @@ class Message(TelegramObject):
"""
Answer with dice
:param emoji:
:param disable_notification:
:param reply_markup:
:return:
@ -1128,6 +1157,7 @@ class Message(TelegramObject):
return SendDice(
chat_id=self.chat.id,
emoji=emoji,
disable_notification=disable_notification,
reply_to_message_id=None,
reply_markup=reply_markup,

View file

@ -1,10 +1,12 @@
from __future__ import annotations
from typing import TYPE_CHECKING, List, Optional
import datetime
from typing import TYPE_CHECKING, List, Optional, Union
from .base import TelegramObject
if TYPE_CHECKING: # pragma: no cover
from .message_entity import MessageEntity
from .poll_option import PollOption
@ -35,3 +37,12 @@ class Poll(TelegramObject):
"""0-based identifier of the correct answer option. Available only for polls in the quiz mode,
which are closed, or was sent (not forwarded) by the bot or to the private chat with the
bot."""
explanation: Optional[str] = None
"""Text that is shown when a user chooses an incorrect answer or taps on the lamp icon in a
quiz-style poll, 0-200 characters"""
explanation_entities: Optional[List[MessageEntity]] = None
"""Special entities like usernames, URLs, bot commands, etc. that appear in the explanation"""
open_period: Optional[int] = None
"""Amount of time in seconds the poll will be active after creation"""
close_date: Optional[Union[datetime.datetime, datetime.timedelta, int]] = None
"""Point in time (Unix timestamp) when the poll will be automatically closed"""