File tree Expand file tree Collapse file tree 1 file changed +12
-4
lines changed
Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Original file line number Diff line number Diff line change 2929
3030
3131def main ():
32- update_id = None
32+ # Telegram Bot Authorization Token
33+ bot = telegram .Bot ('TOKEN' )
34+
35+ # get the first pending update_id, this is so we can skip over it in case
36+ # we get an "Unauthorized" exception.
37+ try :
38+ update_id = bot .getUpdates ()[0 ].update_id
39+ except IndexError :
40+ update_id = None
3341
3442 logging .basicConfig (
3543 format = '%(asctime)s - %(name)s - %(levelname)s - %(message)s' )
3644
37- # Telegram Bot Authorization Token
38- bot = telegram .Bot ('TOKEN' )
39-
4045 while True :
4146 try :
4247 update_id = echo (bot , update_id )
4348 except telegram .TelegramError as e :
4449 # These are network problems with Telegram.
4550 if e .message in ("Bad Gateway" , "Timed out" ):
4651 sleep (1 )
52+ elif e .message == "Unauthorized" :
53+ # The user has removed or blocked the bot.
54+ update_id += 1
4755 else :
4856 raise e
4957 except URLError as e :
You can’t perform that action at this time.
0 commit comments