Skip to content

Commit

Permalink
Fix Invalid Token Error
Browse files Browse the repository at this point in the history
  • Loading branch information
Francesco Scarlato (Jungmann) committed May 25, 2017
1 parent 920f1b0 commit abef19b
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions django_telegrambot/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from django.utils.module_loading import module_has_submodule
from telegram.ext import Dispatcher
from telegram.ext import Updater
from telegram.error import InvalidToken
import os.path

import logging
Expand Down Expand Up @@ -164,7 +165,11 @@ def ready(self):
timeout = b.get('TIMEOUT', None)

if self.mode == WEBHOOK_MODE:
bot = telegram.Bot(token=token)
try:
bot = telegram.Bot(token=token)
except InvalidToken
logger.error('Invalid Token : {}'.format(token))
return
DjangoTelegramBot.dispatchers.append(Dispatcher(bot, None, workers=0))
hookurl = '{}/{}/{}/'.format(webhook_site, webhook_base, token)

Expand All @@ -177,12 +182,17 @@ def ready(self):
bot.more_info = webhook_info
logger.info('Telegram Bot <{}> setting webhook [ {} ] max connections:{} allowed updates:{} pending updates:{} : {}'.format(bot.username, webhook_info.url, webhook_info.max_connections, real_allowed, webhook_info.pending_update_count, setted))
else:
updater = Updater(token=token)
bot = updater.bot
bot.delete_webhook()
DjangoTelegramBot.updaters.append(updater)
DjangoTelegramBot.dispatchers.append(updater.dispatcher)
DjangoTelegramBot.__used_tokens.add(token)
try:
updater = Updater(token=token)
bot = updater.bot
bot.delete_webhook()
DjangoTelegramBot.updaters.append(updater)
DjangoTelegramBot.dispatchers.append(updater.dispatcher)
DjangoTelegramBot.__used_tokens.add(token)
except InvalidToken
logger.error('Invalid Token : {}'.format(token))
return


DjangoTelegramBot.bots.append(bot)
DjangoTelegramBot.bot_tokens.append(token)
Expand Down

0 comments on commit abef19b

Please sign in to comment.