mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2025-01-11 12:31:40 +01:00
Merge pull request #105 from rahiel/master
handle "Unauthorized" exceptions in echobot
This commit is contained in:
commit
a0baa68cf3
1 changed files with 12 additions and 4 deletions
|
@ -29,14 +29,19 @@ except ImportError:
|
|||
|
||||
|
||||
def main():
|
||||
update_id = None
|
||||
# Telegram Bot Authorization Token
|
||||
bot = telegram.Bot('TOKEN')
|
||||
|
||||
# get the first pending update_id, this is so we can skip over it in case
|
||||
# we get an "Unauthorized" exception.
|
||||
try:
|
||||
update_id = bot.getUpdates()[0].update_id
|
||||
except IndexError:
|
||||
update_id = None
|
||||
|
||||
logging.basicConfig(
|
||||
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
||||
|
||||
# Telegram Bot Authorization Token
|
||||
bot = telegram.Bot('TOKEN')
|
||||
|
||||
while True:
|
||||
try:
|
||||
update_id = echo(bot, update_id)
|
||||
|
@ -44,6 +49,9 @@ def main():
|
|||
# These are network problems with Telegram.
|
||||
if e.message in ("Bad Gateway", "Timed out"):
|
||||
sleep(1)
|
||||
elif e.message == "Unauthorized":
|
||||
# The user has removed or blocked the bot.
|
||||
update_id += 1
|
||||
else:
|
||||
raise e
|
||||
except URLError as e:
|
||||
|
|
Loading…
Reference in a new issue