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:
parent
da9ee5ffba
commit
52ebb5a1a7
@ -45,6 +45,7 @@ class ExceptionHandler:
|
|||||||
Class for handling exceptions while Polling
|
Class for handling exceptions while Polling
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# noinspection PyMethodMayBeStatic,PyUnusedLocal
|
||||||
def handle(self, exception):
|
def handle(self, exception):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -235,7 +236,8 @@ 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, 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
|
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,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 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 drop_pending_updates: Pass True to drop all pending updates
|
||||||
:param timeout: Integer. Request connection timeout
|
:param timeout: Integer. Request connection timeout
|
||||||
:return:
|
: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):
|
def delete_webhook(self, drop_pending_updates=None, timeout=None):
|
||||||
"""
|
"""
|
||||||
|
@ -206,7 +206,8 @@ 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, 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'
|
method_url = r'setWebhook'
|
||||||
payload = {
|
payload = {
|
||||||
'url': url if url else "",
|
'url': url if url else "",
|
||||||
@ -216,10 +217,12 @@ def set_webhook(token, url=None, certificate=None, max_connections=None, allowed
|
|||||||
files = {'certificate': certificate}
|
files = {'certificate': certificate}
|
||||||
if max_connections:
|
if max_connections:
|
||||||
payload['max_connections'] = 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)
|
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 drop_pending_updates is not None: # Any bool value should pass
|
||||||
|
payload['drop_pending_updates'] = drop_pending_updates
|
||||||
if timeout:
|
if timeout:
|
||||||
payload['connect-timeout'] = 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)
|
||||||
@ -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):
|
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: # Any bool value should pass
|
||||||
payload['drop_pending_updates'] = drop_pending_updates
|
payload['drop_pending_updates'] = drop_pending_updates
|
||||||
if timeout:
|
if timeout:
|
||||||
payload['connect-timeout'] = timeout
|
payload['connect-timeout'] = timeout
|
||||||
|
@ -48,6 +48,7 @@ class TestTeleBot:
|
|||||||
bot = telebot.TeleBot('')
|
bot = telebot.TeleBot('')
|
||||||
msg = self.create_text_message(r'https://web.telegram.org/')
|
msg = self.create_text_message(r'https://web.telegram.org/')
|
||||||
|
|
||||||
|
# noinspection PyUnusedLocal
|
||||||
@bot.message_handler(regexp=r'((https?):((//)|(\\\\))+([\w\d:#@%/;$()~_?\+-=\\\.&](#!)?)*)')
|
@bot.message_handler(regexp=r'((https?):((//)|(\\\\))+([\w\d:#@%/;$()~_?\+-=\\\.&](#!)?)*)')
|
||||||
def command_url(message):
|
def command_url(message):
|
||||||
msg.text = 'got'
|
msg.text = 'got'
|
||||||
@ -60,6 +61,7 @@ class TestTeleBot:
|
|||||||
bot = telebot.TeleBot('')
|
bot = telebot.TeleBot('')
|
||||||
msg = self.create_text_message(r'lambda_text')
|
msg = self.create_text_message(r'lambda_text')
|
||||||
|
|
||||||
|
# noinspection PyUnusedLocal
|
||||||
@bot.message_handler(func=lambda message: r'lambda' in message.text)
|
@bot.message_handler(func=lambda message: r'lambda' in message.text)
|
||||||
def command_url(message):
|
def command_url(message):
|
||||||
msg.text = 'got'
|
msg.text = 'got'
|
||||||
@ -72,6 +74,7 @@ class TestTeleBot:
|
|||||||
bot = telebot.TeleBot('')
|
bot = telebot.TeleBot('')
|
||||||
msg = self.create_text_message(r'text')
|
msg = self.create_text_message(r'text')
|
||||||
|
|
||||||
|
# noinspection PyUnusedLocal
|
||||||
@bot.message_handler(func=lambda message: r'lambda' in message.text)
|
@bot.message_handler(func=lambda message: r'lambda' in message.text)
|
||||||
def command_url(message):
|
def command_url(message):
|
||||||
msg.text = 'got'
|
msg.text = 'got'
|
||||||
@ -84,6 +87,7 @@ class TestTeleBot:
|
|||||||
bot = telebot.TeleBot('')
|
bot = telebot.TeleBot('')
|
||||||
msg = self.create_text_message(r'web.telegram.org/')
|
msg = self.create_text_message(r'web.telegram.org/')
|
||||||
|
|
||||||
|
# noinspection PyUnusedLocal
|
||||||
@bot.message_handler(regexp=r'((https?):((//)|(\\\\))+([\w\d:#@%/;$()~_?\+-=\\\.&](#!)?)*)')
|
@bot.message_handler(regexp=r'((https?):((//)|(\\\\))+([\w\d:#@%/;$()~_?\+-=\\\.&](#!)?)*)')
|
||||||
def command_url(message):
|
def command_url(message):
|
||||||
msg.text = 'got'
|
msg.text = 'got'
|
||||||
@ -522,6 +526,7 @@ class TestTeleBot:
|
|||||||
tb = telebot.TeleBot('')
|
tb = telebot.TeleBot('')
|
||||||
update = self.create_message_update('/help')
|
update = self.create_message_update('/help')
|
||||||
|
|
||||||
|
# noinspection PyUnusedLocal
|
||||||
@tb.middleware_handler(update_types=['message'])
|
@tb.middleware_handler(update_types=['message'])
|
||||||
def middleware(tb_instance, message):
|
def middleware(tb_instance, message):
|
||||||
message.text = 'got'
|
message.text = 'got'
|
||||||
@ -542,9 +547,10 @@ class TestTeleBot:
|
|||||||
tb = telebot.TeleBot('')
|
tb = telebot.TeleBot('')
|
||||||
update = self.create_message_update('/help')
|
update = self.create_message_update('/help')
|
||||||
|
|
||||||
|
# noinspection PyUnusedLocal
|
||||||
@tb.middleware_handler()
|
@tb.middleware_handler()
|
||||||
def middleware(tb_instance, update):
|
def middleware(tb_instance, mw_update):
|
||||||
update.message.text = 'got'
|
mw_update.message.text = 'got'
|
||||||
|
|
||||||
@tb.message_handler(func=lambda m: m.text == 'got')
|
@tb.message_handler(func=lambda m: m.text == 'got')
|
||||||
def command_handler(message):
|
def command_handler(message):
|
||||||
@ -556,6 +562,6 @@ class TestTeleBot:
|
|||||||
|
|
||||||
def test_chat_permissions(self):
|
def test_chat_permissions(self):
|
||||||
return # CHAT_ID is private chat, no permissions can be set
|
return # CHAT_ID is private chat, no permissions can be set
|
||||||
tb = telebot.TeleBot(TOKEN)
|
#tb = telebot.TeleBot(TOKEN)
|
||||||
permissions = types.ChatPermissions(can_send_messages=True, can_send_polls=False)
|
#permissions = types.ChatPermissions(can_send_messages=True, can_send_polls=False)
|
||||||
msg = tb.set_chat_permissions(CHAT_ID, permissions)
|
#msg = tb.set_chat_permissions(CHAT_ID, permissions)
|
||||||
|
Loading…
Reference in New Issue
Block a user