mirror of
https://github.com/eternnoir/pyTelegramBotAPI.git
synced 2023-08-10 21:12:57 +03:00
Long polling updates and combo content types
This commit is contained in:
parent
fa3ca84d24
commit
7a3fd30f6a
@ -52,11 +52,11 @@ def _make_request(token, method_name, method='get', params=None, files=None):
|
|||||||
:param files: Optional files.
|
:param files: Optional files.
|
||||||
:return: The result parsed to a JSON dictionary.
|
:return: The result parsed to a JSON dictionary.
|
||||||
"""
|
"""
|
||||||
if API_URL is None:
|
if API_URL:
|
||||||
request_url = "https://api.telegram.org/bot{0}/{1}".format(token, method_name)
|
|
||||||
else:
|
|
||||||
request_url = API_URL.format(token, method_name)
|
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))
|
logger.debug("Request: method={0} url={1} params={2} files={3}".format(method, request_url, params, files))
|
||||||
read_timeout = READ_TIMEOUT
|
read_timeout = READ_TIMEOUT
|
||||||
connect_timeout = CONNECT_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
|
read_timeout = params.pop('timeout') + 10
|
||||||
if 'connect-timeout' in params:
|
if 'connect-timeout' in params:
|
||||||
connect_timeout = params.pop('connect-timeout') + 10
|
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:
|
if RETRY_ON_ERROR:
|
||||||
got_result = False
|
got_result = False
|
||||||
current_try = 0
|
current_try = 0
|
||||||
@ -235,7 +240,7 @@ def get_updates(token, offset=None, limit=None, timeout=None, allowed_updates=No
|
|||||||
if limit:
|
if limit:
|
||||||
payload['limit'] = limit
|
payload['limit'] = limit
|
||||||
if timeout:
|
if timeout:
|
||||||
payload['timeout'] = timeout
|
payload['long_polling_timeout'] = timeout
|
||||||
if allowed_updates:
|
if allowed_updates:
|
||||||
payload['allowed_updates'] = json.dumps(allowed_updates)
|
payload['allowed_updates'] = json.dumps(allowed_updates)
|
||||||
return _make_request(token, method_url, params=payload)
|
return _make_request(token, method_url, params=payload)
|
||||||
|
@ -21,6 +21,15 @@ logger = logging.getLogger('TeleBot')
|
|||||||
|
|
||||||
thread_local = threading.local()
|
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):
|
class WorkerThread(threading.Thread):
|
||||||
count = 0
|
count = 0
|
||||||
@ -286,7 +295,6 @@ def chunks(lst, n):
|
|||||||
def generate_random_token():
|
def generate_random_token():
|
||||||
return ''.join(random.sample(string.ascii_letters, 16))
|
return ''.join(random.sample(string.ascii_letters, 16))
|
||||||
|
|
||||||
|
|
||||||
def deprecated(func):
|
def deprecated(func):
|
||||||
"""This is a decorator which can be used to mark functions
|
"""This is a decorator which can be used to mark functions
|
||||||
as deprecated. It will result in a warning being emitted
|
as deprecated. It will result in a warning being emitted
|
||||||
|
Loading…
Reference in New Issue
Block a user