Django app to write Telegram bots
Project description
CI:
PyPI:
Docs:
Django app to write Telegram bots. Just define commands and how to handle them.
NOTE: Just for text messages at this moment.
Documentation
The full documentation is at https://django-telegram-bot.readthedocs.org.
Telegram API documentation at https://core.telegram.org/bots/api
Quickstart
Install django-telegram-bot:
pip install django-telegram-bot
Add telegrambot and rest_framework to your INSTALLED_APPS, and run:
$ python manage.py migrate
After creating a bot in Telegram Platform set token received:
TELEGRAM_BOT_TOKEN = "token from your telegram bot"
Add webhook url to your urlpatterns:
url(r'^telegrambot/', include('telegrambot.urls', namespace="telegrambot")
Define whe file where commands will be defined in bothandlers variable, analogue to django urls and ROOT_URLCONF:
TELEGRAM_BOT_HANDLERS_CONF = "app.handlers"
Set bot commands handlers is very easy just as defining urls in django. Module with bothandlers that list different handlers:
bothandlers = [command('start', StartView.as_command_view()), command('author', AuthorCommandView.as_command_view()), command('author_inverse', AuthorInverseListView.as_command_view()), command('author_query', AuthorCommandQueryView.as_command_view()), unknown_command(UnknownView.as_command_view()), regex(r'author_(?P<name>\w+)', AuthorName.as_command_view()), ]
Use command set_webhook to specify the url to receive the incoming updates via webhook:
$ python manage.py set_webhook
To set the webhook for telegram you need django.contrib.sites installed, SITE_ID configured in settings and with it correct value in the DB.
Command views responses with Telegram messages to the user who send the command with a text message and keyboard. Compound with a context and a template. The way it is handled is analogue to Django views. Visits docs for more details https://django-telegram-bot.readthedocs.org/usage.html
Features
Commands handling definition.
Text responses and keyboards.
Media messages not supported.
Only Markup parse mode.
Running Tests
Does the code actually work?
source <YOURVIRTUALENV>/bin/activate (myenv) $ pip install -r requirements/test.txt (myenv) $ make test (myenv) $ make test-all
History
0.1.0 (2016-21-01)
First release on PyPI.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for django-telegram-bot-0.2.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2d102d6e283745109902558c7366b2e4e6576bcd67a621d4432bb85bd6e0f529 |
|
MD5 | 3d10a811a2e16a65506ece138bdbf767 |
|
BLAKE2b-256 | f5cd1363c68371b511e0a9bc200f085250763c219ab2984c7ac43c2c4ed9bbe0 |
Hashes for django_telegram_bot-0.2.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 744ae4c843f51a013b942a995d65443d409ff439f8ba6a35fa5d2d74e0b39705 |
|
MD5 | 4b819147093579a6abb2c399c32da5de |
|
BLAKE2b-256 | 84448730fbb61b6baa765eb74453798ad11b9c668e279567bfcc8346aa8b15f6 |