Skip to main content

Simple and lightweight Telegram Bot

Project description

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:

  • return proper values for send* - methods (eg. sendDice should return a Dice, not only requests.response object)
  • 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 1 1/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 without going 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 beginner- and userfriendly!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

b4t-python-telegram-bot-1.4.0.tar.gz (10.7 kB view details)

Uploaded Source

Built Distribution

b4t_python_telegram_bot-1.4.0-py3-none-any.whl (14.7 kB view details)

Uploaded Python 3

File details

Details for the file b4t-python-telegram-bot-1.4.0.tar.gz.

File metadata

  • Download URL: b4t-python-telegram-bot-1.4.0.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using 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.8 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for b4t-python-telegram-bot-1.4.0.tar.gz
Algorithm Hash digest
SHA256 f57417885ef5f962b618374620541fa0dba629766e0ee887314cebb0376ce336
MD5 3b8b34408fb660b55c0d573c4a3625ee
BLAKE2b-256 f346178ab4c64bf7f95ef365252d9d7a463a7518b32c935225c410322a02d7db

See more details on using hashes here.

File details

Details for the file b4t_python_telegram_bot-1.4.0-py3-none-any.whl.

File metadata

  • Download URL: b4t_python_telegram_bot-1.4.0-py3-none-any.whl
  • Upload date:
  • Size: 14.7 kB
  • Tags: Python 3
  • Uploaded using 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.8 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for b4t_python_telegram_bot-1.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8a16328bf1bfe6ab14169af6bfe69f62fb980c63194aea532004972e9f35ed42
MD5 fd48d97a398a0a23c0738790b3330fcd
BLAKE2b-256 94ca5566c930ded92aa16d03d3cafa48da10858545e0bf1b7581ce11fc1ffe09

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page