Minimal Telegram Bot framework using requests.
- Simple and minimalistic API for building Telegram bots
- Middleware support for message preprocessing
- Custom message handlers with filters
- Easy message sending and editing (text, photo, audio, video)
pip install .from pytgbot import Bot, filters, middleware
from pytgbot.handler import on_message
# Example middleware
@middleware.use
def lowercase_text(message):
if 'text' in message:
message['text'] = message['text'].lower()
return message
# Example handler for /start command
@on_message(filters.cmd("start"))
def start_handler(msg):
msg.send("Welcome to the bot!")
# Example handler for a specific message
@on_message(filters.msg("hello"))
def hello_handler(msg):
msg.send("Hi there!")
if __name__ == "__main__":
bot = Bot("YOUR_BOT_TOKEN")
bot.run()pytgbot/bot.py: Main bot loop and update pollingpytgbot/message.py: Message object and send/edit methodspytgbot/filters.py: Message filter utilitiespytgbot/handler.py: Handler registrationpytgbot/middleware.py: Middleware support
MIT