Skip to content

Commit 6e871b8

Browse files
authored
Merge pull request eternnoir#1270 from Badiboy/master
Check and update for full compatibility to Bot API up to 5.3
2 parents 3232811 + f6359bc commit 6e871b8

File tree

8 files changed

+62
-30
lines changed

8 files changed

+62
-30
lines changed

README.md

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1-
# <p align="center">pyTelegramBotAPI
2-
3-
<p align="center">A simple, but extensible Python implementation for the <a href="https://core.telegram.org/bots/api">Telegram Bot API</a>.
41

52
[![PyPi Package Version](https://img.shields.io/pypi/v/pyTelegramBotAPI.svg)](https://pypi.python.org/pypi/pyTelegramBotAPI)
63
[![Supported Python versions](https://img.shields.io/pypi/pyversions/pyTelegramBotAPI.svg)](https://pypi.python.org/pypi/pyTelegramBotAPI)
74
[![Build Status](https://travis-ci.org/eternnoir/pyTelegramBotAPI.svg?branch=master)](https://travis-ci.org/eternnoir/pyTelegramBotAPI)
85
[![PyPi downloads](https://img.shields.io/pypi/dm/pyTelegramBotAPI.svg)](https://pypi.org/project/pyTelegramBotAPI/)
96

7+
# <p align="center">pyTelegramBotAPI
8+
9+
<p align="center">A simple, but extensible Python implementation for the <a href="https://core.telegram.org/bots/api">Telegram Bot API</a>.
10+
11+
## <p align="center">Supported Bot API version: <a href="https://core.telegram.org/bots/api#june-25-2021">5.3</a>!
12+
13+
##Contents
14+
1015
* [Getting started.](#getting-started)
1116
* [Writing your first bot](#writing-your-first-bot)
1217
* [Prerequisites](#prerequisites)
@@ -603,21 +608,20 @@ apihelper.proxy = {'https':'socks5://userproxy:password@proxy_address:port'}
603608

604609
## API conformance
605610

606-
_Checking is in progress..._
607-
608-
[Bot API 5.1](https://core.telegram.org/bots/api#march-9-2021) _- To be checked..._
609-
611+
*[Bot API 5.3](https://core.telegram.org/bots/api#june-25-2021) - ChatMemberXXX classes are full copies of ChatMember
612+
*[Bot API 5.2](https://core.telegram.org/bots/api#april-26-2021)
613+
*[Bot API 5.1](https://core.telegram.org/bots/api#march-9-2021)
610614
*[Bot API 5.0](https://core.telegram.org/bots/api-changelog#november-4-2020)
611615
*[Bot API 4.9](https://core.telegram.org/bots/api-changelog#june-4-2020)
612616
*[Bot API 4.8](https://core.telegram.org/bots/api-changelog#april-24-2020)
613617
*[Bot API 4.7](https://core.telegram.org/bots/api-changelog#march-30-2020)
614618
*[Bot API 4.6](https://core.telegram.org/bots/api-changelog#january-23-2020)
615-
*[Bot API 4.5](https://core.telegram.org/bots/api-changelog#december-31-2019) - No nested MessageEntities and Markdown2 support.
619+
*[Bot API 4.5](https://core.telegram.org/bots/api-changelog#december-31-2019) - No nested MessageEntities and Markdown2 support
616620
*[Bot API 4.4](https://core.telegram.org/bots/api-changelog#july-29-2019)
617621
*[Bot API 4.3](https://core.telegram.org/bots/api-changelog#may-31-2019)
618622
*[Bot API 4.2](https://core.telegram.org/bots/api-changelog#april-14-2019)
619-
*[Bot API 4.1](https://core.telegram.org/bots/api-changelog#august-27-2018) - No Passport support.
620-
*[Bot API 4.0](https://core.telegram.org/bots/api-changelog#july-26-2018) - No Passport support.
623+
*[Bot API 4.1](https://core.telegram.org/bots/api-changelog#august-27-2018) - No Passport support
624+
*[Bot API 4.0](https://core.telegram.org/bots/api-changelog#july-26-2018) - No Passport support
621625
*[Bot API 3.6](https://core.telegram.org/bots/api-changelog#february-13-2018)
622626
*[Bot API 3.5](https://core.telegram.org/bots/api-changelog#november-17-2017)
623627
*[Bot API 3.4](https://core.telegram.org/bots/api-changelog#october-11-2017)

requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
py==1.10.0
21
pytest==3.0.2
32
requests==2.20.0
43
wheel==0.24.0

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def read(filename):
2525
install_requires=['requests'],
2626
extras_require={
2727
'json': 'ujson',
28+
'PIL': 'Pillow',
2829
'redis': 'redis>=3.4.1'
2930
},
3031
classifiers=[

telebot/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# -*- coding: utf-8 -*-
2-
from __future__ import print_function
32
from datetime import datetime
43

54
import logging
@@ -1986,7 +1985,7 @@ def send_invoice(
19861985
timeout: Optional[int]=None,
19871986
allow_sending_without_reply: Optional[bool]=None,
19881987
max_tip_amount: Optional[int] = None,
1989-
suggested_tip_amounts: Optional[list]=None) -> types.Message:
1988+
suggested_tip_amounts: Optional[List[int]]=None) -> types.Message:
19901989
"""
19911990
Sends invoice
19921991
:param chat_id: Unique identifier for the target private chat

telebot/apihelper.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -973,11 +973,11 @@ def create_chat_invite_link(token, chat_id, expire_date, member_limit):
973973
}
974974

975975
if expire_date is not None:
976-
payload['expire_date'] = expire_date
977976
if isinstance(payload['expire_date'], datetime):
978977
payload['expire_date'] = payload['expire_date'].timestamp()
979-
980-
if member_limit is not None:
978+
else:
979+
payload['expire_date'] = expire_date
980+
if member_limit:
981981
payload['member_limit'] = member_limit
982982

983983
return _make_request(token, method_url, params=payload, method='post')
@@ -991,9 +991,10 @@ def edit_chat_invite_link(token, chat_id, invite_link, expire_date, member_limit
991991
}
992992

993993
if expire_date is not None:
994-
payload['expire_date'] = expire_date
995994
if isinstance(payload['expire_date'], datetime):
996995
payload['expire_date'] = payload['expire_date'].timestamp()
996+
else:
997+
payload['expire_date'] = expire_date
997998

998999
if member_limit is not None:
9991000
payload['member_limit'] = member_limit
@@ -1258,7 +1259,7 @@ def get_game_high_scores(token, user_id, chat_id=None, message_id=None, inline_m
12581259

12591260
def send_invoice(
12601261
token, chat_id, title, description, invoice_payload, provider_token, currency, prices,
1261-
start_parameter, photo_url=None, photo_size=None, photo_width=None, photo_height=None,
1262+
start_parameter = None, photo_url=None, photo_size=None, photo_width=None, photo_height=None,
12621263
need_name=None, need_phone_number=None, need_email=None, need_shipping_address=None,
12631264
send_phone_number_to_provider = None, send_email_to_provider = None, is_flexible=None,
12641265
disable_notification=None, reply_to_message_id=None, reply_markup=None, provider_data=None,
@@ -1298,8 +1299,10 @@ def send_invoice(
12981299
"""
12991300
method_url = r'sendInvoice'
13001301
payload = {'chat_id': chat_id, 'title': title, 'description': description, 'payload': invoice_payload,
1301-
'provider_token': provider_token, 'start_parameter': start_parameter, 'currency': currency,
1302+
'provider_token': provider_token, 'currency': currency,
13021303
'prices': _convert_list_json_serializable(prices)}
1304+
if start_parameter:
1305+
payload['start_parameter'] = start_parameter
13031306
if photo_url:
13041307
payload['photo_url'] = photo_url
13051308
if photo_size:

telebot/types.py

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -441,12 +441,10 @@ def de_json(cls, json_string):
441441
opts['voice_chat_ended'] = VoiceChatEnded.de_json(obj['voice_chat_ended'])
442442
content_type = 'voice_chat_ended'
443443
if 'voice_chat_participants_invited' in obj:
444-
opts['voice_chat_participants_invited'] = VoiceChatParticipantsInvited.de_json(
445-
obj['voice_chat_participants_invited'])
444+
opts['voice_chat_participants_invited'] = VoiceChatParticipantsInvited.de_json(obj['voice_chat_participants_invited'])
446445
content_type = 'voice_chat_participants_invited'
447446
if 'message_auto_delete_timer_changed' in obj:
448-
opts['message_auto_delete_timer_changed'] = MessageAutoDeleteTimerChanged.de_json(
449-
obj['message_auto_delete_timer_changed'])
447+
opts['message_auto_delete_timer_changed'] = MessageAutoDeleteTimerChanged.de_json(obj['message_auto_delete_timer_changed'])
450448
content_type = 'message_auto_delete_timer_changed'
451449
if 'reply_markup' in obj:
452450
opts['reply_markup'] = InlineKeyboardMarkup.de_json(obj['reply_markup'])
@@ -1232,6 +1230,29 @@ def __init__(self, user, status, custom_title=None, is_anonymous=None, can_be_ed
12321230
self.until_date: int = until_date
12331231

12341232

1233+
class ChatMemberOwner(ChatMember):
1234+
pass
1235+
1236+
class ChatMemberAdministrator(ChatMember):
1237+
pass
1238+
1239+
1240+
class ChatMemberMember(ChatMember):
1241+
pass
1242+
1243+
1244+
class ChatMemberRestricted(ChatMember):
1245+
pass
1246+
1247+
1248+
class ChatMemberLeft(ChatMember):
1249+
pass
1250+
1251+
1252+
class ChatMemberBanned(ChatMember):
1253+
pass
1254+
1255+
12351256
class ChatPermissions(JsonDeserializable, JsonSerializable, Dictionaryable):
12361257
@classmethod
12371258
def de_json(cls, json_string):
@@ -2744,14 +2765,18 @@ def to_json(self):
27442765
return json.dumps(self.to_dict())
27452766

27462767
def to_dict(self):
2747-
return {
2768+
json_dict = {
27482769
"invite_link": self.invite_link,
27492770
"creator": self.creator.to_dict(),
27502771
"is_primary": self.is_primary,
2751-
"is_revoked": self.is_revoked,
2752-
"expire_date": self.expire_date,
2753-
"member_limit": self.member_limit
2772+
"is_revoked": self.is_revoked
27542773
}
2774+
if self.expire_date:
2775+
json_dict["expire_date"] = self.expire_date
2776+
if self.member_limit:
2777+
json_dict["member_limit"] = self.member_limit
2778+
return json_dict
2779+
27552780

27562781
class ProximityAlertTriggered(JsonDeserializable):
27572782
@classmethod
@@ -2778,6 +2803,7 @@ def __init__(self):
27782803
"""
27792804
pass
27802805

2806+
27812807
class VoiceChatScheduled(JsonDeserializable):
27822808
@classmethod
27832809
def de_json(cls, json_string):

telebot/util.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44
import string
55
import threading
66
import traceback
7-
import warnings
8-
import functools
97
from typing import Any, Callable, List, Dict, Optional, Union
108

9+
# noinspection PyPep8Naming
1110
import queue as Queue
1211
import logging
1312

1413
from telebot import types
1514

1615
try:
16+
# noinspection PyPackageRequirements
1717
from PIL import Image
1818
from io import BytesIO
1919
pil_imported = True

telebot/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Versions should comply with PEP440.
22
# This line is parsed in setup.py:
3-
__version__ = '3.8.2'
3+
__version__ = '3.8.3'

0 commit comments

Comments
 (0)