Answer the question
In order to leave comments, you need to log in
How to parse telegram posts using pyrogram?
Hi, I couldn’t figure out the pyrogram documentation and didn’t find how I can receive posts from a channel in telegram live. I would be extremely grateful even for hints or links to the dock
Answer the question
In order to leave comments, you need to log in
First you need to know the ID of the target channel. This can be done using third-party Telegram clients (Kotatogram for PC or Graph for Android, for example).
Then write the following message handler that will only respond to messages from the channel whose ID is set by the CHANNEL_ID variable:
from pyrogram import Client
from pyrogram import types, filters
CHANNEL_ID = -11012345678
app = Client(
"my_account",
api_id=12345,
api_hash="0123456789abcdef0123456789abcdef"
)
@app.on_message(filters=filters.channel)
def my_handler(client: Client, message: types.Message):
if message.chat.id != CHANNEL_ID:
return
print("Получено новое сообщение с ID", message.message_id)
# Как-то обработать сообщение с канала, например, напечатать его текст
print("Текст:", message.text)
app.run()
@app.on_message(filters=filters.channel & ~filters.edited)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question