diff --git a/django_telegrambot/apps.py b/django_telegrambot/apps.py index 0c9cb7c..faaf4cd 100644 --- a/django_telegrambot/apps.py +++ b/django_telegrambot/apps.py @@ -4,6 +4,7 @@ from django.conf import settings import importlib import telegram +from telegram.ext import Dispatcher import os.path import logging @@ -83,6 +84,12 @@ def ready(self): for index, token in enumerate(tokens): bot = telegram.Bot(token=token) + + DjangoTelegramBot.dispatchers.append(Dispatcher(bot, None)) + DjangoTelegramBot.bots.append(bot) + DjangoTelegramBot.bot_tokens.append(bot.token) + DjangoTelegramBot.bot_usernames.append(bot.username) + hookurl = '{}{}/{}/'.format(webhook_site,webhook_base, token) if (use_certificate): setted = bot.setWebhook(hookurl, certificate=open(CERT,'rb')) @@ -91,11 +98,6 @@ def ready(self): logger.info('Telegram Bot <{}> setting webhook [ {} ] : {}'.format(bot.username,hookurl,setted)) - DjangoTelegramBot.dispatchers.append(telegram.ext.Dispatcher(bot, None)) - DjangoTelegramBot.bots.append(bot) - DjangoTelegramBot.bot_tokens.append(bot.token) - DjangoTelegramBot.bot_usernames.append(bot.username) - #per compatibilità salvo il primo bot nella proprietà DjangoTelegramBot.dispatcher if index==0: DjangoTelegramBot.dispatcher = DjangoTelegramBot.dispatchers[0] @@ -123,4 +125,4 @@ def module_exists(module_name, method_name, execute): module_name = '{}.telegrambot'.format( app ) if module_exists(module_name, 'main', True): logger.info('Loaded {}'.format(module_name)) - \ No newline at end of file + diff --git a/django_telegrambot/views.py b/django_telegrambot/views.py index e7cb4b5..a01c58e 100644 --- a/django_telegrambot/views.py +++ b/django_telegrambot/views.py @@ -38,7 +38,7 @@ def webhook (request, bot_token): try: update = telegram.Update.de_json(data) - dispatcher.processUpdate(update) + dispatcher.process_update(update) logger.debug('Bot <{}> : Processed update {}'.format(bot.username, update)) # Dispatch any errors except TelegramError as te: