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 commandspatterns variable, analogue to django urls and ROOT_URLCONF:
TELEGRAM_BOT_COMMANDS_CONF = "app.commands"
Set bot commands handlers is very easy just define a module with commandspatterns list of tuples (‘command’, command_view):
commandspatterns = [('start', StartView.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.1.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | e4b8a75c5c659ba8be1c923accaa14ae04c4821622563c52a41408a2995d3b71 |
|
MD5 | b85d629edad789376242149f13470a12 |
|
BLAKE2b-256 | f77c7ff4dfce120b3370457f6226436e42c976646e0037f3d51ad4b871c7527d |
Hashes for django_telegram_bot-0.1.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1be9bdd8c65326f577f19efc5c0fa79cd0fa9b3b55f5a32f2e9aebd5b5c69d20 |
|
MD5 | 3a880f2354e1a28dbb3357cc460b1333 |
|
BLAKE2b-256 | 2e33839f438e4d28a0c606014f756b0f962ae44a1e79617fff79912e6c7bf5db |