diff --git a/HISTORY.rst b/HISTORY.rst index 1549639..ac8be96 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -2,12 +2,16 @@ History ------- +0.1.9 (2016-04-27) +++++++++++++++++++ + +* Update for python-telegram-bot release v4.0.1 + 0.1.8 (2016-03-22) ++++++++++++++++++ * Update for deprecation in python-telegram-bot release v3.4 - 0.1.5 (2016-01-28) ++++++++++++++++++ diff --git a/README.rst b/README.rst index 84432b4..859316d 100644 --- a/README.rst +++ b/README.rst @@ -58,38 +58,39 @@ Then use it in a project creating a module ``telegrambot.py`` in your app :: #myapp/telegrambot.py from django_telegrambot.apps import DjangoTelegramBot + # Define a few command handlers. These usually take the two arguments bot and + # update. Error handlers also receive the raised TelegramError object in error. def start(bot, update): bot.sendMessage(update.message.chat_id, text='Hi!') + def help(bot, update): bot.sendMessage(update.message.chat_id, text='Help!') + def echo(bot, update): bot.sendMessage(update.message.chat_id, text=update.message.text) + def error(bot, update, error): logger.warn('Update "%s" caused error "%s"' % (update, error)) def main(): - print "Handlers for telegram bot" + logger.info("Loading handlers for telegram bot") - #Utilizzare questa variabile per ottenere il dispatcher relativo al default bot + # Default dispatcher (this is related to the first bot in settings.TELEGRAM_BOT_TOKENS) dp = DjangoTelegramBot.dispatcher - - # in alternativa si può selezionare quale bot usare utilizzando la seguente funzione: - ''' - dp = DjangoTelegramBot.getDispatcher('BOT_2_token') #by bot - dp = DjangoTelegramBot.getDispatcher('BOT_2_username') #by bot username - - ''' + # To get Dispatcher related to a specific bot + # dp = DjangoTelegramBot.getDispatcher('BOT_n_token') #get by bot token + # dp = DjangoTelegramBot.getDispatcher('BOT_n_username') #get by bot username # on different commands - answer in Telegram - dp.addTelegramCommandHandler("start", start) - dp.addTelegramCommandHandler("help", help) + dp.addHandler(CommandHandler("start", start)) + dp.addHandler(CommandHandler("help", help)) # on noncommand i.e message - echo the message on Telegram - dp.addTelegramMessageHandler(echo) + dp.addHandler(MessageHandler([Filters.text], echo)) # log all errors dp.addErrorHandler(error) diff --git a/django_telegrambot/__init__.py b/django_telegrambot/__init__.py index a04c319..a5de29c 100644 --- a/django_telegrambot/__init__.py +++ b/django_telegrambot/__init__.py @@ -1,2 +1,2 @@ -__version__ = '0.1.8' +__version__ = '0.1.9' default_app_config = 'django_telegrambot.apps.DjangoTelegramBot' \ No newline at end of file diff --git a/example/telegrambot.py b/example/telegrambot.py index c630f57..dd33a60 100644 --- a/example/telegrambot.py +++ b/example/telegrambot.py @@ -6,17 +6,20 @@ logger = logging.getLogger(__name__) -#in questa parte del file definire il funzionamento del bot aggiungendo gli handler +# Define a few command handlers. These usually take the two arguments bot and +# update. Error handlers also receive the raised TelegramError object in error. def start(bot, update): bot.sendMessage(update.message.chat_id, text='Hi!') + def help(bot, update): bot.sendMessage(update.message.chat_id, text='Help!') + def echo(bot, update): - logger.info('ECHO: %s'%update.message.text) bot.sendMessage(update.message.chat_id, text=update.message.text) + def error(bot, update, error): logger.warn('Update "%s" caused error "%s"' % (update, error)) @@ -31,11 +34,11 @@ def main(): # dp = DjangoTelegramBot.getDispatcher('BOT_n_username') #get by bot username # on different commands - answer in Telegram - dp.addTelegramCommandHandler("start", start) - dp.addTelegramCommandHandler("help", help) + dp.addHandler(CommandHandler("start", start)) + dp.addHandler(CommandHandler("help", help)) # on noncommand i.e message - echo the message on Telegram - dp.addTelegramMessageHandler(echo) + dp.addHandler(MessageHandler([Filters.text], echo)) # log all errors dp.addErrorHandler(error) diff --git a/requirements.txt b/requirements.txt index 3d7241d..a0d356f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ django>=1.8.0 # Additional requirements go here -python-telegram-bot>=3.4.0 +python-telegram-bot>=4.0.1