Skip to main content

An advanced, asynchronous UI component toolkit built on top of Pyrogram for stateful Telegram bots.

Project description

ChatPack Logo

ChatPack_UI ๐Ÿ“ฆ

An advanced, production-ready, asynchronous UI component toolkit built on top of Pyrogram.

Transforms linear, event-driven Telegram bot development into an elegant, sequential, and stateful dialog runtime.

Python Version Pyrogram Framework PyPI Version

Telegram Channel ย  Telegram Developer


๐Ÿ›  Why ChatPack?

Stop wrestling with complex global state machines, messy database tables, or chaotic callback query routing when building multi-step forms, star ratings, nested menus, or channel verification gates.


โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚               THE OLD WAY (CALLBACK CHAOS)             โ”‚
โ”‚ State (DB) โ”€โ”€> Handler โ”€โ”€> Edit UI โ”€โ”€> Next State (DB) โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
Transform โ”‚ with ChatPack
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚               THE CHATPACK WAY (NATIVE)                โ”‚
โ”‚       data = await Form([Step1, Step2]).run()          โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

โœจ Key Features

  • โšก Sequential Execution Runtime: Write complex multi-step interactive flows using clean, native await syntax without manually tracking user state histories.
  • ๐Ÿ’ก Dual Invocation APIs: Use standard Form-level tracking via ask() or pull pure scalar values directly using the modern standalone ask_value() method.
  • ๐Ÿงฉ Rich Interactive UI Suite: Out-of-the-box components for text fields, choice menus, channel subscription walls, star ratings, nested menus, and confirmation dialogs.
  • ๐Ÿงน Automated UI Cleanup: Optional engine routines to automatically flush intermediate prompt and response messages upon completion, keeping the user's chat history immaculate.
  • โš™๏ธ Zero Configuration Boilerplate: 100% granular control over localization, layouts, button labels, emojis, and custom input validation.

๐Ÿš€ Installation

Install the stable release directly from PyPI:

pip install chatpack-ui

โš ๏ธ Note: Requires Python 3.8+ and an active Pyrogram environment.


๐Ÿ’ก Architecture: ask() vs ask_value()

Every interactive component within ChatPack extends the BaseField core class and provides two flexible invocation patterns designed for distinct execution flows:

1. await component.ask(client, chat_id)

  • Returns: A Python tuple containing (validated_value, tracked_message_ids).
  • Best For: Inside the sequential Form context where tracking message IDs is required for automatic bulk UI wiping and history cleanup routines.

2. await component.ask_value(client, chat_id)

  • Returns: The raw, extracted scalar data type directly (bool, int, str, etc.).
  • Best For: Isolated, one-off standalone actions anywhere in your existing Pyrogram command handlers (e.g., verifying membership or checking a deletion prompt) without unpacking tuple wrappers manually.

โšก Quick Start

Here is how easily you can implement a sequential multi-step profile survey with built-in environment configurations and automated UI cleanup:

import os
from dotenv import load_dotenv
from pyrogram import Client, filters
from pyrogram.types import Message, CallbackQuery
from chatpack import Form, TextInput, SelectMenu
from chatpack.utils.listener import listener_manager

load_dotenv()

app = Client(
    "chatpack_production_bot",
    api_id=int(os.getenv("API_ID")),
    api_hash=os.getenv("API_HASH")),
    bot_token=os.getenv("BOT_TOKEN"),
)

@app.on_message(filters.private, group=-1)
async def chatpack_message_interceptor(client: Client, message: Message):
    if message.text == "/cancel":
        future = listener_manager._listeners.get(message.chat.id)
        if future and not future.done():
            future.set_result(message)
            message.stop_propagation()
            return
    if listener_manager.resolve(message.chat.id, message):
        message.stop_propagation()

@app.on_callback_query(group=-1)
async def chatpack_callback_interceptor(
    client: Client, callback_query: CallbackQuery
):
    if listener_manager.resolve(callback_query.message.chat.id, callback_query):
        await callback_query.answer()
        callback_query.stop_propagation()

@app.on_message(filters.command("survey") & filters.private)
async def survey_handler(client: Client, message: Message):
    form = Form(
        [
            TextInput(key="name", prompt="What is your name?"),
            SelectMenu(
                key="gender",
                prompt="Please select your gender:",
                options={"male": "๐Ÿ™‹โ€โ™‚๏ธ Male", "female": "๐Ÿ™‹โ€โ™€๏ธ Female"},
            ),
        ],
        timeout_per_field=60,
        cleanup=True,
    )

    data = await form.run(client, message.chat.id)

    if data:
        await message.reply(
            f"โœ… Thank you! Your profile has been updated, {data['name']}."
        )

if __name__ == "__main__":
    app.run()

๐Ÿงฉ Built-in Core Components

1. Action Confirmation (ConfirmDialog)

Perfect for verifying high-risk actions (like deleting accounts or flushing data) using native boolean checks via ask_value():

