0

This represent the Telethon request to send the reaction on the post of the public channel.when run the code I got some error when the code try to run this "SendReactionRequest" they catch the error of TLC object

import asyncio
from telethon.sync import TelegramClient
from telethon.tl.functions.channels import GetFullChannelRequest
from telethon.tl.functions.messages import SendReactionRequest

async def send_reaction(client, chat_id, message_id):
    try:
        await client(SendReactionRequest(
            peer=chat_id,
            msg_id=message_id,
            big=True,
            add_to_recent=True,
            reaction=''
        ))
        print('Reaction sent successfully')
    except Exception as e:
        print("Error sending reaction:", str(e))

async def main(phone):
    async with TelegramClient(f'sessions/{phone}', APIID, 'HashXXXX') as client:
        if not await client.is_user_authorized():
            print(f'{phone} needs to be authenticated by OTP')
            return

        chat_id = 'ViewTestChannel12'
        message_id = 9

        await send_reaction(client, chat_id, message_id)

with open('phone.csv', 'r') as file:
    phones = file.read().splitlines()

async def run_main():
    for phone in phones:
        await main(phone)

asyncio.run(run_main())
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Aug 11 '23 at 17:38

1 Answers1

0

Raw API (when you use client(SomeRequest(...))) is subject to change across minor versions of the library. In this case, older versions of the request used just a string for the emoji, but it is now (as of v1.29) a Reaction as you can see in SendReactionRequest:

result = client(functions.messages.SendReactionRequest(
    peer=chat_id,
    msg_id=message_id,
    big=True,
    add_to_recent=True,
    reaction=[types.ReactionEmoji(
        emoticon=''
    )]
))

(If copy pasting the emoji doesn't work, try using the correct unicode escape sequence.)

Lonami
  • 5,945
  • 2
  • 20
  • 38