pyTelegramBotAPI 4.22.0__py3-none-any.whl → 4.23.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pytelegrambotapi-4.22.0.dist-info → pytelegrambotapi-4.23.0.dist-info}/METADATA +2 -4
- pytelegrambotapi-4.23.0.dist-info/RECORD +41 -0
- telebot/__init__.py +261 -31
- telebot/apihelper.py +36 -11
- telebot/async_telebot.py +268 -31
- telebot/asyncio_filters.py +23 -27
- telebot/asyncio_handler_backends.py +98 -137
- telebot/asyncio_helper.py +41 -12
- telebot/asyncio_storage/__init__.py +13 -13
- telebot/asyncio_storage/base_storage.py +123 -68
- telebot/asyncio_storage/memory_storage.py +225 -66
- telebot/asyncio_storage/pickle_storage.py +274 -110
- telebot/asyncio_storage/redis_storage.py +339 -179
- telebot/custom_filters.py +21 -28
- telebot/handler_backends.py +258 -295
- telebot/states/__init__.py +128 -0
- telebot/states/asyncio/__init__.py +7 -0
- telebot/states/asyncio/context.py +153 -0
- telebot/states/asyncio/middleware.py +21 -0
- telebot/states/sync/__init__.py +7 -0
- telebot/states/sync/context.py +143 -0
- telebot/states/sync/middleware.py +21 -0
- telebot/storage/__init__.py +13 -13
- telebot/storage/base_storage.py +118 -68
- telebot/storage/memory_storage.py +225 -69
- telebot/storage/pickle_storage.py +263 -116
- telebot/storage/redis_storage.py +324 -183
- telebot/types.py +143 -41
- telebot/util.py +720 -700
- telebot/version.py +1 -1
- pytelegrambotapi-4.22.0.dist-info/RECORD +0 -34
- {pytelegrambotapi-4.22.0.dist-info → pytelegrambotapi-4.23.0.dist-info}/WHEEL +0 -0
- {pytelegrambotapi-4.22.0.dist-info → pytelegrambotapi-4.23.0.dist-info}/licenses/LICENSE +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: pyTelegramBotAPI
|
|
3
|
-
Version: 4.
|
|
3
|
+
Version: 4.23.0
|
|
4
4
|
Summary: Python Telegram bot api.
|
|
5
5
|
Project-URL: Homepage, https://github.com/eternnoir/pyTelegramBotAPI
|
|
6
6
|
Project-URL: Documentation, https://pytba.readthedocs.org
|
|
@@ -23,8 +23,6 @@ Requires-Python: >=3.8
|
|
|
23
23
|
Requires-Dist: requests
|
|
24
24
|
Provides-Extra: aiohttp
|
|
25
25
|
Requires-Dist: aiohttp; extra == 'aiohttp'
|
|
26
|
-
Provides-Extra: aioredis
|
|
27
|
-
Requires-Dist: aioredis; extra == 'aioredis'
|
|
28
26
|
Provides-Extra: coloredlogs
|
|
29
27
|
Requires-Dist: coloredlogs; extra == 'coloredlogs'
|
|
30
28
|
Provides-Extra: fastapi
|
|
@@ -55,7 +53,7 @@ Description-Content-Type: text/markdown
|
|
|
55
53
|
<p align="center">A simple, but extensible Python implementation for the <a href="https://core.telegram.org/bots/api">Telegram Bot API</a>.</p>
|
|
56
54
|
<p align="center">Both synchronous and asynchronous.</p>
|
|
57
55
|
|
|
58
|
-
## <p align="center">Supported Bot API version: <a href="https://core.telegram.org/bots/api
|
|
56
|
+
## <p align="center">Supported Bot API version: <a href="https://core.telegram.org/bots/api#september-6-2024"><img src="https://img.shields.io/badge/Bot%20API-7.10-blue?logo=telegram" alt="Supported Bot API version"></a>
|
|
59
57
|
|
|
60
58
|
<h2><a href='https://pytba.readthedocs.io/en/latest/index.html'>Official documentation</a></h2>
|
|
61
59
|
<h2><a href='https://pytba.readthedocs.io/ru/latest/index.html'>Official ru documentation</a></h2>
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
telebot/__init__.py,sha256=b0LIGG4qK94pnwefptKq0KVNwxR6NgAedzCdiUcGrfc,417917
|
|
2
|
+
telebot/apihelper.py,sha256=dI1K74azMPqwBwEs4UvWQ4shW36JJKAn2ptFQo-j3ss,95267
|
|
3
|
+
telebot/async_telebot.py,sha256=tksz1f9UfU6oyU1CZ_PRTtDm4k5J82uosXgBrJHrbOA,391043
|
|
4
|
+
telebot/asyncio_filters.py,sha256=w63xFjFnXtr4oo3Kqx1Fs485vQxNCgXZs1ukdkNcnEA,12854
|
|
5
|
+
telebot/asyncio_handler_backends.py,sha256=BWS7zr93FJNZJmPHBoXo4i_PIHGlmrEoWy1miXax9aI,2785
|
|
6
|
+
telebot/asyncio_helper.py,sha256=veOPbLDag2HwlJ0CYQbIkmEHmz1ek2uk72NzNs7PdL0,96125
|
|
7
|
+
telebot/callback_data.py,sha256=k4Rz3lAONG5J2M9TESKMIjqXoBNJMfEy9nnrmJAyi3Q,5358
|
|
8
|
+
telebot/custom_filters.py,sha256=ncF8_zwlSqkuATI46Xc6HQ5Y1ZoQ1fO6AlcRbs7bO3U,12975
|
|
9
|
+
telebot/formatting.py,sha256=_y8M5KOv9UOXfF9z7Et4fPVgh9JnzI1cr4un9sfdlc0,15176
|
|
10
|
+
telebot/handler_backends.py,sha256=lyKu0PaH2c4y5FfyQS3M9tOyBJ8ATjxHZkATzu01XpE,7969
|
|
11
|
+
telebot/service_utils.py,sha256=xLmlZLTVs34UOdQtMvwduor8hnLxQCx8iJ92wDGl2Mw,2053
|
|
12
|
+
telebot/types.py,sha256=rHHkagvfWgtqxGsXvwVR_GD9EWujzn1_lm9AYnxkc40,463667
|
|
13
|
+
telebot/util.py,sha256=ylRtI4DI4I1BJAF2Ack7WyGbTN1cRkubUCbhLNiiPj4,21385
|
|
14
|
+
telebot/version.py,sha256=33cH7PM7w-P3rSAYZ0ykyw3QddU6BsFL5Asu9RL52qA,99
|
|
15
|
+
telebot/asyncio_storage/__init__.py,sha256=fraOWJby1ddJmPAXf1oXWmZJXRodSpING17MF875NPI,433
|
|
16
|
+
telebot/asyncio_storage/base_storage.py,sha256=I-NII9ZMCxCHStPc-73qSyQhjBtkhNzb2IcZPhjR1Eg,3243
|
|
17
|
+
telebot/asyncio_storage/memory_storage.py,sha256=h8yc2xpfLmbcBjPmKkqNhZtUtpNQ7EuKIfMGue61e7w,5849
|
|
18
|
+
telebot/asyncio_storage/pickle_storage.py,sha256=3uaQGw6jF1kF7x-qLq1VIGjya2hcEY1J9HAouDuXH4U,7647
|
|
19
|
+
telebot/asyncio_storage/redis_storage.py,sha256=ruhh1jPUf0YHQWfg_QAHPEn8Vm9cvBwkybD5R7GSUDw,9897
|
|
20
|
+
telebot/ext/__init__.py,sha256=_mSeNU1cib3cWSZ6Kb6nKy9znEYwEzGNRCYZsD61rLk,66
|
|
21
|
+
telebot/ext/reloader.py,sha256=vzmJxCsA_COHF-bpmyddDuUXroxNih051IYRMiR21LY,826
|
|
22
|
+
telebot/ext/aio/__init__.py,sha256=2yi7jtvEIH1DqAseFevfujNYi7ZSh5aPMOKGrxIgqsw,143
|
|
23
|
+
telebot/ext/aio/webhooks.py,sha256=tf4DMXkKWvM_Uko_lpLRc0uDwttyZGvsvDLNNbwmO_Y,3788
|
|
24
|
+
telebot/ext/sync/__init__.py,sha256=Lj-15dj1TYkf11d0vY14_2mssnoFR5Uk320huWa_rGc,140
|
|
25
|
+
telebot/ext/sync/webhooks.py,sha256=XMMhXnDuFs7CWJ7iDi11H0dwf6fRA4pbAjFjNgNJ18Y,3513
|
|
26
|
+
telebot/states/__init__.py,sha256=ggLBEJyMoh3i_IDpUE_jvtP7NiC7IwIR4QJXmI1BFGc,4401
|
|
27
|
+
telebot/states/asyncio/__init__.py,sha256=vomgAmaY590Ul0U-oovN7-Vjf6CwrchmjAZS8PX-lqY,132
|
|
28
|
+
telebot/states/asyncio/context.py,sha256=LeH1uD3NSkQ6EJ-rsSfJfA1SaQ_FnoPRWg746SwOhFI,4952
|
|
29
|
+
telebot/states/asyncio/middleware.py,sha256=UZgd4Ty8JwOcj50zdI8eJ0tfPCmgiymxyaX-dR2tpVg,730
|
|
30
|
+
telebot/states/sync/__init__.py,sha256=FqxubuunwknusMEAkaUwgFdIBmTZtEhRUaRZE18bzzs,131
|
|
31
|
+
telebot/states/sync/context.py,sha256=mw19DPMSqPsg8e-i3ZVsp-YxZSfHfn1rpisn5smvfrM,4731
|
|
32
|
+
telebot/states/sync/middleware.py,sha256=7mGC0xEQt7vjfCgmJWOKn7BXHxjQyLFoyZ1rL0blm4Q,680
|
|
33
|
+
telebot/storage/__init__.py,sha256=Uagoo-sNYA0PX-hICKSaXtr4YRUOp2GPwlK1vlap9O8,401
|
|
34
|
+
telebot/storage/base_storage.py,sha256=WzGgSflKzcn2ENsgz1Q-D_v-ZKCtnMOURGOHIwNJ0WU,2986
|
|
35
|
+
telebot/storage/memory_storage.py,sha256=-r1vuIt1YHq9btkr6E7BCu4Do-wUDlNcttG22SSgEYo,5799
|
|
36
|
+
telebot/storage/pickle_storage.py,sha256=dqw7syOJuTWyU0KK8XwbJvQ9PMyDHhZQG-MevZImEak,7121
|
|
37
|
+
telebot/storage/redis_storage.py,sha256=DReU2lc8cI0f3XMIT1N9-suGZ6jE8H9I_mapK3A-lyE,9450
|
|
38
|
+
pytelegrambotapi-4.23.0.dist-info/METADATA,sha256=7DjRELqoR1X4QlXm6oojq1e6IIt3pxX7J_5PjoLz59c,48157
|
|
39
|
+
pytelegrambotapi-4.23.0.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
|
|
40
|
+
pytelegrambotapi-4.23.0.dist-info/licenses/LICENSE,sha256=qz_jTTxi4zSAFaTdASiwml2iAk0UZ6R4MRADNzwYo_A,18387
|
|
41
|
+
pytelegrambotapi-4.23.0.dist-info/RECORD,,
|
telebot/__init__.py
CHANGED
|
@@ -7,7 +7,7 @@ import sys
|
|
|
7
7
|
import threading
|
|
8
8
|
import time
|
|
9
9
|
import traceback
|
|
10
|
-
from typing import Any, Callable, List, Optional, Union
|
|
10
|
+
from typing import Any, Callable, List, Optional, Union, Dict
|
|
11
11
|
|
|
12
12
|
# these imports are used to avoid circular import error
|
|
13
13
|
import telebot.util
|
|
@@ -20,7 +20,6 @@ from telebot.storage import StatePickleStorage, StateMemoryStorage, StateStorage
|
|
|
20
20
|
# random module to generate random string
|
|
21
21
|
import random
|
|
22
22
|
import string
|
|
23
|
-
import copy
|
|
24
23
|
|
|
25
24
|
import ssl
|
|
26
25
|
|
|
@@ -153,9 +152,14 @@ class TeleBot:
|
|
|
153
152
|
:param allow_sending_without_reply: Default value for allow_sending_without_reply, defaults to None
|
|
154
153
|
:type allow_sending_without_reply: :obj:`bool`, optional
|
|
155
154
|
|
|
156
|
-
|
|
157
155
|
:param colorful_logs: Outputs colorful logs
|
|
158
156
|
:type colorful_logs: :obj:`bool`, optional
|
|
157
|
+
|
|
158
|
+
:param validate_token: Validate token, defaults to True;
|
|
159
|
+
:type validate_token: :obj:`bool`, optional
|
|
160
|
+
|
|
161
|
+
:raises ImportError: If coloredlogs module is not installed and colorful_logs is True
|
|
162
|
+
:raises ValueError: If token is invalid
|
|
159
163
|
"""
|
|
160
164
|
|
|
161
165
|
def __init__(
|
|
@@ -169,7 +173,8 @@ class TeleBot:
|
|
|
169
173
|
disable_notification: Optional[bool]=None,
|
|
170
174
|
protect_content: Optional[bool]=None,
|
|
171
175
|
allow_sending_without_reply: Optional[bool]=None,
|
|
172
|
-
colorful_logs: Optional[bool]=False
|
|
176
|
+
colorful_logs: Optional[bool]=False,
|
|
177
|
+
validate_token: Optional[bool]=True
|
|
173
178
|
):
|
|
174
179
|
|
|
175
180
|
# update-related
|
|
@@ -187,6 +192,11 @@ class TeleBot:
|
|
|
187
192
|
self.webhook_listener = None
|
|
188
193
|
self._user = None
|
|
189
194
|
|
|
195
|
+
if validate_token:
|
|
196
|
+
util.validate_token(self.token)
|
|
197
|
+
|
|
198
|
+
self.bot_id: Union[int, None] = util.extract_bot_id(self.token) # subject to change in future, unspecified
|
|
199
|
+
|
|
190
200
|
# logs-related
|
|
191
201
|
if colorful_logs:
|
|
192
202
|
try:
|
|
@@ -238,6 +248,7 @@ class TeleBot:
|
|
|
238
248
|
self.business_message_handlers = []
|
|
239
249
|
self.edited_business_message_handlers = []
|
|
240
250
|
self.deleted_business_messages_handlers = []
|
|
251
|
+
self.purchased_paid_media_handlers = []
|
|
241
252
|
|
|
242
253
|
self.custom_filters = {}
|
|
243
254
|
self.state_handlers = []
|
|
@@ -281,7 +292,7 @@ class TeleBot:
|
|
|
281
292
|
self.threaded = threaded
|
|
282
293
|
if self.threaded:
|
|
283
294
|
self.worker_pool = util.ThreadPool(self, num_threads=num_threads)
|
|
284
|
-
|
|
295
|
+
|
|
285
296
|
@property
|
|
286
297
|
def user(self) -> types.User:
|
|
287
298
|
"""
|
|
@@ -714,6 +725,7 @@ class TeleBot:
|
|
|
714
725
|
new_business_messages = None
|
|
715
726
|
new_edited_business_messages = None
|
|
716
727
|
new_deleted_business_messages = None
|
|
728
|
+
new_purchased_paid_media = None
|
|
717
729
|
|
|
718
730
|
for update in updates:
|
|
719
731
|
if apihelper.ENABLE_MIDDLEWARE and not self.use_class_middlewares:
|
|
@@ -795,8 +807,10 @@ class TeleBot:
|
|
|
795
807
|
if update.deleted_business_messages:
|
|
796
808
|
if new_deleted_business_messages is None: new_deleted_business_messages = []
|
|
797
809
|
new_deleted_business_messages.append(update.deleted_business_messages)
|
|
798
|
-
|
|
799
|
-
|
|
810
|
+
if update.purchased_paid_media:
|
|
811
|
+
if new_purchased_paid_media is None: new_purchased_paid_media = []
|
|
812
|
+
new_purchased_paid_media.append(update.purchased_paid_media)
|
|
813
|
+
|
|
800
814
|
if new_messages:
|
|
801
815
|
self.process_new_messages(new_messages)
|
|
802
816
|
if new_edited_messages:
|
|
@@ -841,6 +855,8 @@ class TeleBot:
|
|
|
841
855
|
self.process_new_edited_business_message(new_edited_business_messages)
|
|
842
856
|
if new_deleted_business_messages:
|
|
843
857
|
self.process_new_deleted_business_messages(new_deleted_business_messages)
|
|
858
|
+
if new_purchased_paid_media:
|
|
859
|
+
self.process_new_purchased_paid_media(new_purchased_paid_media)
|
|
844
860
|
|
|
845
861
|
def process_new_messages(self, new_messages):
|
|
846
862
|
"""
|
|
@@ -977,8 +993,11 @@ class TeleBot:
|
|
|
977
993
|
"""
|
|
978
994
|
self._notify_command_handlers(self.deleted_business_messages_handlers, new_deleted_business_messages, 'deleted_business_messages')
|
|
979
995
|
|
|
980
|
-
|
|
981
|
-
|
|
996
|
+
def process_new_purchased_paid_media(self, new_purchased_paid_media):
|
|
997
|
+
"""
|
|
998
|
+
:meta private:
|
|
999
|
+
"""
|
|
1000
|
+
self._notify_command_handlers(self.purchased_paid_media_handlers, new_purchased_paid_media, 'purchased_paid_media')
|
|
982
1001
|
|
|
983
1002
|
def process_middlewares(self, update):
|
|
984
1003
|
"""
|
|
@@ -3126,7 +3145,9 @@ class TeleBot:
|
|
|
3126
3145
|
caption: Optional[str]=None, parse_mode: Optional[str]=None, caption_entities: Optional[List[types.MessageEntity]]=None,
|
|
3127
3146
|
show_caption_above_media: Optional[bool]=None, disable_notification: Optional[bool]=None,
|
|
3128
3147
|
protect_content: Optional[bool]=None, reply_parameters: Optional[types.ReplyParameters]=None,
|
|
3129
|
-
reply_markup: Optional[REPLY_MARKUP_TYPES]=None
|
|
3148
|
+
reply_markup: Optional[REPLY_MARKUP_TYPES]=None, business_connection_id: Optional[str]=None,
|
|
3149
|
+
payload: Optional[str]=None
|
|
3150
|
+
) -> types.Message:
|
|
3130
3151
|
"""
|
|
3131
3152
|
Use this method to send paid media to channel chats. On success, the sent Message is returned.
|
|
3132
3153
|
|
|
@@ -3165,6 +3186,12 @@ class TeleBot:
|
|
|
3165
3186
|
:param reply_markup: Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user
|
|
3166
3187
|
:type reply_markup: :class:`telebot.types.InlineKeyboardMarkup` or :class:`telebot.types.ReplyKeyboardMarkup` or :class:`telebot.types.ReplyKeyboardRemove` or :class:`telebot.types.ForceReply`
|
|
3167
3188
|
|
|
3189
|
+
:param business_connection_id: Identifier of a business connection, in which the message will be sent
|
|
3190
|
+
:type business_connection_id: :obj:`str`
|
|
3191
|
+
|
|
3192
|
+
:param payload: Bot-defined paid media payload, 0-128 bytes. This will not be displayed to the user, use it for your internal processes.
|
|
3193
|
+
:type payload: :obj:`str`
|
|
3194
|
+
|
|
3168
3195
|
:return: On success, the sent Message is returned.
|
|
3169
3196
|
:rtype: :class:`telebot.types.Message`
|
|
3170
3197
|
"""
|
|
@@ -3173,7 +3200,8 @@ class TeleBot:
|
|
|
3173
3200
|
self.token, chat_id, star_count, media, caption=caption, parse_mode=parse_mode,
|
|
3174
3201
|
caption_entities=caption_entities, show_caption_above_media=show_caption_above_media,
|
|
3175
3202
|
disable_notification=disable_notification, protect_content=protect_content,
|
|
3176
|
-
reply_parameters=reply_parameters, reply_markup=reply_markup
|
|
3203
|
+
reply_parameters=reply_parameters, reply_markup=reply_markup, business_connection_id=business_connection_id,
|
|
3204
|
+
payload=payload)
|
|
3177
3205
|
)
|
|
3178
3206
|
|
|
3179
3207
|
|
|
@@ -4185,6 +4213,62 @@ class TeleBot:
|
|
|
4185
4213
|
apihelper.edit_chat_invite_link(self.token, chat_id, invite_link, name, expire_date, member_limit, creates_join_request)
|
|
4186
4214
|
)
|
|
4187
4215
|
|
|
4216
|
+
def create_chat_subscription_invite_link(
|
|
4217
|
+
self, chat_id: Union[int, str], subscription_period: int, subscription_price: int,
|
|
4218
|
+
name: Optional[str]=None) -> types.ChatInviteLink:
|
|
4219
|
+
"""
|
|
4220
|
+
Use this method to create a subscription invite link for a channel chat. The bot must have the can_invite_users administrator rights.
|
|
4221
|
+
The link can be edited using the method editChatSubscriptionInviteLink or revoked using the method revokeChatInviteLink.
|
|
4222
|
+
Returns the new invite link as a ChatInviteLink object.
|
|
4223
|
+
|
|
4224
|
+
Telegram documentation: https://core.telegram.org/bots/api#createchatsubscriptioninvitelink
|
|
4225
|
+
|
|
4226
|
+
:param chat_id: Unique identifier for the target channel chat or username of the target channel
|
|
4227
|
+
(in the format @channelusername)
|
|
4228
|
+
:type chat_id: :obj:`int` or :obj:`str`
|
|
4229
|
+
|
|
4230
|
+
:param name: Invite link name; 0-32 characters
|
|
4231
|
+
:type name: :obj:`str`
|
|
4232
|
+
|
|
4233
|
+
:param subscription_period: The number of seconds the subscription will be active for before the next payment.
|
|
4234
|
+
Currently, it must always be 2592000 (30 days).
|
|
4235
|
+
:type subscription_period: :obj:`int`
|
|
4236
|
+
|
|
4237
|
+
:param subscription_price: The amount of Telegram Stars a user must pay initially and after each subsequent
|
|
4238
|
+
subscription period to be a member of the chat; 1-2500
|
|
4239
|
+
:type subscription_price: :obj:`int`
|
|
4240
|
+
|
|
4241
|
+
:return: Returns the new invite link as a ChatInviteLink object.
|
|
4242
|
+
:rtype: :class:`telebot.types.ChatInviteLink`
|
|
4243
|
+
"""
|
|
4244
|
+
return types.ChatInviteLink.de_json(
|
|
4245
|
+
apihelper.create_chat_subscription_invite_link(self.token, chat_id, subscription_period, subscription_price, name=name)
|
|
4246
|
+
)
|
|
4247
|
+
|
|
4248
|
+
def edit_chat_subscription_invite_link(
|
|
4249
|
+
self, chat_id: Union[int, str], invite_link: str, name: Optional[str]=None) -> types.ChatInviteLink:
|
|
4250
|
+
"""
|
|
4251
|
+
Use this method to edit a subscription invite link created by the bot. The bot must have the can_invite_users administrator rights.
|
|
4252
|
+
Returns the edited invite link as a ChatInviteLink object.
|
|
4253
|
+
|
|
4254
|
+
Telegram documentation: https://core.telegram.org/bots/api#editchatsubscriptioninvitelink
|
|
4255
|
+
|
|
4256
|
+
:param chat_id: Unique identifier for the target chat or username of the target channel
|
|
4257
|
+
(in the format @channelusername)
|
|
4258
|
+
:type chat_id: :obj:`int` or :obj:`str`
|
|
4259
|
+
|
|
4260
|
+
:param invite_link: The invite link to edit
|
|
4261
|
+
:type invite_link: :obj:`str`
|
|
4262
|
+
|
|
4263
|
+
:param name: Invite link name; 0-32 characters
|
|
4264
|
+
:type name: :obj:`str`
|
|
4265
|
+
|
|
4266
|
+
:return: Returns the edited invite link as a ChatInviteLink object.
|
|
4267
|
+
:rtype: :class:`telebot.types.ChatInviteLink`
|
|
4268
|
+
"""
|
|
4269
|
+
return types.ChatInviteLink.de_json(
|
|
4270
|
+
apihelper.edit_chat_subscription_invite_link(self.token, chat_id, invite_link, name=name)
|
|
4271
|
+
)
|
|
4188
4272
|
|
|
4189
4273
|
def revoke_chat_invite_link(
|
|
4190
4274
|
self, chat_id: Union[int, str], invite_link: str) -> types.ChatInviteLink:
|
|
@@ -5557,7 +5641,7 @@ class TeleBot:
|
|
|
5557
5641
|
|
|
5558
5642
|
|
|
5559
5643
|
def answer_pre_checkout_query(
|
|
5560
|
-
self, pre_checkout_query_id:
|
|
5644
|
+
self, pre_checkout_query_id: str, ok: bool,
|
|
5561
5645
|
error_message: Optional[str]=None) -> bool:
|
|
5562
5646
|
"""
|
|
5563
5647
|
Once the user has confirmed their payment and shipping details, the Bot API sends the final confirmation in the form of an Update with the
|
|
@@ -6642,7 +6726,9 @@ class TeleBot:
|
|
|
6642
6726
|
self.middlewares.append(middleware)
|
|
6643
6727
|
|
|
6644
6728
|
|
|
6645
|
-
def set_state(self, user_id: int, state: Union[
|
|
6729
|
+
def set_state(self, user_id: int, state: Union[str, State], chat_id: Optional[int]=None,
|
|
6730
|
+
business_connection_id: Optional[str]=None, message_thread_id: Optional[int]=None,
|
|
6731
|
+
bot_id: Optional[int]=None) -> bool:
|
|
6646
6732
|
"""
|
|
6647
6733
|
Sets a new state of a user.
|
|
6648
6734
|
|
|
@@ -6652,25 +6738,49 @@ class TeleBot:
|
|
|
6652
6738
|
Otherwise, if you only set user_id, chat_id will equal to user_id, this means that
|
|
6653
6739
|
state will be set for the user in his private chat with a bot.
|
|
6654
6740
|
|
|
6741
|
+
.. versionchanged:: 4.23.0
|
|
6742
|
+
|
|
6743
|
+
Added additional parameters to support topics, business connections, and message threads.
|
|
6744
|
+
|
|
6745
|
+
.. seealso::
|
|
6746
|
+
|
|
6747
|
+
For more details, visit the `custom_states.py example <https://github.com/eternnoir/pyTelegramBotAPI/blob/master/examples/custom_states.py>`_.
|
|
6748
|
+
|
|
6655
6749
|
:param user_id: User's identifier
|
|
6656
6750
|
:type user_id: :obj:`int`
|
|
6657
6751
|
|
|
6658
|
-
:param state: new state. can be string,
|
|
6752
|
+
:param state: new state. can be string, or :class:`telebot.types.State`
|
|
6659
6753
|
:type state: :obj:`int` or :obj:`str` or :class:`telebot.types.State`
|
|
6660
6754
|
|
|
6661
6755
|
:param chat_id: Chat's identifier
|
|
6662
6756
|
:type chat_id: :obj:`int`
|
|
6663
6757
|
|
|
6664
|
-
:
|
|
6758
|
+
:param bot_id: Bot's identifier, defaults to current bot id
|
|
6759
|
+
:type bot_id: :obj:`int`
|
|
6760
|
+
|
|
6761
|
+
:param business_connection_id: Business identifier
|
|
6762
|
+
:type business_connection_id: :obj:`str`
|
|
6763
|
+
|
|
6764
|
+
:param message_thread_id: Identifier of the message thread
|
|
6765
|
+
:type message_thread_id: :obj:`int`
|
|
6766
|
+
|
|
6767
|
+
:return: True on success
|
|
6768
|
+
:rtype: :obj:`bool`
|
|
6665
6769
|
"""
|
|
6666
6770
|
if chat_id is None:
|
|
6667
6771
|
chat_id = user_id
|
|
6668
|
-
|
|
6772
|
+
if bot_id is None:
|
|
6773
|
+
bot_id = self.bot_id
|
|
6774
|
+
return self.current_states.set_state(
|
|
6775
|
+
chat_id=chat_id, user_id=user_id, state=state, bot_id=bot_id,
|
|
6776
|
+
business_connection_id=business_connection_id, message_thread_id=message_thread_id)
|
|
6669
6777
|
|
|
6670
6778
|
|
|
6671
|
-
def reset_data(self, user_id: int, chat_id: Optional[int]=None
|
|
6779
|
+
def reset_data(self, user_id: int, chat_id: Optional[int]=None,
|
|
6780
|
+
business_connection_id: Optional[str]=None,
|
|
6781
|
+
message_thread_id: Optional[int]=None, bot_id: Optional[int]=None) -> bool:
|
|
6672
6782
|
"""
|
|
6673
|
-
Reset data for a user in chat.
|
|
6783
|
+
Reset data for a user in chat: sets the 'data' field to an empty dictionary.
|
|
6674
6784
|
|
|
6675
6785
|
:param user_id: User's identifier
|
|
6676
6786
|
:type user_id: :obj:`int`
|
|
@@ -6678,16 +6788,34 @@ class TeleBot:
|
|
|
6678
6788
|
:param chat_id: Chat's identifier
|
|
6679
6789
|
:type chat_id: :obj:`int`
|
|
6680
6790
|
|
|
6681
|
-
:
|
|
6791
|
+
:param bot_id: Bot's identifier, defaults to current bot id
|
|
6792
|
+
:type bot_id: :obj:`int`
|
|
6793
|
+
|
|
6794
|
+
:param business_connection_id: Business identifier
|
|
6795
|
+
:type business_connection_id: :obj:`str`
|
|
6796
|
+
|
|
6797
|
+
:param message_thread_id: Identifier of the message thread
|
|
6798
|
+
:type message_thread_id: :obj:`int`
|
|
6799
|
+
|
|
6800
|
+
:return: True on success
|
|
6801
|
+
:rtype: :obj:`bool`
|
|
6682
6802
|
"""
|
|
6683
6803
|
if chat_id is None:
|
|
6684
6804
|
chat_id = user_id
|
|
6685
|
-
|
|
6805
|
+
if bot_id is None:
|
|
6806
|
+
bot_id = self.bot_id
|
|
6807
|
+
return self.current_states.reset_data(chat_id=chat_id, user_id=user_id, bot_id=bot_id,
|
|
6808
|
+
business_connection_id=business_connection_id, message_thread_id=message_thread_id)
|
|
6686
6809
|
|
|
6687
6810
|
|
|
6688
|
-
def delete_state(self, user_id: int, chat_id: Optional[int]=None
|
|
6811
|
+
def delete_state(self, user_id: int, chat_id: Optional[int]=None, business_connection_id: Optional[str]=None,
|
|
6812
|
+
message_thread_id: Optional[int]=None, bot_id: Optional[int]=None) -> bool:
|
|
6689
6813
|
"""
|
|
6690
|
-
|
|
6814
|
+
Fully deletes the storage record of a user in chat.
|
|
6815
|
+
|
|
6816
|
+
.. warning::
|
|
6817
|
+
|
|
6818
|
+
This does NOT set state to None, but deletes the object from storage.
|
|
6691
6819
|
|
|
6692
6820
|
:param user_id: User's identifier
|
|
6693
6821
|
:type user_id: :obj:`int`
|
|
@@ -6695,14 +6823,19 @@ class TeleBot:
|
|
|
6695
6823
|
:param chat_id: Chat's identifier
|
|
6696
6824
|
:type chat_id: :obj:`int`
|
|
6697
6825
|
|
|
6698
|
-
:return:
|
|
6826
|
+
:return: True on success
|
|
6827
|
+
:rtype: :obj:`bool`
|
|
6699
6828
|
"""
|
|
6700
6829
|
if chat_id is None:
|
|
6701
6830
|
chat_id = user_id
|
|
6702
|
-
|
|
6831
|
+
if bot_id is None:
|
|
6832
|
+
bot_id = self.bot_id
|
|
6833
|
+
return self.current_states.delete_state(chat_id=chat_id, user_id=user_id, bot_id=bot_id,
|
|
6834
|
+
business_connection_id=business_connection_id, message_thread_id=message_thread_id)
|
|
6703
6835
|
|
|
6704
6836
|
|
|
6705
|
-
def retrieve_data(self, user_id: int, chat_id: Optional[int]=None
|
|
6837
|
+
def retrieve_data(self, user_id: int, chat_id: Optional[int]=None, business_connection_id: Optional[str]=None,
|
|
6838
|
+
message_thread_id: Optional[int]=None, bot_id: Optional[int]=None) -> Optional[Dict[str, Any]]:
|
|
6706
6839
|
"""
|
|
6707
6840
|
Returns context manager with data for a user in chat.
|
|
6708
6841
|
|
|
@@ -6712,34 +6845,70 @@ class TeleBot:
|
|
|
6712
6845
|
:param chat_id: Chat's unique identifier, defaults to user_id
|
|
6713
6846
|
:type chat_id: int, optional
|
|
6714
6847
|
|
|
6848
|
+
:param bot_id: Bot's identifier, defaults to current bot id
|
|
6849
|
+
:type bot_id: int, optional
|
|
6850
|
+
|
|
6851
|
+
:param business_connection_id: Business identifier
|
|
6852
|
+
:type business_connection_id: str, optional
|
|
6853
|
+
|
|
6854
|
+
:param message_thread_id: Identifier of the message thread
|
|
6855
|
+
:type message_thread_id: int, optional
|
|
6856
|
+
|
|
6715
6857
|
:return: Context manager with data for a user in chat
|
|
6716
6858
|
:rtype: Optional[Any]
|
|
6717
6859
|
"""
|
|
6718
6860
|
if chat_id is None:
|
|
6719
6861
|
chat_id = user_id
|
|
6720
|
-
|
|
6862
|
+
if bot_id is None:
|
|
6863
|
+
bot_id = self.bot_id
|
|
6864
|
+
return self.current_states.get_interactive_data(chat_id=chat_id, user_id=user_id, bot_id=bot_id,
|
|
6865
|
+
business_connection_id=business_connection_id,
|
|
6866
|
+
message_thread_id=message_thread_id)
|
|
6721
6867
|
|
|
6722
6868
|
|
|
6723
|
-
def get_state(self, user_id: int, chat_id: Optional[int]=None
|
|
6869
|
+
def get_state(self, user_id: int, chat_id: Optional[int]=None,
|
|
6870
|
+
business_connection_id: Optional[str]=None,
|
|
6871
|
+
message_thread_id: Optional[int]=None, bot_id: Optional[int]=None) -> str:
|
|
6724
6872
|
"""
|
|
6725
6873
|
Gets current state of a user.
|
|
6726
6874
|
Not recommended to use this method. But it is ok for debugging.
|
|
6727
6875
|
|
|
6876
|
+
.. warning::
|
|
6877
|
+
|
|
6878
|
+
Even if you are using :class:`telebot.types.State`, this method will return a string.
|
|
6879
|
+
When comparing(not recommended), you should compare this string with :class:`telebot.types.State`.name
|
|
6880
|
+
|
|
6728
6881
|
:param user_id: User's identifier
|
|
6729
6882
|
:type user_id: :obj:`int`
|
|
6730
6883
|
|
|
6731
6884
|
:param chat_id: Chat's identifier
|
|
6732
6885
|
:type chat_id: :obj:`int`
|
|
6733
6886
|
|
|
6887
|
+
:param bot_id: Bot's identifier, defaults to current bot id
|
|
6888
|
+
:type bot_id: :obj:`int`
|
|
6889
|
+
|
|
6890
|
+
:param business_connection_id: Business identifier
|
|
6891
|
+
:type business_connection_id: :obj:`str`
|
|
6892
|
+
|
|
6893
|
+
:param message_thread_id: Identifier of the message thread
|
|
6894
|
+
:type message_thread_id: :obj:`int`
|
|
6895
|
+
|
|
6734
6896
|
:return: state of a user
|
|
6735
6897
|
:rtype: :obj:`int` or :obj:`str` or :class:`telebot.types.State`
|
|
6736
6898
|
"""
|
|
6737
6899
|
if chat_id is None:
|
|
6738
6900
|
chat_id = user_id
|
|
6739
|
-
|
|
6901
|
+
if bot_id is None:
|
|
6902
|
+
bot_id = self.bot_id
|
|
6903
|
+
return self.current_states.get_state(chat_id=chat_id, user_id=user_id, bot_id=bot_id,
|
|
6904
|
+
business_connection_id=business_connection_id, message_thread_id=message_thread_id)
|
|
6740
6905
|
|
|
6741
6906
|
|
|
6742
|
-
def add_data(self, user_id: int, chat_id: Optional[int]=None,
|
|
6907
|
+
def add_data(self, user_id: int, chat_id: Optional[int]=None,
|
|
6908
|
+
business_connection_id: Optional[str]=None,
|
|
6909
|
+
message_thread_id: Optional[int]=None,
|
|
6910
|
+
bot_id: Optional[int]=None,
|
|
6911
|
+
**kwargs) -> None:
|
|
6743
6912
|
"""
|
|
6744
6913
|
Add data to states.
|
|
6745
6914
|
|
|
@@ -6749,13 +6918,25 @@ class TeleBot:
|
|
|
6749
6918
|
:param chat_id: Chat's identifier
|
|
6750
6919
|
:type chat_id: :obj:`int`
|
|
6751
6920
|
|
|
6921
|
+
:param bot_id: Bot's identifier, defaults to current bot id
|
|
6922
|
+
:type bot_id: :obj:`int`
|
|
6923
|
+
|
|
6924
|
+
:param business_connection_id: Business identifier
|
|
6925
|
+
:type business_connection_id: :obj:`str`
|
|
6926
|
+
|
|
6927
|
+
:param message_thread_id: Identifier of the message thread
|
|
6928
|
+
:type message_thread_id: :obj:`int`
|
|
6929
|
+
|
|
6752
6930
|
:param kwargs: Data to add
|
|
6753
6931
|
:return: None
|
|
6754
6932
|
"""
|
|
6755
6933
|
if chat_id is None:
|
|
6756
6934
|
chat_id = user_id
|
|
6935
|
+
if bot_id is None:
|
|
6936
|
+
bot_id = self.bot_id
|
|
6757
6937
|
for key, value in kwargs.items():
|
|
6758
|
-
self.current_states.set_data(chat_id, user_id, key, value
|
|
6938
|
+
self.current_states.set_data(chat_id=chat_id, user_id=user_id, key=key, value=value, bot_id=bot_id,
|
|
6939
|
+
business_connection_id=business_connection_id, message_thread_id=message_thread_id)
|
|
6759
6940
|
|
|
6760
6941
|
|
|
6761
6942
|
def register_next_step_handler_by_chat_id(
|
|
@@ -7868,6 +8049,55 @@ class TeleBot:
|
|
|
7868
8049
|
handler_dict = self._build_handler_dict(callback, func=func, pass_bot=pass_bot, **kwargs)
|
|
7869
8050
|
self.add_pre_checkout_query_handler(handler_dict)
|
|
7870
8051
|
|
|
8052
|
+
def purchased_paid_media_handler(self, func=None, **kwargs):
|
|
8053
|
+
"""
|
|
8054
|
+
Handles new incoming purchased paid media.
|
|
8055
|
+
|
|
8056
|
+
:param func: Function executed as a filter
|
|
8057
|
+
:type func: :obj:`function`
|
|
8058
|
+
|
|
8059
|
+
:param kwargs: Optional keyword arguments(custom filters)
|
|
8060
|
+
|
|
8061
|
+
:return: None
|
|
8062
|
+
"""
|
|
8063
|
+
def decorator(handler):
|
|
8064
|
+
handler_dict = self._build_handler_dict(handler, func=func, **kwargs)
|
|
8065
|
+
self.add_purchased_paid_media_handler(handler_dict)
|
|
8066
|
+
return handler
|
|
8067
|
+
|
|
8068
|
+
return decorator
|
|
8069
|
+
|
|
8070
|
+
def add_purchased_paid_media_handler(self, handler_dict):
|
|
8071
|
+
"""
|
|
8072
|
+
Adds a purchased paid media handler
|
|
8073
|
+
Note that you should use register_purchased_paid_media_handler to add purchased_paid_media_handler to the bot.
|
|
8074
|
+
|
|
8075
|
+
:meta private:
|
|
8076
|
+
|
|
8077
|
+
:param handler_dict:
|
|
8078
|
+
:return:
|
|
8079
|
+
"""
|
|
8080
|
+
self.purchased_paid_media_handlers.append(handler_dict)
|
|
8081
|
+
|
|
8082
|
+
def register_purchased_paid_media_handler(self, callback: Callable, func: Callable, pass_bot: Optional[bool]=False, **kwargs):
|
|
8083
|
+
"""
|
|
8084
|
+
Registers purchased paid media handler.
|
|
8085
|
+
|
|
8086
|
+
:param callback: function to be called
|
|
8087
|
+
:type callback: :obj:`function`
|
|
8088
|
+
|
|
8089
|
+
:param func: Function executed as a filter
|
|
8090
|
+
:type func: :obj:`function`
|
|
8091
|
+
|
|
8092
|
+
:param pass_bot: True if you need to pass TeleBot instance to handler(useful for separating handlers into different files)
|
|
8093
|
+
:type pass_bot: :obj:`bool`
|
|
8094
|
+
|
|
8095
|
+
:param kwargs: Optional keyword arguments(custom filters)
|
|
8096
|
+
|
|
8097
|
+
:return: None
|
|
8098
|
+
"""
|
|
8099
|
+
handler_dict = self._build_handler_dict(callback, func=func, pass_bot=pass_bot, **kwargs)
|
|
8100
|
+
self.add_purchased_paid_media_handler(handler_dict)
|
|
7871
8101
|
|
|
7872
8102
|
def poll_handler(self, func, **kwargs):
|
|
7873
8103
|
"""
|
|
@@ -8757,7 +8987,7 @@ class TeleBot:
|
|
|
8757
8987
|
logger.error("It is not allowed to pass data and values inside data to the handler. Check your handler: {}".format(handler['function']))
|
|
8758
8988
|
return
|
|
8759
8989
|
else:
|
|
8760
|
-
data_copy = copy
|
|
8990
|
+
data_copy = data.copy()
|
|
8761
8991
|
for key in list(data_copy):
|
|
8762
8992
|
# remove data from data_copy if handler does not accept it
|
|
8763
8993
|
if key not in params:
|
telebot/apihelper.py
CHANGED
|
@@ -529,28 +529,33 @@ def send_photo(
|
|
|
529
529
|
def send_paid_media(
|
|
530
530
|
token, chat_id, star_count, media,
|
|
531
531
|
caption=None, parse_mode=None, caption_entities=None, show_caption_above_media=None,
|
|
532
|
-
disable_notification=None, protect_content=None, reply_parameters=None, reply_markup=None
|
|
532
|
+
disable_notification=None, protect_content=None, reply_parameters=None, reply_markup=None,
|
|
533
|
+
business_connection_id=None, payload=None):
|
|
533
534
|
method_url = r'sendPaidMedia'
|
|
534
535
|
media_json, files = convert_input_media_array(media)
|
|
535
|
-
|
|
536
|
+
_payload = {'chat_id': chat_id, 'star_count': star_count, 'media': media_json}
|
|
536
537
|
if caption:
|
|
537
|
-
|
|
538
|
+
_payload['caption'] = caption
|
|
538
539
|
if parse_mode:
|
|
539
|
-
|
|
540
|
+
_payload['parse_mode'] = parse_mode
|
|
540
541
|
if caption_entities:
|
|
541
|
-
|
|
542
|
+
_payload['caption_entities'] = json.dumps(types.MessageEntity.to_list_of_dicts(caption_entities))
|
|
542
543
|
if show_caption_above_media is not None:
|
|
543
|
-
|
|
544
|
+
_payload['show_caption_above_media'] = show_caption_above_media
|
|
544
545
|
if disable_notification is not None:
|
|
545
|
-
|
|
546
|
+
_payload['disable_notification'] = disable_notification
|
|
546
547
|
if protect_content is not None:
|
|
547
|
-
|
|
548
|
+
_payload['protect_content'] = protect_content
|
|
548
549
|
if reply_parameters is not None:
|
|
549
|
-
|
|
550
|
+
_payload['reply_parameters'] = reply_parameters.to_json()
|
|
550
551
|
if reply_markup:
|
|
551
|
-
|
|
552
|
+
_payload['reply_markup'] = _convert_markup(reply_markup)
|
|
553
|
+
if business_connection_id:
|
|
554
|
+
_payload['business_connection_id'] = business_connection_id
|
|
555
|
+
if payload:
|
|
556
|
+
_payload['payload'] = payload
|
|
552
557
|
return _make_request(
|
|
553
|
-
token, method_url, params=
|
|
558
|
+
token, method_url, params=_payload,
|
|
554
559
|
method='post' if files else 'get',
|
|
555
560
|
files=files if files else None)
|
|
556
561
|
|
|
@@ -1202,6 +1207,26 @@ def edit_chat_invite_link(token, chat_id, invite_link, name, expire_date, member
|
|
|
1202
1207
|
|
|
1203
1208
|
return _make_request(token, method_url, params=payload, method='post')
|
|
1204
1209
|
|
|
1210
|
+
def create_chat_subscription_invite_link(token, chat_id, subscription_period, subscription_price, name=None):
|
|
1211
|
+
method_url = 'createChatSubscriptionInviteLink'
|
|
1212
|
+
payload = {
|
|
1213
|
+
'chat_id': chat_id,
|
|
1214
|
+
'subscription_period': subscription_period,
|
|
1215
|
+
'subscription_price': subscription_price
|
|
1216
|
+
}
|
|
1217
|
+
if name:
|
|
1218
|
+
payload['name'] = name
|
|
1219
|
+
return _make_request(token, method_url, params=payload, method='post')
|
|
1220
|
+
|
|
1221
|
+
def edit_chat_subscription_invite_link(token, chat_id, invite_link, name=None):
|
|
1222
|
+
method_url = 'editChatSubscriptionInviteLink'
|
|
1223
|
+
payload = {
|
|
1224
|
+
'chat_id': chat_id,
|
|
1225
|
+
'invite_link': invite_link
|
|
1226
|
+
}
|
|
1227
|
+
if name:
|
|
1228
|
+
payload['name'] = name
|
|
1229
|
+
return _make_request(token, method_url, params=payload, method='post')
|
|
1205
1230
|
|
|
1206
1231
|
def revoke_chat_invite_link(token, chat_id, invite_link):
|
|
1207
1232
|
method_url = 'revokeChatInviteLink'
|