@@ -192,7 +192,8 @@ def start_webhook(self,
192192 key = None ,
193193 clean = False ,
194194 bootstrap_retries = 0 ,
195- webhook_url = None ):
195+ webhook_url = None ,
196+ allowed_updates = None ):
196197 """
197198 Starts a small http server to listen for updates via webhook. If cert
198199 and key are not provided, the webhook will be started directly on
@@ -215,9 +216,10 @@ def start_webhook(self,
215216 | < 0 - retry indefinitely
216217 | 0 - no retries (default)
217218 | > 0 - retry up to X times
218- webhook_url (Optional[str]): Explicitly specifiy the webhook url.
219+ webhook_url (Optional[str]): Explicitly specify the webhook url.
219220 Useful behind NAT, reverse proxy, etc. Default is derived from
220221 `listen`, `port` & `url_path`.
222+ allowed_updates (Optional[list[str]]): Passed to Bot.setWebhook
221223
222224 Returns:
223225 Queue: The update queue that can be filled from the main thread
@@ -231,7 +233,7 @@ def start_webhook(self,
231233 self .job_queue .start ()
232234 self ._init_thread (self .dispatcher .start , "dispatcher" ),
233235 self ._init_thread (self ._start_webhook , "updater" , listen , port , url_path , cert ,
234- key , bootstrap_retries , clean , webhook_url )
236+ key , bootstrap_retries , clean , webhook_url , allowed_updates )
235237
236238 # Return the update queue so the main thread can insert updates
237239 return self .update_queue
@@ -247,7 +249,7 @@ def _start_polling(self, poll_interval, timeout, read_latency, bootstrap_retries
247249 cur_interval = poll_interval
248250 self .logger .debug ('Updater thread started' )
249251
250- self ._bootstrap (bootstrap_retries , clean = clean , webhook_url = '' )
252+ self ._bootstrap (bootstrap_retries , clean = clean , webhook_url = '' , allowed_updates = None )
251253
252254 while self .running :
253255 try :
@@ -295,7 +297,7 @@ def _increase_poll_interval(current_interval):
295297 return current_interval
296298
297299 def _start_webhook (self , listen , port , url_path , cert , key , bootstrap_retries , clean ,
298- webhook_url ):
300+ webhook_url , allowed_updates ):
299301 self .logger .debug ('Updater thread started' )
300302 use_ssl = cert is not None and key is not None
301303 if not url_path .startswith ('/' ):
@@ -316,7 +318,8 @@ def _start_webhook(self, listen, port, url_path, cert, key, bootstrap_retries, c
316318 max_retries = bootstrap_retries ,
317319 clean = clean ,
318320 webhook_url = webhook_url ,
319- cert = open (cert , 'rb' ))
321+ cert = open (cert , 'rb' ),
322+ allowed_updates = allowed_updates )
320323 elif clean :
321324 self .logger .warning ("cleaning updates is not supported if "
322325 "SSL-termination happens elsewhere; skipping" )
@@ -346,7 +349,7 @@ def _check_ssl_cert(self, cert, key):
346349 def _gen_webhook_url (listen , port , url_path ):
347350 return 'https://{listen}:{port}{path}' .format (listen = listen , port = port , path = url_path )
348351
349- def _bootstrap (self , max_retries , clean , webhook_url , cert = None ):
352+ def _bootstrap (self , max_retries , clean , webhook_url , allowed_updates , cert = None ):
350353 retries = 0
351354 while 1 :
352355
@@ -357,7 +360,8 @@ def _bootstrap(self, max_retries, clean, webhook_url, cert=None):
357360 self ._clean_updates ()
358361 sleep (1 )
359362
360- self .bot .setWebhook (url = webhook_url , certificate = cert )
363+ self .bot .setWebhook (
364+ url = webhook_url , certificate = cert , allowed_updates = allowed_updates )
361365 except (Unauthorized , InvalidToken ):
362366 raise
363367 except TelegramError :
0 commit comments