from chatpack.components.confirm import ConfirmDialog

dialog = ConfirmDialog("Are you sure you want to permanently delete your data?")
confirmed = await dialog.ask_value(client, message.chat.id, timeout=30)

if confirmed:
    await message.reply("Data successfully wiped.")

2. Mandatory Membership Gate (JoinChecker)

Restrict bot access until the user joins specific sponsor channels. Features dynamic API validation and customizable popup alerts:

from chatpack import JoinChecker

checker = JoinChecker(
    key="force_join",
    prompt="๐Ÿ”’ **Access Restricted**\n\nPlease join our channel to unlock features:",
    channels=["@backpack_dev"],
    mode="all",
    button_text="Verify Membership ๐Ÿ”„",
    not_joined_alert="๐Ÿ›‘ Verification failed! Please join the channel first.",
)
is_allowed = await checker.ask_value(client, message.chat.id, timeout=180)

3. Interactive Star Ratings (RatingStars)

Collect customer satisfaction scores or performance metrics directly on a single message layout with live UI state updates:

from chatpack import RatingStars

rating = RatingStars(
    key="feedback",
    prompt="โญ๏ธ **Rate Our Service**\n\nHow would you rate your experience?",
    max_stars=5,
    submit_button_text="Submit Rating ๐Ÿ“ค",
    success_message_format="โœจ **Recorded!** Thanks for rating us {stars} Stars",
)
score = await rating.ask_value(client, message.chat.id, timeout=60)

4. Dynamic Nested Menus (NestedMenu)

Build deep, multi-tiered interactive navigation catalogs inside a single message using simple python nested dictionaries:

from chatpack import NestedMenu

catalog = {
    "๐Ÿ’ป Development": {
        "๐Ÿ Python": {"FastAPI": "f_api", "Django": "dj_web"}
    },
    "๐Ÿง DevOps": "linux_core"
}

menu = NestedMenu(
    key="catalog",
    prompt="๐Ÿ“‚ **Explore Catalog**\n\nSelect a path:",
    menu_data=catalog,
)
selected_node = await menu.ask_value(client, message.chat.id)

5. Media & Content Broadcast (BroadcastSender)

An administrative engine that safely intercepts any update message type (text, photos, video logs, files) and replicates it across a list of target users sequentially:

from chatpack import BroadcastSender

sender = BroadcastSender(
    user_ids=[12345678, 87654321],
    prompt="๐Ÿš€ Forward or send the message you want to broadcast to everyone:",
)
stats = await sender.ask_value(client, message.chat.id, timeout=300)

6. Anti-Flood Bulk Writer (ChunkSender)

Transmit massive telemetry outputs, server metrics, or text structures exceeding Telegram's 4,096-character limit safely without breaking line words:

from chatpack import ChunkSender

await ChunkSender.send(
    client=client,
    chat_id=message.chat.id,
    text="Your huge application log context data...",
    max_chars=4000,
    delay=0.2,
)

๐Ÿ‘ฅ Support & Community

For queries, feature requests, or custom engineering integrations, connect via official channels:

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ TYPE                      โ”‚ LOCATION                             โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ ๐Ÿ“ข Telegram Channel       โ”‚ [https://t.me/backpack_dev](https://t.me/backpack_dev)            โ”‚
โ”‚ ๐Ÿ‘จโ€๐Ÿ’ป Personal Developer     โ”‚ [https://t.me/thenewbiebackpack](https://t.me/thenewbiebackpack)       โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜


โš–๏ธ License

Distributed under the MIT License. Feel free to use, modify, and build scalable automation ecosystems with it.

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

chatpack_ui-1.0.3.tar.gz (17.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

chatpack_ui-1.0.3-py3-none-any.whl (18.6 kB view details)

Uploaded Python 3

File details

Details for the file chatpack_ui-1.0.3.tar.gz.

File metadata

  • Download URL: chatpack_ui-1.0.3.tar.gz
  • Upload date:
  • Size: 17.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for chatpack_ui-1.0.3.tar.gz
Algorithm Hash digest
SHA256 b1d608c7bd62f77659c423825f0b10bdaa3144b3e9614fe5a46d9506f5367f3b
MD5 da9d617461f91400d51e19e8fbddf9f3
BLAKE2b-256 da8d98e20ca6f058e58ab99181f008c5a77f69e796f33648c014457b3e4861a8

See more details on using hashes here.

File details

Details for the file chatpack_ui-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: chatpack_ui-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 18.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for chatpack_ui-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 c47eb3a9ec8eca0317df0df6087a63588b2cd5dfdc9d64a3909982f3d2d9b2b7
MD5 a7840ae983d47a231beef50149919141
BLAKE2b-256 b306db256ff8fadedce04d3bfd650e19aa91f102e22b006b20a73aca8cac3458

See more details on using hashes here.

Supported by

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