Skip to main content

A monkeypatcher add-on for Pyrogram that does conversation handling

Project description

pyromod

Telegram GitHub release (latest by date) Downloads Downloads

pyromod is a versatile Python add-on for the Pyrogram library, designed to make developing Telegram bots faster and more efficient.

It's based on monkeypatching, which means it works together with Pyrogram, rather than being a fork or modified version. It adds features to Pyrogram classes on the go, so you don't need to update it every time Pyrogram is updated.

Whether you're building a simple chatbot or a complex form to get multiple responses from the user, pyromod has you covered. It enhances Pyrogram with a range of advanced features, simplifies conversation handling, and offers a high degree of customizability.

Key Features

  • Effortless Bot Development: pyromod streamlines the process of building conversational Telegram bots, saving you time and effort during development.

  • Advanced Conversation Management: Managing conversations with users is made easier, allowing you to create dynamic and interactive interactions much easier, without having to save states anywhere, by leveraging the power of async/await syntax.

  • Effortless Inline Keyboards Creation: Creating inline keyboards is easier than ever with pyromod's inline keyboard helper functions.

  • User-Friendly Pagination: Enhance the user experience by providing easy navigation tools with the pyromod's pagination helpers.

  • Highly Customizable: pyromod's configuration options let you customize its behavior to meet your specific project requirements.

Examples

Awaiting a single message from a specific chat:

response = await client.listen(chat_id=chat_id)

Awaiting a single message from a specific user in a specific chat:

response = await client.listen(chat_id=chat_id, user_id=user_id)

Asking the user a question then await for the response:

response = await client.ask(chat_id=chat_id, text='What is your name?')

Asking the user a question then await for the response, with a timeout:

try:
    response = await client.ask(chat_id=chat_id, text='What is your name?', timeout=10)
except ListenerTimeout:
    await message.reply('You took too long to answer.')

Full handler example, getting user's name and age with bound method Chat.ask:

from pyromod import Client, Message
from pyrogram import filters


@Client.on_message(filters.command('form'))
async def on_form(client: Client, message: Message):
    chat = message.chat

    name = await chat.ask('What is your name?', filters=filters.text)
    age = await chat.ask('What is your age?', filters=filters.text)

    await message.reply(f'Your name is {name.text} and you are {age.text} years old.')

Easier inline keyboard creation:

from pyromod.helpers import ikb

keyboard = ikb([
    [('Button 1', 'callback_data_1'), ('Button 2', 'callback_data_2')],
    [('Another button', 't.me/pyromodchat', 'url')]
])

Installation

To get started with pyromod, you can install it using pip:

pip install pyromod

Or poetry:

poetry add pyromod

Or rye:

rye add pyromod

Initialization

To initialize pyromod, on the file that creates the client instance, simply import the Client class from pyromod instead of pyrogram:

from pyromod import Client

And that's all! You can still use the Client class as you would normally do with Pyrogram, but now having all the extra features.

You don't need to change the imports on the plugins files. Even by importing Client from pyrogram, the pyromod features will be available anyway. In order to monkeyatch pyromod features successfully, it's just required that the first Client class imported to your project code should be from pyromod. Then all the other future Client instances will be patched automatically.

You just need to import from pyromod if you want your IDE to recognize and suggest the extra features based on pyromod.Client type.

Contributing

We welcome contributions from the community to make pyromod even better.

Feel free to open issues, submit pull requests, or contribute in any way that aligns with our goals.

Copyright & License

This project may include snippets of Pyrogram code

Licensed under the terms of the GNU Lesser General Public License v3 or later (LGPLv3+)

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

pyromod-3.0.1.tar.gz (11.3 kB view details)

Uploaded Source

Built Distribution

pyromod-3.0.1-py3-none-any.whl (33.0 kB view details)

Uploaded Python 3

File details

Details for the file pyromod-3.0.1.tar.gz.

File metadata

  • Download URL: pyromod-3.0.1.tar.gz
  • Upload date:
  • Size: 11.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.10.12 Linux/5.15.0-76-generic

File hashes

Hashes for pyromod-3.0.1.tar.gz
Algorithm Hash digest
SHA256 fdf38190916c8097b059992cf8b89f2a802bb48d3cef9d4a2ac999c23f420f18
MD5 d140b8d46e57f512f24990f5faee3ff4
BLAKE2b-256 c5e18da803ac32e61848a8ecc14d79c6e9c400fdb3fbf9f1ba572527caa7b7e8

See more details on using hashes here.

File details

Details for the file pyromod-3.0.1-py3-none-any.whl.

File metadata

  • Download URL: pyromod-3.0.1-py3-none-any.whl
  • Upload date:
  • Size: 33.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.10.12 Linux/5.15.0-76-generic

File hashes

Hashes for pyromod-3.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cb2516dc9919a05540d01adb5a61e608869e6d341578e08f31d599ab939014be
MD5 28c31a0588eb3844ad58a4b42b8fa5b8
BLAKE2b-256 56abfabaacf4a869144b1f3e0944f9dad4a8c70ee02f969d878a657fe56eaf39

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