From 5d4979a675b8f26a86b74bdc51634c7028433ac9 Mon Sep 17 00:00:00 2001 From: "Francesco Scarlato (Jungmann)" Date: Sun, 24 Jul 2016 11:08:01 +0200 Subject: [PATCH] Release 0.2.1 --- HISTORY.rst | 4 + HISTORY.rst~ | 34 ++++++++ README.rst | 35 +++++---- README.rst~ | 133 ++++++++++++++++++++++++++++++++ django_telegrambot/__init__.py | 4 +- django_telegrambot/__init__.py~ | 2 + example/telegrambot.py | 9 ++- example/telegrambot.py~ | 46 +++++++++++ requirements.txt | 2 +- requirements.txt~ | 3 + 10 files changed, 253 insertions(+), 19 deletions(-) create mode 100644 HISTORY.rst~ create mode 100644 README.rst~ create mode 100644 django_telegrambot/__init__.py~ create mode 100644 example/telegrambot.py~ create mode 100644 requirements.txt~ diff --git a/HISTORY.rst b/HISTORY.rst index fc0d2af..59b85dc 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -2,6 +2,10 @@ History ------- +0.2.1 (2016-07-24) +++++++++++++++++++ +* Update for python-telegram-bot release v5.0 + 0.2.0 (2016-04-27) ++++++++++++++++++ diff --git a/HISTORY.rst~ b/HISTORY.rst~ new file mode 100644 index 0000000..fc0d2af --- /dev/null +++ b/HISTORY.rst~ @@ -0,0 +1,34 @@ +.. :changelog: + +History +------- +0.2.0 (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) +++++++++++++++++++ + +* Fix compatibility. + +0.1.4 (2016-01-28) +++++++++++++++++++ + +* Fix compatibility. + +0.1.3 (2016-01-28) +++++++++++++++++++ + +* Fix setting certificate. +* Add method DjangoTelegramBot.getBot(); get bot instance by token or username. + +0.1.2 (2016-01-26) +++++++++++++++++++ + +* First release on PyPI. diff --git a/README.rst b/README.rst index 1a1e0c2..84a92ba 100644 --- a/README.rst +++ b/README.rst @@ -56,27 +56,32 @@ Include in your urls.py the ``django_telegrambot.urls`` using the same value of Then use it in a project creating a module ``telegrambot.py`` in your app :: #myapp/telegrambot.py + # Example code for telegrambot.py module from telegram.ext import CommandHandler, MessageHandler, Filters - from django_telegrambot.apps import DjangoTelegramBot + from django_telegrambot.apps import DjangoTelegramBot + + import logging + logger = logging.getLogger(__name__) + # 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(): logger.info("Loading handlers for telegram bot") @@ -87,16 +92,20 @@ Then use it in a project creating a module ``telegrambot.py`` in your app :: # dp = DjangoTelegramBot.getDispatcher('BOT_n_username') #get by bot username # on different commands - answer in Telegram - dp.addHandler(CommandHandler("start", start)) - dp.addHandler(CommandHandler("help", help)) - + dp.add_handler(CommandHandler("start", start)) + dp.add_handler(CommandHandler("help", help)) + # on noncommand i.e message - echo the message on Telegram - dp.addHandler(MessageHandler([Filters.text], echo)) - + dp.add_handler(MessageHandler([Filters.text], echo)) + + # log all errors + dp.add_error_handler(error) + # log all errors dp.addErrorHandler(error) + Features -------- diff --git a/README.rst~ b/README.rst~ new file mode 100644 index 0000000..1a1e0c2 --- /dev/null +++ b/README.rst~ @@ -0,0 +1,133 @@ +============================= +django-telegrambot +============================= + +.. image:: https://badge.fury.io/py/django-telegrambot.png + :target: https://badge.fury.io/py/django-telegrambot + +.. image:: https://travis-ci.org/JungDev/django-telegrambot.png?branch=master + :target: https://travis-ci.org/JungDev/django-telegrambot + +A simple app to develop Telegram bots with Django + +Documentation +------------- + +The full documentation is at https://django-telegrambot.readthedocs.org. + +Quickstart +---------- + +Install django-telegrambot:: + + pip install django-telegrambot + +Configure your installation +--------------------------- + +Add ``django_telegrambot`` in ``INSTALLED_APPS`` :: + + #settings.py + INSTALLED_APPS = ( + ... + 'django_telegrambot', + ... + ) + +And set your bots:: + + #settings.py + #Django Telegram Bot settings + TELEGRAM_BOT_TOKENS = ('BOT_1_token','BOT_2_token',) + TELEGRAM_WEBHOOK_SITE = 'https://mysite.it' + TELEGRAM_WEBHOOK_BASE = '/baseurl' + #TELEGRAM_WEBHOOK_CERTIFICATE = 'cert.pem' #If your site use self-signed certificate, must be set with location of your public key certificate. (More info at https://core.telegram.org/bots/self-signed ) + + +Include in your urls.py the ``django_telegrambot.urls`` using the same value of ``TELEGRAM_WEBHOOK_BASE`` :: + + #urls.py + urlpatterns = [ + ... + url(r'^baseurl/', include('django_telegrambot.urls')), + ... + ] + +Then use it in a project creating a module ``telegrambot.py`` in your app :: + + #myapp/telegrambot.py + from telegram.ext import CommandHandler, MessageHandler, Filters + 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(): + logger.info("Loading handlers for telegram bot") + + # Default dispatcher (this is related to the first bot in settings.TELEGRAM_BOT_TOKENS) + dp = DjangoTelegramBot.dispatcher + # 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.addHandler(CommandHandler("start", start)) + dp.addHandler(CommandHandler("help", help)) + + # on noncommand i.e message - echo the message on Telegram + dp.addHandler(MessageHandler([Filters.text], echo)) + + # log all errors + dp.addErrorHandler(error) + + +Features +-------- + +* Multiple bots + +Contributing +------------ + +Patches and bug reports are welcome, just please keep the style consistent with the original source. + +Running Tests +-------------- + +Does the code actually work? + +:: + + source /bin/activate + (myenv) $ pip install -r requirements-test.txt + (myenv) $ python runtests.py + +Credits +--------- +Required package: +* `Python Telegram Bot`_ + +.. _`Python Telegram Bot`: https://github.com/python-telegram-bot/python-telegram-bot + +Tools used in rendering this package: + +* Cookiecutter_ + +.. _Cookiecutter: https://github.com/audreyr/cookiecutter + diff --git a/django_telegrambot/__init__.py b/django_telegrambot/__init__.py index 488eae9..99e5d96 100644 --- a/django_telegrambot/__init__.py +++ b/django_telegrambot/__init__.py @@ -1,2 +1,2 @@ -__version__ = '0.2.0' -default_app_config = 'django_telegrambot.apps.DjangoTelegramBot' \ No newline at end of file +__version__ = '0.2.1' +default_app_config = 'django_telegrambot.apps.DjangoTelegramBot' diff --git a/django_telegrambot/__init__.py~ b/django_telegrambot/__init__.py~ new file mode 100644 index 0000000..488eae9 --- /dev/null +++ b/django_telegrambot/__init__.py~ @@ -0,0 +1,2 @@ +__version__ = '0.2.0' +default_app_config = 'django_telegrambot.apps.DjangoTelegramBot' \ No newline at end of file diff --git a/example/telegrambot.py b/example/telegrambot.py index a44a99b..682b75e 100644 --- a/example/telegrambot.py +++ b/example/telegrambot.py @@ -35,11 +35,14 @@ def main(): # dp = DjangoTelegramBot.getDispatcher('BOT_n_username') #get by bot username # on different commands - answer in Telegram - dp.addHandler(CommandHandler("start", start)) - dp.addHandler(CommandHandler("help", help)) + dp.add_handler(CommandHandler("start", start)) + dp.add_handler(CommandHandler("help", help)) # on noncommand i.e message - echo the message on Telegram - dp.addHandler(MessageHandler([Filters.text], echo)) + dp.add_handler(MessageHandler([Filters.text], echo)) + + # log all errors + dp.add_error_handler(error) # log all errors dp.addErrorHandler(error) diff --git a/example/telegrambot.py~ b/example/telegrambot.py~ new file mode 100644 index 0000000..a44a99b --- /dev/null +++ b/example/telegrambot.py~ @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Example code for telegrambot.py module +from telegram.ext import CommandHandler, MessageHandler, Filters +from django_telegrambot.apps import DjangoTelegramBot + +import logging +logger = logging.getLogger(__name__) + + +# 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(): + logger.info("Loading handlers for telegram bot") + + # Default dispatcher (this is related to the first bot in settings.TELEGRAM_BOT_TOKENS) + dp = DjangoTelegramBot.dispatcher + # 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.addHandler(CommandHandler("start", start)) + dp.addHandler(CommandHandler("help", help)) + + # on noncommand i.e message - echo the message on Telegram + dp.addHandler(MessageHandler([Filters.text], echo)) + + # log all errors + dp.addErrorHandler(error) + diff --git a/requirements.txt b/requirements.txt index a0d356f..4497dc2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ django>=1.8.0 # Additional requirements go here -python-telegram-bot>=4.0.1 +python-telegram-bot>=5.0 diff --git a/requirements.txt~ b/requirements.txt~ new file mode 100644 index 0000000..a0d356f --- /dev/null +++ b/requirements.txt~ @@ -0,0 +1,3 @@ +django>=1.8.0 +# Additional requirements go here +python-telegram-bot>=4.0.1