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, create at least one bot with django admin. Token is the only required field. You may need to provided public key certificate for your server. https://core.telegram.org/bots/self-signed Heroku has https and ssl by default so it is a good option if you dont want to deal with that.
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()), ]
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. The webhook for each bot is set when a Bot is saved and enabled field is set to true.
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
Multiple bots
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.3.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 04e34fa0d16841ceaa8776c9bba86dfa2367d87b665edf294ceadf9b57424b1e |
|
MD5 | 1830874c88f48895eaac537b3e55b90f |
|
BLAKE2b-256 | 12bdcb8a39f541aa90a76a42314e369fd44bbe7ec8a96f2d5b3d0c400538e711 |
Hashes for django_telegram_bot-0.3.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6f25aefee94090d7baf76cd3206b33c904c471b9127619ba0deec51c0447b116 |
|
MD5 | 3546a6fe4fd247f0489e61df6c843c2a |
|
BLAKE2b-256 | 4ae6f72a25f61a085fbd9b37686f10a0f6a16342e0f2169fe2264639d368dac8 |