Skip to content

Commit

Permalink
Update for python-telegram-bot release v5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Jul 20, 2016
1 parent 6e04ef3 commit 19b1921
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
14 changes: 8 additions & 6 deletions django_telegrambot/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from django.conf import settings
import importlib
import telegram
from telegram.ext import Dispatcher
import os.path

import logging
Expand Down Expand Up @@ -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'))
Expand All @@ -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]
Expand Down Expand Up @@ -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))


2 changes: 1 addition & 1 deletion django_telegrambot/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 19b1921

Please sign in to comment.