Skip to content

Commit d9c4abe

Browse files
authored
Merge pull request #2264 from Badiboy/master
BOT API 7.3
2 parents a8b2986 + 3532812 commit d9c4abe

File tree

8 files changed

+626
-209
lines changed

8 files changed

+626
-209
lines changed

docs/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
copyright = f'2022-{datetime.now().year}, {author}'
2323

2424
# The full version, including alpha/beta/rc tags
25-
release = '4.17.0'
25+
release = '4.18.0'
2626

2727

2828
# -- General configuration ---------------------------------------------------

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "pyTelegramBotAPI"
7-
version = "4.17.0"
7+
version = "4.18.0"
88
description = "Python Telegram bot api."
99
authors = [{name = "eternnoir", email = "eternnoir@gmail.com"}]
1010
license = {text = "GPL2"}

telebot/__init__.py

Lines changed: 47 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ def __init__(
189189
# logs-related
190190
if colorful_logs:
191191
try:
192+
# noinspection PyPackageRequirements
192193
import coloredlogs
193194
coloredlogs.install(logger=logger, level=logger.level)
194195
except ImportError:
@@ -1012,6 +1013,7 @@ def __notify_update(self, new_messages):
10121013

10131014
def _setup_change_detector(self, path_to_watch: str):
10141015
try:
1016+
# noinspection PyPackageRequirements
10151017
from watchdog.observers import Observer
10161018
from telebot.ext.reloader import EventHandler
10171019
except ImportError:
@@ -1491,7 +1493,7 @@ def get_user_profile_photos(self, user_id: int, offset: Optional[int]=None,
14911493
)
14921494

14931495

1494-
def get_chat(self, chat_id: Union[int, str]) -> types.Chat:
1496+
def get_chat(self, chat_id: Union[int, str]) -> types.ChatFullInfo:
14951497
"""
14961498
Use this method to get up to date information about the chat (current name of the user for one-on-one
14971499
conversations, current username of a user, group or channel, etc.). Returns a Chat object on success.
@@ -1502,9 +1504,9 @@ def get_chat(self, chat_id: Union[int, str]) -> types.Chat:
15021504
:type chat_id: :obj:`int` or :obj:`str`
15031505
15041506
:return: Chat information
1505-
:rtype: :class:`telebot.types.Chat`
1507+
:rtype: :class:`telebot.types.ChatFullInfo`
15061508
"""
1507-
return types.Chat.de_json(
1509+
return types.ChatFullInfo.de_json(
15081510
apihelper.get_chat(self.token, chat_id)
15091511
)
15101512

@@ -1889,7 +1891,7 @@ def copy_message(
18891891
apihelper.copy_message(self.token, chat_id, from_chat_id, message_id, caption=caption,
18901892
parse_mode=parse_mode, caption_entities=caption_entities, disable_notification=disable_notification,
18911893
reply_markup=reply_markup, timeout=timeout, protect_content=protect_content,
1892-
message_thread_id=message_thread_id, reply_parameters=reply_parameters))
1894+
message_thread_id=message_thread_id, reply_parameters=reply_parameters))
18931895

18941896

