Django Telegram bot base config
Project description
django-tbot-base
Django Telegram bot base config
Installation:
pip install django-tbot-base
Setting up
YourProject/settings.py
# Application definition
INSTALLED_APPS = [
'tbot_base',
...
]
# Add your bot handlers in order of priority
BOT_HANDLERS = [
'tbot.handlers',
]
YourProject/urls.py
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('tbot_base.urls')), # include webhook url
]
python manage.py makemigrations tbot_base
python manage.py migrate
Usage
Handlers
YourProject/tbot/handlers.py
from telebot import types
from telebot.apihelper import ApiTelegramException
from tbot_base.bot import tbot
@tbot.message_handler(func=lambda message: True)
def text_messages(message: types.Message):
tbot.send_message(message.from_user.id, 'Hello!')
@tbot.callback_query_handler(func=lambda call: True)
def callback_inline(call: types.CallbackQuery):
tbot.send_message(call.from_user.id, 'Hello!')
# remove the "clock" on the inline button
try:
tbot.answer_callback_query(callback_query_id=call.id, text='')
except ApiTelegramException:
pass
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
django-tbot-base-1.0.1.tar.gz
(4.6 kB
view hashes)
Built Distribution
Close
Hashes for django_tbot_base-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f6abfdf796623cfbcb137f1b7c21c6b10259a9577c410748b6c237d046e21ebf |
|
MD5 | cef5d5f888514c685d237e661267242c |
|
BLAKE2b-256 | 5b99985bc9923c083a779cfe59ae8dc4c20c26faaf4c790bc3eae543a5325e90 |