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 2882147 commit ab9f3d4
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions django_telegrambot/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +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
from telegram.error import InvalidToken, TelegramError
import os.path

import logging
Expand Down Expand Up @@ -167,20 +167,25 @@ def ready(self):
if self.mode == WEBHOOK_MODE:
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)
DjangoTelegramBot.dispatchers.append(Dispatcher(bot, None, workers=0))
hookurl = '{}/{}/{}/'.format(webhook_site, webhook_base, token)

max_connections = b.get('WEBHOOK_MAX_CONNECTIONS', 40)
max_connections = b.get('WEBHOOK_MAX_CONNECTIONS', 40)

setted = bot.setWebhook(hookurl, certificate=certificate, timeout=timeout, max_connections=max_connections, allowed_updates=allowed_updates)
webhook_info = bot.getWebhookInfo()
real_allowed = webhook_info.allowed_updates if webhook_info.allowed_updates else ["ALL"]
setted = bot.setWebhook(hookurl, certificate=certificate, timeout=timeout, max_connections=max_connections, allowed_updates=allowed_updates)
webhook_info = bot.getWebhookInfo()
real_allowed = webhook_info.allowed_updates if webhook_info.allowed_updates else ["ALL"]

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))

except InvalidToken:
logger.error('Invalid Token : {}'.format(token))
return
except TelegramError as er:
logger.error('Error : {}'.format(repr(er)))
return

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:
try:
updater = Updater(token=token)
Expand All @@ -192,7 +197,9 @@ def ready(self):
except InvalidToken:
logger.error('Invalid Token : {}'.format(token))
return

except TelegramError as er:
logger.error('Error : {}'.format(repr(er)))
return

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

0 comments on commit ab9f3d4

Please sign in to comment.