Conversation-Pyrogram
A conversation plugin class for pyrogram using inbuild Update Handlers
Complete list of handlers to be used without Handlers postfix :-
https://docs.pyrogram.org/api/handlers#index
Installation
Use the package manager pip to install or simply copy the class file to your project.
pip install git+https://github.com/Ripeey/Conversation-Pyrogram
Basic Usage
main.py Where the Client is initialized
from pyrogram import Client
from convopyro import Conversation
app = Client('MyApp')
Conversation(app) # That's it!
Then at any update handler
answer = client.listen.CallbackQuery(filters.user(update.from_user.id))
Example
from pyrogram import Client, filters
from pyrogram.types import Message, InlineKeyboardButton, InlineKeyboardMarkup, CallbackQuery
from convopyro import listen_message, stop_listen
@Client.on_message(filters.command(["start"], ["!",".","/"]) & filters.private)
async def start(client:Client, message:Message):
await client.send_message(
chat_id = message.chat.id,
text = "What's your name?",
reply_markup = InlineKeyboardMarkup(
[[InlineKeyboardButton(text="Stop Listen", callback_data="stop_listen")]]
)
)
answer = await listen_message(client, message.chat.id, timeout=None)
if answer:
await answer.reply(f"hello {answer.text}")
else:
await message.reply("Canceled Answer")
@Client.on_callback_query(filters.regex(pattern=r"^stop_listen$"))
async def listen_stopped(client:Client, callback_query:CallbackQuery):
await stop_listen(client, callback_query.from_user.id)
await callback_query.message.delete()
Advanced Usage
The conversation class has 2 primary methods listen.Handler (Handlers like Message, CallbackQuery ...etc) and listen.Cancel for ending an ongoing listener.
listen.Handler()
The conversation listen.Message (or any other Handler) takes 3 parameters, default is None but either filter or id as parameter is required.
-
filters : Single or Combined is required but this is optional if
idis passed with a valid single user or chat filter (which will learn below). -
id : An unique id for each listen, this could be str, a single user filter or chat filter, this is mostly optional and only needed to
Cancel()a conversation listen. If user/chat filter is passed then it combines itself withfiltersso you dont need to repeat again infiltersusing&, where as if str is used it's just used normally asid. -
timeout : Waiting time in seconds int for getting a response optional.
Return
- Update : Based on handlers used could be one of received updates such as Message, CallbackQuery, etc.
- None : When listen gets cancel using
listen.Cancela None is return as response at listen callback. - Exception : An
asyncio.TimeoutErroris raised if provided waiting time get's over.
listen.Cancel()
The conversation listen.Cancel takes 1 required parameter. This method is used to cancel a specific conversation listen.
- id : An unique id provided during listen, this could be str, a single user filter or chat filter.
Return
- Boolean : False if
idprovided already cancelled or invalid.
Example
@app.on_callback_query(filters.regex(r'stop'))
async def _(client, query):
# This will return response None at listen
await client.listen.Cancel(filters.user(query.from_user.id))
@app.on_message(filters.regex(r'hi'))
async def _(client, message):
button = InlineKeyboardMarkup([[InlineKeyboardButton('Cancel Question', callback_data = 'stop')]])
question = await client.send_message(message.chat.id, 'Enter your name in 5s.', reply_markup = button)
# A nice flow of conversation
try:
response = await client.listen.Message(filters.text, id = filters.user(message.from_user.id), timeout = 5)
except asyncio.TimeoutError:
await message.reply('Too late 5s gone.')
else:
if response:
await response.reply(f'Hello {response.text}')
else:
await message.reply('Okay cancelled question!')
finally:
await question.delete()
Metadata
Release files for convopyro 0.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| convopyro-0.5.tar.gz | 5.5 kB | Without provenance | Details for convopyro-0.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| convopyro-0.5-py3-none-any.whl | Python 3 | none | any | Details for convopyro-0.5-py3-none-any.whl |
Total release size: 11.4 kB
Release files / convopyro-0.5.tar.gz
| Download URL | convopyro-0.5.tar.gz |
|---|---|
| Size | 5.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
26bbebc90d48b8f96da371df9246cd63545273c2f9af0bd835b1e1119d4e5f90
|
|
BLAKE2b-256 checksum How to use checksums |
7652f7bded3158d6f2a912ccb636e95b45dd653f2360398f35cb5e0662bf07c0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.8
|
Release files / convopyro-0.5-py3-none-any.whl
| Download URL | convopyro-0.5-py3-none-any.whl |
|---|---|
| Size | 5.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2db5c99e460c47779241a9a876cbc5254fa838e32d47770abafc086fe8835383
|
|
BLAKE2b-256 checksum How to use checksums |
14e0f8d2c09dd5810c48cf3dafb0bad03779da5039cf0beaa5c19ca06b414a6e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.8
|
Security for convopyro 0.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.