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 29
29
30
30
31
31
def 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
33
41
34
42
logging .basicConfig (
35
43
format = '%(asctime)s - %(name)s - %(levelname)s - %(message)s' )
36
44
37
- # Telegram Bot Authorization Token
38
- bot = telegram .Bot ('TOKEN' )
39
-
40
45
while True :
41
46
try :
42
47
update_id = echo (bot , update_id )
43
48
except telegram .TelegramError as e :
44
49
# These are network problems with Telegram.
45
50
if e .message in ("Bad Gateway" , "Timed out" ):
46
51
sleep (1 )
52
+ elif e .message == "Unauthorized" :
53
+ # The user has removed or blocked the bot.
54
+ update_id += 1
47
55
else :
48
56
raise e
49
57
except URLError as e :
You can’t perform that action at this time.
0 commit comments