frogram is a lightweight Python library for building Telegram bots with a simple and intuitive interface. It provides decorator-based handlers for commands, text messages, and photos, along with convenient methods for sending and managing messages.
Project description
Frogram - Modern Telegram Bot Framework for Python
Frogram is a lightweight yet powerful Python library for building Telegram bots with an elegant and developer-friendly interface. Designed for both beginners and experienced developers, it provides all the essential tools to create feature-rich bots quickly and efficiently.
Features
✨ Intuitive Interface
- Clean, Pythonic API design
- Decorator-based handlers
- Context-aware processing
⌨️ Keyboard Support
- Full inline keyboard functionality
- Reply keyboard with all options
- Dynamic keyboard editing
📨 Message Handling
- Commands, text, and photo processing
- Media and file support
- Message lifecycle management (send/edit/delete)
🔄 Callback System
- Advanced callback query handling
- Alert and notification responses
- Interactive message updates
⚡ Performance
- Lightweight with minimal dependencies
- Synchronous and asynchronous support
- Efficient polling mechanism
Installation
pip install frogram
Quick Start
from frogram import Bot, inline_keyboard, inline_button
bot = Bot("YOUR_BOT_TOKEN")
@bot.on_command("start")
def start_handler(ctx):
keyboard = inline_keyboard([
[inline_button("Option 1", callback_data="opt1"),
inline_button("Option 2", callback_data="opt2")]
])
ctx.bot.send_message("Welcome! Choose an option:", reply_markup=keyboard)
@bot.on_callback
def callback_handler(ctx):
ctx.answer(f"You selected: {ctx.data}")
bot.start_polling()
Core Components
1. Keyboard System
Inline Keyboard
keyboard = inline_keyboard([
[inline_button("Button", callback_data="action"),
[inline_button("Open URL", url="https://example.com")]
])
Reply Keyboard
keyboard = reply_keyboard([
[keyboard_button("Yes"), keyboard_button("No")],
[keyboard_button("Share Contact", request_contact=True)]
])
Remove Keyboard
remove_keyboard(selective=True)
2. Message Handling
Command Handler
@bot.on_command("help")
def help_command(ctx):
ctx.bot.send_message("Available commands: /start, /help")
Text Message Handler
@bot.on_message
def echo_handler(ctx):
ctx.bot.send_message(f"Echo: {ctx.text}")
Photo Handler
@bot.on_photo
def photo_handler(ctx):
print(f"Received photo: {ctx.photo_url}")
3. Callback System
@bot.on_callback
def callback_handler(ctx):
if ctx.data == "confirm":
ctx.answer("Confirmed!", show_alert=True)
ctx.edit_message_reply_markup(reply_markup=None)
Advanced Usage
Dynamic Keyboard Update
@bot.on_callback
def update_keyboard(ctx):
new_kb = inline_keyboard([
[inline_button("New Option", callback_data="new")]
])
ctx.edit_message_reply_markup(reply_markup=new_kb)
Message Management
# Send photo with caption
bot.send_photo(
photo_url="https://example.com/image.jpg",
caption="Check this out!",
reply_markup=keyboard
)
# Delete message
bot.delete(chat_id=12345, message_id=42)
File Handling
# Get file URL from file_id
file_url = bot.get_file_url(file_id)
Error Handling
Frogram integrates with debugmes for comprehensive error reporting:
try:
bot.start_polling()
except Exception as e:
debugmes.critical(f"Bot crashed: {e}")
API Reference
Bot Class Methods
| Method | Description |
|---|---|
send_message() |
Send text message with optional keyboard |
send_photo() |
Send photo with caption |
edit_message_reply_markup() |
Update message keyboard |
delete() |
Delete message |
get_file_url() |
Get downloadable file URL |
answer_callback_query() |
Respond to callback query |
Context Objects
| Property/Method | Description |
|---|---|
message |
Original message dictionary |
text/caption |
Message content |
photo_url |
Highest quality photo URL |
delete() |
Delete current message |
answer() |
Answer callback query |
Best Practices
- Error Handling: Always wrap handlers in try-except blocks
- Rate Limiting: Respect Telegram's API limits (30 messages/second)
- State Management: Implement proper session handling
- Security: Validate all user input and callback data
Contributing
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create your feature branch
- Commit your changes
- Push to the branch
- Open a pull request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Frogram - Build better Telegram bots, faster. 🚀 ``
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file frogram-0.0.1.tar.gz.
File metadata
- Download URL: frogram-0.0.1.tar.gz
- Upload date:
- Size: 7.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ed65c8b342649a65d05a6e97ad880a1676be4a0d3ca460c96b170ef120f97a06
|
|
| MD5 |
886bd03a463f49e851b85f4c28e777b7
|
|
| BLAKE2b-256 |
5cd3bbd8a1c34bda60da32e7e97519111b535300a1587bf051a7ba23abf0fc0d
|
File details
Details for the file frogram-0.0.1-py3-none-any.whl.
File metadata
- Download URL: frogram-0.0.1-py3-none-any.whl
- Upload date:
- Size: 7.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
beb3638b01ceb40ad8949d3e3f7f7975c6c738f42df8606d1a2187bec87cdb68
|
|
| MD5 |
9b7ed7f1679045be3faadbe0fcc0fdd8
|
|
| BLAKE2b-256 |
6ce99d33c1bd7960ea1fd9cbe3fae6f0be2d37c3afa4fcde8760d36630d082d8
|