18951897
def delete_message(self, chat_id: Union[int, str], message_id: int,
@@ -2356,9 +2358,7 @@ def send_voice(
23562358
reply_parameters: Optional[types.ReplyParameters]=None,
23572359
business_connection_id: Optional[str]=None) -> types.Message:
23582360
"""
2359-
Use this method to send audio files, if you want Telegram clients to display the file as a playable voice message.
2360-
For this to work, your audio must be in an .OGG file encoded with OPUS (other formats may be sent as Audio or Document).
2361-
On success, the sent Message is returned. Bots can currently send voice messages of up to 50 MB in size, this limit may be changed in the future.
2361+
Use this method to send audio files, if you want Telegram clients to display the file as a playable voice message. For this to work, your audio must be in an .OGG file encoded with OPUS, or in .MP3 format, or in .M4A format (other formats may be sent as Audio or Document). On success, the sent Message is returned. Bots can currently send voice messages of up to 50 MB in size, this limit may be changed in the future.
23622362
23632363
Telegram documentation: https://core.telegram.org/bots/api#sendvoice
23642364
@@ -3162,7 +3162,7 @@ def send_location(
31623162
:param longitude: Longitude of the location
31633163
:type longitude: :obj:`float`
31643164
3165-
:param live_period: Period in seconds for which the location will be updated (see Live Locations, should be between 60 and 86400.
3165+
:param live_period: Period in seconds during which the location will be updated (see Live Locations, should be between 60 and 86400, or 0x7FFFFFFF for live locations that can be edited indefinitely.
31663166
:type live_period: :obj:`int`
31673167
31683168
:param reply_markup: Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard
@@ -3245,7 +3245,9 @@ def edit_message_live_location(
32453245
timeout: Optional[int]=None,
32463246
horizontal_accuracy: Optional[float]=None,
32473247
heading: Optional[int]=None,
3248-
proximity_alert_radius: Optional[int]=None) -> types.Message or bool:
3248+
proximity_alert_radius: Optional[int]=None,
3249+
live_period: Optional[int]=None,
3250+
) -> types.Message or bool:
32493251
"""
32503252
Use this method to edit live location messages. A location can be edited until its live_period expires or editing is explicitly
32513253
disabled by a call to stopMessageLiveLocation. On success, if the edited message is not an inline message, the edited Message
@@ -3284,14 +3286,17 @@ def edit_message_live_location(
32843286
:param proximity_alert_radius: The maximum distance for proximity alerts about approaching another chat member, in meters. Must be between 1 and 100000 if specified.
32853287
:type proximity_alert_radius: :obj:`int`
32863288
3289+
:param live_period: New period in seconds during which the location can be updated, starting from the message send date. If 0x7FFFFFFF is specified, then the location can be updated forever. Otherwise, the new value must not exceed the current live_period by more than a day, and the live location expiration date must remain within the next 90 days. If not specified, then live_period remains unchanged
3290+
:type live_period: :obj:`int`
3291+
32873292
:return: On success, if the edited message is not an inline message, the edited Message is returned, otherwise True is returned.
32883293
:rtype: :class:`telebot.types.Message` or bool
32893294
"""
32903295
return types.Message.de_json(
32913296
apihelper.edit_message_live_location(
32923297
self.token, latitude, longitude, chat_id=chat_id, message_id=message_id, inline_message_id=inline_message_id,
32933298
reply_markup=reply_markup, timeout=timeout, horizontal_accuracy=horizontal_accuracy, heading=heading,
3294-
proximity_alert_radius=proximity_alert_radius)
3299+
proximity_alert_radius=proximity_alert_radius, live_period=live_period)
32953300
)
32963301

32973302

@@ -5129,7 +5134,7 @@ def create_invoice_link(self,
51295134

51305135
# noinspection PyShadowingBuiltins
51315136
def send_poll(
5132-
self, chat_id: Union[int, str], question: str, options: List[str],
5137+
self, chat_id: Union[int, str], question: str, options: List[types.InputPollOption],
51335138
is_anonymous: Optional[bool]=None, type: Optional[str]=None,
51345139
allows_multiple_answers: Optional[bool]=None,
51355140
correct_option_id: Optional[int]=None,
@@ -5147,7 +5152,10 @@ def send_poll(
51475152
protect_content: Optional[bool]=None,
51485153
message_thread_id: Optional[int]=None,
51495154
reply_parameters: Optional[types.ReplyParameters]=None,
5150-
business_connection_id: Optional[str]=None) -> types.Message:
5155+
business_connection_id: Optional[str]=None,
5156+
question_parse_mode: Optional[str] = None,
5157+
question_entities: Optional[List[types.MessageEntity]] = None,
5158+
) -> types.Message:
51515159
"""
51525160
Use this method to send a native poll.
51535161
On success, the sent Message is returned.
@@ -5160,8 +5168,8 @@ def send_poll(
51605168
:param question: Poll question, 1-300 characters
51615169
:type question: :obj:`str`
51625170
5163-
:param options: A JSON-serialized list of answer options, 2-10 strings 1-100 characters each
5164-
:type options: :obj:`list` of :obj:`str`
5171+
:param options: A JSON-serialized list of 2-10 answer options
5172+
:type options: :obj:`list` of :obj:`InputPollOption`
51655173
51665174
:param is_anonymous: True, if the poll needs to be anonymous, defaults to True
51675175
:type is_anonymous: :obj:`bool`
@@ -5172,12 +5180,10 @@ def send_poll(
51725180
:param allows_multiple_answers: True, if the poll allows multiple answers, ignored for polls in quiz mode, defaults to False
51735181
:type allows_multiple_answers: :obj:`bool`
51745182
5175-
:param correct_option_id: 0-based identifier of the correct answer option. Available only for polls in quiz mode,
5176-
defaults to None
5183+
:param correct_option_id: 0-based identifier of the correct answer option. Available only for polls in quiz mode, defaults to None
51775184
:type correct_option_id: :obj:`int`
51785185
5179-
:param explanation: Text that is shown when a user chooses an incorrect answer or taps on the lamp icon in a quiz-style poll,
5180-
0-200 characters with at most 2 line feeds after entities parsing
5186+
: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
51815187
:type explanation: :obj:`str`
51825188
51835189
:param explanation_parse_mode: Mode for parsing entities in the explanation. See formatting options for more details.
@@ -5201,15 +5207,13 @@ def send_poll(
52015207
:param allow_sending_without_reply: deprecated. Pass True, if the message should be sent even if the specified replied-to message is not found
52025208
:type allow_sending_without_reply: :obj:`bool`
52035209
5204-
:param reply_markup: Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard,
5205-
instructions to remove reply keyboard or to force a reply from the user.
5210+
:param reply_markup: Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.
52065211
:type reply_markup: :obj:`InlineKeyboardMarkup` | :obj:`ReplyKeyboardMarkup` | :obj:`ReplyKeyboardRemove` | :obj:`ForceReply`
52075212
52085213
:param timeout: Timeout in seconds for waiting for a response from the user.
52095214
:type timeout: :obj:`int`
52105215
5211-
:param explanation_entities: A JSON-serialized list of special entities that appear in the explanation,
5212-
which can be specified instead of parse_mode
5216+
:param explanation_entities: A JSON-serialized list of special entities that appear in the explanation, which can be specified instead of parse_mode
52135217
:type explanation_entities: :obj:`list` of :obj:`MessageEntity`
52145218
52155219
:param protect_content: Protects the contents of the sent message from forwarding and saving
@@ -5224,6 +5228,12 @@ def send_poll(
52245228
:param business_connection_id: Identifier of the business connection to use for the poll
52255229
:type business_connection_id: :obj:`str`
52265230
5231+
:param question_parse_mode: Mode for parsing entities in the question. See formatting options for more details. Currently, only custom emoji entities are allowed
5232+
:type question_parse_mode: :obj:`str`
5233+
5234+
:param question_entities: A JSON-serialized list of special entities that appear in the poll question. It can be specified instead of question_parse_mode
5235+
:type question_entities: :obj:`list` of :obj:`MessageEntity`
5236+
52275237
:return: On success, the sent Message is returned.
52285238
:rtype: :obj:`types.Message`
52295239
"""
@@ -5255,6 +5265,18 @@ def send_poll(
52555265
raise RuntimeError("The send_poll signature was changed, please see send_poll function details.")
52565266

52575267
explanation_parse_mode = self.parse_mode if (explanation_parse_mode is None) else explanation_parse_mode
5268+
question_parse_mode = self.parse_mode if (question_parse_mode is None) else question_parse_mode
5269+
5270+
if options and (not isinstance(options[0], types.InputPollOption)):
5271+
# show a deprecation warning
5272+
logger.warning("The parameter 'options' changed, should be List[types.InputPollOption], other types are deprecated.")
5273+
# convert options to appropriate type
5274+
if isinstance(options[0], str):
5275+
options = [types.InputPollOption(option) for option in options]
5276+
elif isinstance(options[0], types.PollOption):
5277+
options = [types.InputPollOption(option.text, text_entities=option.text_entities) for option in options]
5278+
else:
5279+
raise RuntimeError("Type of 'options' items is unknown. Options should be List[types.InputPollOption], other types are deprecated.")
52585280

52595281
return types.Message.de_json(
52605282
apihelper.send_poll(
@@ -5265,7 +5287,8 @@ def send_poll(
52655287
close_date=close_date, is_closed=is_closed, disable_notification=disable_notification,
52665288
reply_markup=reply_markup, timeout=timeout, explanation_entities=explanation_entities,
52675289
protect_content=protect_content, message_thread_id=message_thread_id,
5268-
reply_parameters=reply_parameters, business_connection_id=business_connection_id)
5290+
reply_parameters=reply_parameters, business_connection_id=business_connection_id,
5291+
question_parse_mode=question_parse_mode, question_entities=question_entities)
52695292
)
52705293

52715294

@@ -5564,7 +5587,7 @@ def get_user_chat_boosts(self, chat_id: Union[int, str], user_id: int) -> types.
55645587
apihelper.get_user_chat_boosts(self.token, chat_id, user_id)
55655588
)
55665589

5567-
5590+
# noinspection PyShadowingBuiltins
55685591
def set_sticker_set_thumbnail(self, name: str, user_id: int, thumbnail: Union[Any, str]=None, format: Optional[str]=None) -> bool:
55695592
"""
55705593
Use this method to set the thumbnail of a sticker set.

0 commit comments

Comments
 (0)