1
0
mirror of https://github.com/eternnoir/pyTelegramBotAPI.git synced 2023-08-10 21:12:57 +03:00

Added timeout to xxx_webhook

This commit is contained in:
Badiboy 2021-01-07 00:13:44 +03:00
parent 6559f431b7
commit 5dc008a762
2 changed files with 20 additions and 10 deletions

View File

@ -235,7 +235,7 @@ class TeleBot:
""" """
self.reply_backend.load_handlers(filename, del_file_after_loading) self.reply_backend.load_handlers(filename, del_file_after_loading)
def set_webhook(self, url=None, certificate=None, max_connections=None, allowed_updates=None, ip_address=None): def set_webhook(self, url=None, certificate=None, max_connections=None, allowed_updates=None, ip_address=None, timeout=None):
""" """
Use this method to specify a url and receive incoming updates via an outgoing webhook. Whenever there is an Use this method to specify a url and receive incoming updates via an outgoing webhook. Whenever there is an
update for the bot, we will send an HTTPS POST request to the specified url, containing a JSON-serialized Update. update for the bot, we will send an HTTPS POST request to the specified url, containing a JSON-serialized Update.
@ -246,27 +246,30 @@ class TeleBot:
:param max_connections: Maximum allowed number of simultaneous HTTPS connections to the webhook for update delivery, 1-100. Defaults to 40. Use lower values to limit the load on your bot's server, and higher values to increase your bot's throughput. :param max_connections: Maximum allowed number of simultaneous HTTPS connections to the webhook for update delivery, 1-100. Defaults to 40. Use lower values to limit the load on your bot's server, and higher values to increase your bot's throughput.
:param allowed_updates: A JSON-serialized list of the update types you want your bot to receive. For example, specify [message, edited_channel_post, callback_query] to only receive updates of these types. See Update for a complete list of available update types. Specify an empty list to receive all updates regardless of type (default). If not specified, the previous setting will be used. :param allowed_updates: A JSON-serialized list of the update types you want your bot to receive. For example, specify [message, edited_channel_post, callback_query] to only receive updates of these types. See Update for a complete list of available update types. Specify an empty list to receive all updates regardless of type (default). If not specified, the previous setting will be used.
:param ip_address: The fixed IP address which will be used to send webhook requests instead of the IP address resolved through DNS :param ip_address: The fixed IP address which will be used to send webhook requests instead of the IP address resolved through DNS
:param timeout: Integer. Request connection timeout
:return: :return:
""" """
return apihelper.set_webhook(self.token, url, certificate, max_connections, allowed_updates, ip_address) return apihelper.set_webhook(self.token, url, certificate, max_connections, allowed_updates, ip_address, timeout)
def delete_webhook(self, drop_pending_updates=None): def delete_webhook(self, drop_pending_updates=None, timeout=None):
""" """
Use this method to remove webhook integration if you decide to switch back to getUpdates. Use this method to remove webhook integration if you decide to switch back to getUpdates.
:param drop_pending_updates: Pass True to drop all pending updates :param drop_pending_updates: Pass True to drop all pending updates
:param timeout: Integer. Request connection timeout
:return: bool :return: bool
""" """
return apihelper.delete_webhook(self.token, drop_pending_updates) return apihelper.delete_webhook(self.token, drop_pending_updates, timeout)
def get_webhook_info(self): def get_webhook_info(self, timeout=None):
""" """
Use this method to get current webhook status. Requires no parameters. Use this method to get current webhook status. Requires no parameters.
If the bot is using getUpdates, will return an object with the url field empty. If the bot is using getUpdates, will return an object with the url field empty.
:param timeout: Integer. Request connection timeout
:return: On success, returns a WebhookInfo object. :return: On success, returns a WebhookInfo object.
""" """
result = apihelper.get_webhook_info(self.token) result = apihelper.get_webhook_info(self.token, timeout)
return types.WebhookInfo.de_json(result) return types.WebhookInfo.de_json(result)
def remove_webhook(self): def remove_webhook(self):
@ -455,7 +458,8 @@ class TeleBot:
except Exception as e: except Exception as e:
logger.error("Infinity polling exception: {}".format(e)) logger.error("Infinity polling exception: {}".format(e))
time.sleep(3) time.sleep(3)
pass continue
logger.info("Infinity polling: polling exited")
logger.info("Break infinity polling") logger.info("Break infinity polling")
def polling(self, none_stop=False, interval=0, timeout=20, long_polling_timeout=20): def polling(self, none_stop=False, interval=0, timeout=20, long_polling_timeout=20):

View File

@ -206,7 +206,7 @@ def send_message(
return _make_request(token, method_url, params=payload, method='post') return _make_request(token, method_url, params=payload, method='post')
def set_webhook(token, url=None, certificate=None, max_connections=None, allowed_updates=None, ip_address=None): def set_webhook(token, url=None, certificate=None, max_connections=None, allowed_updates=None, ip_address=None, timeout=None):
method_url = r'setWebhook' method_url = r'setWebhook'
payload = { payload = {
'url': url if url else "", 'url': url if url else "",
@ -220,20 +220,26 @@ def set_webhook(token, url=None, certificate=None, max_connections=None, allowed
payload['allowed_updates'] = json.dumps(allowed_updates) payload['allowed_updates'] = json.dumps(allowed_updates)
if ip_address is not None: # Empty string should pass if ip_address is not None: # Empty string should pass
payload['ip_address'] = ip_address payload['ip_address'] = ip_address
if timeout:
payload['connect-timeout'] = timeout
return _make_request(token, method_url, params=payload, files=files) return _make_request(token, method_url, params=payload, files=files)
def delete_webhook(token, drop_pending_updates=None): def delete_webhook(token, drop_pending_updates=None, timeout=None):
method_url = r'deleteWebhook' method_url = r'deleteWebhook'
payload = {} payload = {}
if drop_pending_updates is not None: # None / True / False if drop_pending_updates is not None: # None / True / False
payload['drop_pending_updates'] = drop_pending_updates payload['drop_pending_updates'] = drop_pending_updates
if timeout:
payload['connect-timeout'] = timeout
return _make_request(token, method_url, params=payload) return _make_request(token, method_url, params=payload)
def get_webhook_info(token): def get_webhook_info(token, timeout=None):
method_url = r'getWebhookInfo' method_url = r'getWebhookInfo'
payload = {} payload = {}
if timeout:
payload['connect-timeout'] = timeout
return _make_request(token, method_url, params=payload) return _make_request(token, method_url, params=payload)