From 7a3fd30f6ac7c06e39673665f9ec2817ad64294c Mon Sep 17 00:00:00 2001 From: Badiboy Date: Sat, 7 Nov 2020 12:52:51 +0300 Subject: [PATCH] Long polling updates and combo content types --- telebot/apihelper.py | 17 +++++++++++------ telebot/util.py | 10 +++++++++- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/telebot/apihelper.py b/telebot/apihelper.py index b80a627..ec4ad9b 100644 --- a/telebot/apihelper.py +++ b/telebot/apihelper.py @@ -52,11 +52,11 @@ def _make_request(token, method_name, method='get', params=None, files=None): :param files: Optional files. :return: The result parsed to a JSON dictionary. """ - if API_URL is None: - request_url = "https://api.telegram.org/bot{0}/{1}".format(token, method_name) - else: + if API_URL: request_url = API_URL.format(token, method_name) - + else: + request_url = "https://api.telegram.org/bot{0}/{1}".format(token, method_name) + logger.debug("Request: method={0} url={1} params={2} files={3}".format(method, request_url, params, files)) read_timeout = READ_TIMEOUT connect_timeout = CONNECT_TIMEOUT @@ -67,7 +67,12 @@ def _make_request(token, method_name, method='get', params=None, files=None): read_timeout = params.pop('timeout') + 10 if 'connect-timeout' in params: connect_timeout = params.pop('connect-timeout') + 10 - + if 'long_polling_timeout' in params: + # For getUpdates: the only function with timeout on the BOT API side + params['timeout'] = params.pop('long_polling_timeout') + + + result = None if RETRY_ON_ERROR: got_result = False current_try = 0 @@ -235,7 +240,7 @@ def get_updates(token, offset=None, limit=None, timeout=None, allowed_updates=No if limit: payload['limit'] = limit if timeout: - payload['timeout'] = timeout + payload['long_polling_timeout'] = timeout if allowed_updates: payload['allowed_updates'] = json.dumps(allowed_updates) return _make_request(token, method_url, params=payload) diff --git a/telebot/util.py b/telebot/util.py index 438e8c1..3ad4463 100644 --- a/telebot/util.py +++ b/telebot/util.py @@ -21,6 +21,15 @@ logger = logging.getLogger('TeleBot') thread_local = threading.local() +content_type_media = [ + 'text', 'audio', 'document', 'photo', 'sticker', 'video', 'video_note', 'voice', 'contact', 'dice', 'poll', + 'venue', 'location' +] + +content_type_service = [ + 'new_chat_members', 'left_chat_member', 'new_chat_title', 'new_chat_photo', 'delete_chat_photo', 'group_chat_created', + 'supergroup_chat_created', 'channel_chat_created', 'migrate_to_chat_id', 'migrate_from_chat_id', 'pinned_message' +] class WorkerThread(threading.Thread): count = 0 @@ -286,7 +295,6 @@ def chunks(lst, n): def generate_random_token(): return ''.join(random.sample(string.ascii_letters, 16)) - def deprecated(func): """This is a decorator which can be used to mark functions as deprecated. It will result in a warning being emitted