Skip to main content

Brain4Tech Python Telegram Bot

A simple and lightweight Python Telegram Bot with a small range of functionalities using the Telegram Bot API

Installation with pip: pip install b4t-python-telegram-bot

Requirements:

  1. the latest Python version
  2. a bot token from BotFather

Currently supported:

  • send and receive messages, images, audio, video animations and documents (silently, and/or in media groups)
  • polls, dices, contacts, locations and venues
  • chat actions
  • inlinebuttons and callback-queries
  • keyboardbuttons
  • bot-commands
  • "single-chat mode": bot is only active in one single chat/group/channel
  • "return-on-update-only mode": bot only returns a value when it receives a valid update
  • new chat members
  • ban, unban or kick members from group-like chats
  • restrict members in group-like chats
  • get information about chat members
  • edit messages
  • MarkdownV2-formatting

Future plans:

  • forward messages & reply to messages
  • get chat-information and set chat-attributes (like photo and description)
  • download images, audio, video and documents
  • improve Markdown formatting support
  • add time delay between requests and use timeout features
  • documentation

How it works:

The bot frequently sends a request to the telegram server and gets a response. If there is usable content within the response (i.e. someone send a message to the bot or into a group where the bot is a group member of) it parses the response into a custom datastructure ( = classes, lol) which the programmer gets in return to work with. The structure of the returned class is the same as Telegram sends the response, which means you can get your needed information like you can see here. Example: I want to know what the content is of the message I just received:

from telegram_bot import TelegramBot
bot = TelegramBot ("<insert your bot_token here>")
response = bot.poll()

if response:    
    message = response.message.text

Easy! You can also check if your response is a message or (for example) an incoming command or a callback from an inline-keyboard:

[see above]

if response:    
    if response.isMessage():
	    # do stuff here
	elif response.isCallback():
		# do other stuff here
	elif response.isBotCommand():
		# you know what's coming...

Check the Update-class in telegram_bot/updates.py for more. It's pretty self explaining.

Good-to-know:

  • the codebase is still in development.
  • Mistakes and Bugs can will occur! If you found one, please open an issue :)
  • This code is FREE to use! YEYY!

About Me:

  • software-engineering student from Germany (4th semester)
  • 3-4 years of Python experience
  • I've been studying the Telegram Bot API for 2 years and released small scripts in my other repository. Unfortunately that coding style is unusable for bigger projects so I decided to create an own little library for future projects and other people who want to learn the Telegram Bot API so they don't need to go through the pain I've been going through.
  • beginner at GitHub and publishing code.
  • English is obviously not my first language

Feel free to make a pull request and help me making this repository more beginner- and userfriendly!

Metadata

Release files for b4t-python-telegram-bot 2.0.0

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

Source distribution (sdist)

Source distribution for b4t-python-telegram-bot 2.0.0
File Size Uploaded Provenance Actions
b4t-python-telegram-bot-2.0.0.tar.gz 10.9 kB Without provenance Details for b4t-python-telegram-bot-2.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for b4t-python-telegram-bot 2.0.0
File Interpreter ABI Platform Actions
b4t_python_telegram_bot-2.0.0-py3-none-any.whl Python 3 none any Details for b4t_python_telegram_bot-2.0.0-py3-none-any.whl

Total release size: 26.1 kB

Release files / b4t-python-telegram-bot-2.0.0.tar.gz

Download URL b4t-python-telegram-bot-2.0.0.tar.gz
Size 10.9 kB
Tags Source
SHA-256 checksum
How to use checksums
3d47deed434bee935a384a5ed0d88bc1c10d5d2f57cd497d125290dfa7759445
BLAKE2b-256 checksum
How to use checksums
b1d54ac9c2400567400411930ea8b36ff7f0e6080a2aec78d6e1e521ac483e1e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.11

Release files / b4t_python_telegram_bot-2.0.0-py3-none-any.whl

Download URL b4t_python_telegram_bot-2.0.0-py3-none-any.whl
Size 15.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cd30f5325277f6fb5006e9c46b043cab831d6def61ccf79de8ae73ad2164c8fa
BLAKE2b-256 checksum
How to use checksums
a2c32960dbaef4261a310131a1c0cff3cd62247fb3582b412fab0294e46e8f37
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.11

Security for b4t-python-telegram-bot 2.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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