Skip to content

Commit 24b1129

Browse files
authored
Merge pull request #1584 from coder2020official/master
Bot API 6.1 update
2 parents f96775e + 7f9dac4 commit 24b1129

File tree

9 files changed

+242
-15
lines changed

9 files changed

+242
-15
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<p align="center">A simple, but extensible Python implementation for the <a href="https://core.telegram.org/bots/api">Telegram Bot API</a>.</p>
1212
<p align="center">Both synchronous and asynchronous.</p>
1313

14-
## <p align="center">Supported Bot API version: <a href="https://core.telegram.org/bots/api#april-16-2022">6.0</a>!
14+
## <p align="center">Supported Bot API version: <a href="https://core.telegram.org/bots/api#june-20-2022">6.1</a>!
1515

1616
<h2><a href='https://pytba.readthedocs.io/en/latest/index.html'>Official documentation</a></h2>
1717

@@ -727,6 +727,7 @@ Result will be:
727727

728728

729729
## API conformance
730+
*[Bot API 6.1](https://core.telegram.org/bots/api#june-20-2022)
730731
*[Bot API 6.0](https://core.telegram.org/bots/api#april-16-2022)
731732
*[Bot API 5.7](https://core.telegram.org/bots/api#january-31-2022)
732733
*[Bot API 5.6](https://core.telegram.org/bots/api#december-30-2021)

docs/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
author = 'coder2020official'
2323

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

2727

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

telebot/__init__.py

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ def load_reply_handlers(self, filename="./.handler-saves/reply.save", del_file_a
261261
self.reply_backend.load_handlers(filename, del_file_after_loading)
262262

263263
def set_webhook(self, url=None, certificate=None, max_connections=None, allowed_updates=None, ip_address=None,
264-
drop_pending_updates = None, timeout=None):
264+
drop_pending_updates = None, timeout=None, secret_token=None):
265265
"""
266266
Use this method to specify a url and receive incoming updates via an outgoing webhook. Whenever there is an
267267
update for the bot, we will send an HTTPS POST request to the specified url,
@@ -286,10 +286,11 @@ def set_webhook(self, url=None, certificate=None, max_connections=None, allowed_
286286
resolved through DNS
287287
:param drop_pending_updates: Pass True to drop all pending updates
288288
:param timeout: Integer. Request connection timeout
289+
:param secret_token: Secret token to be used to verify the webhook request.
289290
:return: API reply.
290291
"""
291292
return apihelper.set_webhook(self.token, url, certificate, max_connections, allowed_updates, ip_address,
292-
drop_pending_updates, timeout)
293+
drop_pending_updates, timeout, secret_token)
293294

294295
def delete_webhook(self, drop_pending_updates=None, timeout=None):
295296
"""
@@ -2462,6 +2463,69 @@ def send_invoice(
24622463
max_tip_amount, suggested_tip_amounts, protect_content)
24632464
return types.Message.de_json(result)
24642465

2466+
2467+
def create_invoice_link(self,
2468+
title: str, description: str, payload:str, provider_token: str,
2469+
currency: str, prices: List[types.LabeledPrice],
2470+
max_tip_amount: Optional[int] = None,
2471+
suggested_tip_amounts: Optional[List[int]]=None,
2472+
provider_data: Optional[str]=None,
2473+
photo_url: Optional[str]=None,
2474+
photo_size: Optional[int]=None,
2475+
photo_width: Optional[int]=None,
2476+
photo_height: Optional[int]=None,
2477+
need_name: Optional[bool]=None,
2478+
need_phone_number: Optional[bool]=None,
2479+
need_email: Optional[bool]=None,
2480+
need_shipping_address: Optional[bool]=None,
2481+
send_phone_number_to_provider: Optional[bool]=None,
2482+
send_email_to_provider: Optional[bool]=None,
2483+
is_flexible: Optional[bool]=None) -> str:
2484+
2485+
"""
2486+
Use this method to create a link for an invoice.
2487+
Returns the created invoice link as String on success.
2488+
2489+
Telegram documentation:
2490+
https://core.telegram.org/bots/api#createinvoicelink
2491+
2492+
:param title: Product name, 1-32 characters
2493+
:param description: Product description, 1-255 characters
2494+
:param payload: Bot-defined invoice payload, 1-128 bytes. This will not be displayed to the user,
2495+
use for your internal processes.
2496+
:param provider_token: Payments provider token, obtained via @Botfather
2497+
:param currency: Three-letter ISO 4217 currency code,
2498+
see https://core.telegram.org/bots/payments#supported-currencies
2499+
:param prices: Price breakdown, a list of components
2500+
(e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.)
2501+
:param max_tip_amount: The maximum accepted amount for tips in the smallest units of the currency
2502+
:param suggested_tip_amounts: A JSON-serialized array of suggested amounts of tips in the smallest
2503+
:param provider_data: A JSON-serialized data about the invoice, which will be shared with the payment provider.
2504+
A detailed description of required fields should be provided by the payment provider.
2505+
:param photo_url: URL of the product photo for the invoice. Can be a photo of the goods
2506+
:param photo_size: Photo size in bytes
2507+
:param photo_width: Photo width
2508+
:param photo_height: Photo height
2509+
:param need_name: Pass True, if you require the user's full name to complete the order
2510+
:param need_phone_number: Pass True, if you require the user's phone number to complete the order
2511+
:param need_email: Pass True, if you require the user's email to complete the order
2512+
:param need_shipping_address: Pass True, if you require the user's shipping address to complete the order
2513+
:param send_phone_number_to_provider: Pass True, if user's phone number should be sent to provider
2514+
:param send_email_to_provider: Pass True, if user's email address should be sent to provider
2515+
:param is_flexible: Pass True, if the final price depends on the shipping method
2516+
2517+
:return: Created invoice link as String on success.
2518+
"""
2519+
result = apihelper.create_invoice_link(
2520+
self.token, title, description, payload, provider_token,
2521+
currency, prices, max_tip_amount, suggested_tip_amounts, provider_data,
2522+
photo_url, photo_size, photo_width, photo_height, need_name, need_phone_number,
2523+
need_email, need_shipping_address, send_phone_number_to_provider,
2524+
send_email_to_provider, is_flexible)
2525+
return result
2526+
2527+
2528+
24652529
# noinspection PyShadowingBuiltins
24662530
# TODO: rewrite this method like in API
24672531
def send_poll(

telebot/apihelper.py

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ def send_message(
268268

269269

270270
def set_webhook(token, url=None, certificate=None, max_connections=None, allowed_updates=None, ip_address=None,
271-
drop_pending_updates = None, timeout=None):
271+
drop_pending_updates = None, timeout=None, secret_token=None):
272272
method_url = r'setWebhook'
273273
payload = {
274274
'url': url if url else "",
@@ -286,6 +286,8 @@ def set_webhook(token, url=None, certificate=None, max_connections=None, allowed
286286
payload['drop_pending_updates'] = drop_pending_updates
287287
if timeout:
288288
payload['timeout'] = timeout
289+
if secret_token:
290+
payload['secret_token'] = secret_token
289291
return _make_request(token, method_url, params=payload, files=files)
290292

291293

@@ -1622,6 +1624,45 @@ def answer_web_app_query(token, web_app_query_id, result: types.InlineQueryResul
16221624
return _make_request(token, method_url, params=payload, method='post')
16231625

16241626

1627+
def create_invoice_link(token, title, description, payload, provider_token,
1628+
currency, prices, max_tip_amount=None, suggested_tip_amounts=None, provider_data=None,
1629+
photo_url=None, photo_size=None, photo_width=None, photo_height=None, need_name=None, need_phone_number=None,
1630+
need_email=None, need_shipping_address=None, send_phone_number_to_provider=None,
1631+
send_email_to_provider=None, is_flexible=None):
1632+
method_url = r'createInvoiceLink'
1633+
payload = {'title': title, 'description': description, 'payload': payload, 'provider_token': provider_token,
1634+
'currency': currency, 'prices': _convert_list_json_serializable(prices)}
1635+
if max_tip_amount:
1636+
payload['max_tip_amount'] = max_tip_amount
1637+
if suggested_tip_amounts:
1638+
payload['suggested_tip_amounts'] = json.dumps(suggested_tip_amounts)
1639+
if provider_data:
1640+
payload['provider_data'] = provider_data
1641+
if photo_url:
1642+
payload['photo_url'] = photo_url
1643+
if photo_size:
1644+
payload['photo_size'] = photo_size
1645+
if photo_width:
1646+
payload['photo_width'] = photo_width
1647+
if photo_height:
1648+
payload['photo_height'] = photo_height
1649+
if need_name is not None:
1650+
payload['need_name'] = need_name
1651+
if need_phone_number is not None:
1652+
payload['need_phone_number'] = need_phone_number
1653+
if need_email is not None:
1654+
payload['need_email'] = need_email
1655+
if need_shipping_address is not None:
1656+
payload['need_shipping_address'] = need_shipping_address
1657+
if send_phone_number_to_provider is not None:
1658+
payload['send_phone_number_to_provider'] = send_phone_number_to_provider
1659+
if send_email_to_provider is not None:
1660+
payload['send_email_to_provider'] = send_email_to_provider
1661+
if is_flexible is not None:
1662+
payload['is_flexible'] = is_flexible
1663+
return _make_request(token, method_url, params=payload, method='post')
1664+
1665+
16251666
# noinspection PyShadowingBuiltins
16261667
def send_poll(
16271668
token, chat_id,

telebot/async_telebot.py

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,7 +1384,7 @@ def enable_saving_states(self, filename="./.state-save/states.pkl"):
13841384
self.current_states = StatePickleStorage(file_path=filename)
13851385

13861386
async def set_webhook(self, url=None, certificate=None, max_connections=None, allowed_updates=None, ip_address=None,
1387-
drop_pending_updates = None, timeout=None):
1387+
drop_pending_updates = None, timeout=None, secret_token=None):
13881388
"""
13891389
Use this method to specify a url and receive incoming updates via an outgoing webhook. Whenever there is an
13901390
update for the bot, we will send an HTTPS POST request to the specified url,
@@ -1409,10 +1409,11 @@ async def set_webhook(self, url=None, certificate=None, max_connections=None, al
14091409
resolved through DNS
14101410
:param drop_pending_updates: Pass True to drop all pending updates
14111411
:param timeout: Integer. Request connection timeout
1412+
:param secret_token: Secret token to be used to verify the webhook
14121413
:return:
14131414
"""
14141415
return await asyncio_helper.set_webhook(self.token, url, certificate, max_connections, allowed_updates, ip_address,
1415-
drop_pending_updates, timeout)
1416+
drop_pending_updates, timeout, secret_token)
14161417

14171418

14181419

@@ -3066,6 +3067,67 @@ async def send_invoice(
30663067
max_tip_amount, suggested_tip_amounts, protect_content)
30673068
return types.Message.de_json(result)
30683069

3070+
3071+
async def create_invoice_link(self,
3072+
title: str, description: str, payload:str, provider_token: str,
3073+
currency: str, prices: List[types.LabeledPrice],
3074+
max_tip_amount: Optional[int] = None,
3075+
suggested_tip_amounts: Optional[List[int]]=None,
3076+
provider_data: Optional[str]=None,
3077+
photo_url: Optional[str]=None,
3078+
photo_size: Optional[int]=None,
3079+
photo_width: Optional[int]=None,
3080+
photo_height: Optional[int]=None,
3081+
need_name: Optional[bool]=None,
3082+
need_phone_number: Optional[bool]=None,
3083+
need_email: Optional[bool]=None,
3084+
need_shipping_address: Optional[bool]=None,
3085+
send_phone_number_to_provider: Optional[bool]=None,
3086+
send_email_to_provider: Optional[bool]=None,
3087+
is_flexible: Optional[bool]=None) -> str:
3088+
3089+
"""
3090+
Use this method to create a link for an invoice.
3091+
Returns the created invoice link as String on success.
3092+
3093+
Telegram documentation:
3094+
https://core.telegram.org/bots/api#createinvoicelink
3095+
3096+
:param title: Product name, 1-32 characters
3097+
:param description: Product description, 1-255 characters
3098+
:param payload: Bot-defined invoice payload, 1-128 bytes. This will not be displayed to the user,
3099+
use for your internal processes.
3100+
:param provider_token: Payments provider token, obtained via @Botfather
3101+
:param currency: Three-letter ISO 4217 currency code,
3102+
see https://core.telegram.org/bots/payments#supported-currencies
3103+
:param prices: Price breakdown, a list of components
3104+
(e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.)
3105+
:param max_tip_amount: The maximum accepted amount for tips in the smallest units of the currency
3106+
:param suggested_tip_amounts: A JSON-serialized array of suggested amounts of tips in the smallest
3107+
:param provider_data: A JSON-serialized data about the invoice, which will be shared with the payment provider.
3108+
A detailed description of required fields should be provided by the payment provider.
3109+
:param photo_url: URL of the product photo for the invoice. Can be a photo of the goods
3110+
:param photo_size: Photo size in bytes
3111+
:param photo_width: Photo width
3112+
:param photo_height: Photo height
3113+
:param need_name: Pass True, if you require the user's full name to complete the order
3114+
:param need_phone_number: Pass True, if you require the user's phone number to complete the order
3115+
:param need_email: Pass True, if you require the user's email to complete the order
3116+
:param need_shipping_address: Pass True, if you require the user's shipping address to complete the order
3117+
:param send_phone_number_to_provider: Pass True, if user's phone number should be sent to provider
3118+
:param send_email_to_provider: Pass True, if user's email address should be sent to provider
3119+
:param is_flexible: Pass True, if the final price depends on the shipping method
3120+
3121+
:return: Created invoice link as String on success.
3122+
"""
3123+
result = await asyncio_helper.create_invoice_link(
3124+
self.token, title, description, payload, provider_token,
3125+
currency, prices, max_tip_amount, suggested_tip_amounts, provider_data,
3126+
photo_url, photo_size, photo_width, photo_height, need_name, need_phone_number,
3127+
need_email, need_shipping_address, send_phone_number_to_provider,
3128+
send_email_to_provider, is_flexible)
3129+
return result
3130+
30693131
# noinspection PyShadowingBuiltins
30703132
async def send_poll(
30713133
self, chat_id: Union[int, str], question: str, options: List[str],

telebot/asyncio_helper.py

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ async def download_file(token, file_path):
171171

172172

173173
async def set_webhook(token, url=None, certificate=None, max_connections=None, allowed_updates=None, ip_address=None,
174-
drop_pending_updates = None, timeout=None):
174+
drop_pending_updates = None, timeout=None, secret_token=None):
175175
method_url = r'setWebhook'
176176
payload = {
177177
'url': url if url else "",
@@ -189,6 +189,8 @@ async def set_webhook(token, url=None, certificate=None, max_connections=None, a
189189
payload['drop_pending_updates'] = drop_pending_updates
190190
if timeout:
191191
payload['timeout'] = timeout
192+
if secret_token:
193+
payload['secret_token'] = secret_token
192194
return await _process_request(token, method_url, params=payload, files=files)
193195

194196

@@ -1599,6 +1601,47 @@ async def delete_sticker_from_set(token, sticker):
15991601
return await _process_request(token, method_url, params=payload, method='post')
16001602

16011603

1604+
1605+
async def create_invoice_link(token, title, description, payload, provider_token,
1606+
currency, prices, max_tip_amount=None, suggested_tip_amounts=None, provider_data=None,
1607+
photo_url=None, photo_size=None, photo_width=None, photo_height=None, need_name=None, need_phone_number=None,
1608+
need_email=None, need_shipping_address=None, send_phone_number_to_provider=None,
1609+
send_email_to_provider=None, is_flexible=None):
1610+
method_url = r'createInvoiceLink'
1611+
payload = {'title': title, 'description': description, 'payload': payload, 'provider_token': provider_token,
1612+
'currency': currency, 'prices': await _convert_list_json_serializable(prices)}
1613+
if max_tip_amount:
1614+
payload['max_tip_amount'] = max_tip_amount
1615+
if suggested_tip_amounts:
1616+
payload['suggested_tip_amounts'] = json.dumps(suggested_tip_amounts)
1617+
if provider_data:
1618+
payload['provider_data'] = provider_data
1619+
if photo_url:
1620+
payload['photo_url'] = photo_url
1621+
if photo_size:
1622+
payload['photo_size'] = photo_size
1623+
if photo_width:
1624+
payload['photo_width'] = photo_width
1625+
if photo_height:
1626+
payload['photo_height'] = photo_height
1627+
if need_name is not None:
1628+
payload['need_name'] = need_name
1629+
if need_phone_number is not None:
1630+
payload['need_phone_number'] = need_phone_number
1631+
if need_email is not None:
1632+
payload['need_email'] = need_email
1633+
if need_shipping_address is not None:
1634+
payload['need_shipping_address'] = need_shipping_address
1635+
if send_phone_number_to_provider is not None:
1636+
payload['send_phone_number_to_provider'] = send_phone_number_to_provider
1637+
if send_email_to_provider is not None:
1638+
payload['send_email_to_provider'] = send_email_to_provider
1639+
if is_flexible is not None:
1640+
payload['is_flexible'] = is_flexible
1641+
return await _process_request(token, method_url, params=payload, method='post')
1642+
1643+
1644+
16021645
# noinspection PyShadowingBuiltins
16031646
async def send_poll(
16041647
token, chat_id,

0 commit comments

Comments
 (0)