Reactions to messages Telegram/Telethon

Viewed 1356
2 Answers

I couldn't find a way to do this via telethon. However, you can get a list of reactions to messages using pyrogram: GetMessageReactionsList

Something like that:

from pyrogram import Client
from pyrogram.raw.functions.messages import GetMessageReactionsList


app = Client(
    "my_account",
    api_id=12345678,
    api_hash='XXX'
)

chat_id = -123456789

with app:
    peer = app.resolve_peer(chat_id)

    for message in app.iter_history(chat_id=chat_id):
        reactions = app.send(
            GetMessageReactionsList(
                peer=peer,
                id=message.message_id,
                limit=100
            )
        )

UPD Found an easier way:

with app:
    peer = app.resolve_peer(chat_id)

    for message in app.iter_history(chat_id=chat_id):
        print(message.reactions)

I recently was looking for reactions as well and discovered the GetMessagesReactionsRequest() function from the Telegram API methods list:

with TelegramClient(session, api_id, api_hash) as client:
     reaction = client(GetMessagesReactionsRequest(chat_test, id=[4775]))

Where ID is the message ID. There might be a more efficient solution, as soon as I found it I'll let you know.

Related