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

drop_pending_updates in set_webhook

This commit is contained in:
Badiboy
2021-01-09 21:22:49 +03:00
parent da9ee5ffba
commit 52ebb5a1a7
3 changed files with 23 additions and 11 deletions

View File

@ -45,6 +45,7 @@ class ExceptionHandler:
Class for handling exceptions while Polling
"""
# noinspection PyMethodMayBeStatic,PyUnusedLocal
def handle(self, exception):
return False
@ -235,7 +236,8 @@ class TeleBot:
"""
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, timeout=None):
def set_webhook(self, url=None, certificate=None, max_connections=None, allowed_updates=None, ip_address=None,
drop_pending_updates = None, timeout=None):
"""
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.
@ -246,10 +248,11 @@ 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 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 drop_pending_updates: Pass True to drop all pending updates
:param timeout: Integer. Request connection timeout
:return:
"""
return apihelper.set_webhook(self.token, url, certificate, max_connections, allowed_updates, ip_address, timeout)
return apihelper.set_webhook(self.token, url, certificate, max_connections, allowed_updates, ip_address, drop_pending_updates, timeout)
def delete_webhook(self, drop_pending_updates=None, timeout=None):
"""

View File

@ -206,7 +206,8 @@ def send_message(
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, timeout=None):
def set_webhook(token, url=None, certificate=None, max_connections=None, allowed_updates=None, ip_address=None,
drop_pending_updates = None, timeout=None):
method_url = r'setWebhook'
payload = {
'url': url if url else "",
@ -216,10 +217,12 @@ def set_webhook(token, url=None, certificate=None, max_connections=None, allowed
files = {'certificate': certificate}
if max_connections:
payload['max_connections'] = max_connections
if allowed_updates is not None: # Empty lists should pass
if allowed_updates is not None: # Empty lists should pass
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
if drop_pending_updates is not None: # Any bool value should pass
payload['drop_pending_updates'] = drop_pending_updates
if timeout:
payload['connect-timeout'] = timeout
return _make_request(token, method_url, params=payload, files=files)
@ -228,7 +231,7 @@ def set_webhook(token, url=None, certificate=None, max_connections=None, allowed
def delete_webhook(token, drop_pending_updates=None, timeout=None):
method_url = r'deleteWebhook'
payload = {}
if drop_pending_updates is not None: # None / True / False
if drop_pending_updates is not None: # Any bool value should pass
payload['drop_pending_updates'] = drop_pending_updates
if timeout:
payload['connect-timeout'] = timeout