Skip to main content

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

Release files for django-tbot-base 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-tbot-base 1.0.1
File Size Uploaded
django-tbot-base-1.0.1.tar.gz 4.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-tbot-base 1.0.1
File Interpreter ABI Platform
django_tbot_base-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 10.5 kB

Release files / django-tbot-base-1.0.1.tar.gz

Download URL django-tbot-base-1.0.1.tar.gz
Size 4.6 kB
Tags Source
SHA-256 checksum
How to use checksums
9edd4244d9f34e28452f4c51ef105c57d5037d61d57ee446feeb94c3c6e64d6a
BLAKE2b-256 checksum
How to use checksums
cb18fd7dbcb8e9f2f5c7936d0823592931d340578db4d7175f81e0a49f9de38c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

Release files / django_tbot_base-1.0.1-py3-none-any.whl

Download URL django_tbot_base-1.0.1-py3-none-any.whl
Size 6.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f6abfdf796623cfbcb137f1b7c21c6b10259a9577c410748b6c237d046e21ebf
BLAKE2b-256 checksum
How to use checksums
5b99985bc9923c083a779cfe59ae8dc4c20c26faaf4c790bc3eae543a5325e90
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page