LonamiWebs / Telethon

Pure Python 3 MTProto API Telegram client library, for bots too!
https://docs.telethon.dev
MIT License
10.01k stars 1.41k forks source link

Clicking (using telethon) ➡️emoji on inline keyboard throws an error . #4147

Closed hammersharkfish closed 1 year ago

hammersharkfish commented 1 year ago

Code that causes the issue

async def take_group_action(message,):
    print("Clicking...")

    for _ in ["auto", "➡️"]:
        await message.click(text=_) 

Expected behavior

User clicks the button .

Actual behavior

Correctly clicks on button which has the text "auto". Throws error when clicking on inline button having text "➡️" .

Traceback

Unhandled exception on signal_tg1_initial_sales_tax
Traceback (most recent call last):
  File "C:\Users\work\AppData\Local\Programs\Python\Python310\lib\site-packages\telethon\client\updates.py", line 543, in _dispatch_update
    await callback(event)
  File "C:\Work\gaurav joshi sniper bot\main.py", line 203, in signal_tg1_initial_sales_tax
    await take_group_action(client.msg, wallet_count * [auto_cross_position_text, next_position_text])
  File "C:\Work\gaurav joshi sniper bot\main.py", line 139, in take_group_action
    await message.click(row, col)
  File "C:\Users\work\AppData\Local\Programs\Python\Python310\lib\site-packages\telethon\tl\custom\message.py", line 1037, in click
    return await button.click(
  File "C:\Users\work\AppData\Local\Programs\Python\Python310\lib\site-packages\telethon\tl\custom\messagebutton.py", line 107, in click
    return await self._client(req)
  File "C:\Users\work\AppData\Local\Programs\Python\Python310\lib\site-packages\telethon\client\users.py", line 30, in __call__
    return await self._call(self._sender, request, ordered=ordered)
  File "C:\Users\work\AppData\Local\Programs\Python\Python310\lib\site-packages\telethon\client\users.py", line 83, in _call
    result = await future
telethon.errors.rpcerrorlist.DataInvalidError: Encrypted data invalid (caused by GetBotCallbackAnswerRequest)

Telethon version

1.28.5

Python version

3.x

Operating system (including distribution name and version)

windows 10

Other details

No response

Checklist

hammersharkfish commented 1 year ago

Incoming message: Message(id=23833, peer_id=PeerUser(user_id=5047380096), date=datetime.datetime(2023, 7, 16, 6, 52, 24, tzinfo=datetime.timezone.utc), message='📌Primary Trade 3%🇸6%', out=False, mentioned=False, media_unread=False, silent=False, post=False, from_scheduled=False, legacy=False, edit_hide=False, pinned=False, noforwards=False, from_id=None, fwd_from=None, via_bot_id=None, reply_to=None, media=None, reply_markup=ReplyInlineMarkup(rows=[KeyboardButtonRow(buttons=[KeyboardButtonCallback(text='Maestro', data=b'maestro', requires_password=False), KeyboardButtonCallback(text='Sniper Bot', data=b'sniper', requires_password=False)]), KeyboardButtonRow(buttons=[KeyboardButtonCallback(text='⬅️', data=b'back', requires_password=False), KeyboardButtonCallback(text='🔃GTAN', data=b'\xf0\x9f\x94\x84', requires_password=False), KeyboardButtonCallback(text='➡️', data=b'forward0', requires_password=False)]), KeyboardButtonRow(buttons=[KeyboardButtonCallback(text='p1', data=b'asdsad', requires_password=False), KeyboardButtonCallback(text='auto', data=b'buy', requires_password=False), KeyboardButtonCallback(text='p2', data=b'sell', requires_password=False)])]), entities=[], views=None, forwards=None, replies=None, edit_date=None, post_author=None, grouped_id=None, reactions=None, restriction_reason=[], ttl_period=None) ^ The message .

Lonami commented 1 year ago

The UTF-8 encoded bytes of your emoji string must match exactly with those of the button. This includes any modifiers, visible or not.

You can click by index or find the button doing your own comparisons instead.

Otherwise it would be helpful to have a dump of the messge to learn what the buttons look like. As it stands this issue is not actionable.

hammersharkfish commented 1 year ago

Incoming message: Message(id=23833, peer_id=PeerUser(user_id=5047380096), date=datetime.datetime(2023, 7, 16, 6, 52, 24, tzinfo=datetime.timezone.utc), message='📌Primary Trade 3%🇸6%', out=False, mentioned=False, media_unread=False, silent=False, post=False, from_scheduled=False, legacy=False, edit_hide=False, pinned=False, noforwards=False, from_id=None, fwd_from=None, via_bot_id=None, reply_to=None, media=None, reply_markup=ReplyInlineMarkup(rows=[KeyboardButtonRow(buttons=[KeyboardButtonCallback(text='Maestro', data=b'maestro', requires_password=False), KeyboardButtonCallback(text='Sniper Bot', data=b'sniper', requires_password=False)]), KeyboardButtonRow(buttons=[KeyboardButtonCallback(text='⬅️', data=b'back', requires_password=False), KeyboardButtonCallback(text='🔃GTAN', data=b'\xf0\x9f\x94\x84', requires_password=False), KeyboardButtonCallback(text='➡️', data=b'forward0', requires_password=False)]), KeyboardButtonRow(buttons=[KeyboardButtonCallback(text='p1', data=b'asdsad', requires_password=False), KeyboardButtonCallback(text='auto', data=b'buy', requires_password=False), KeyboardButtonCallback(text='p2', data=b'sell', requires_password=False)])]), entities=[], views=None, forwards=None, replies=None, edit_date=None, post_author=None, grouped_id=None, reactions=None, restriction_reason=[], ttl_period=None) ^ The message .

The messageis here

Lonami commented 1 year ago

Right, I had the issue open before you posted that, so I did not see your comment.

The text seem to match.

You could try clicking by b'forward0' data directly instead.

If the message was edited or the message you're using to click on is wrong, Telegram will complain.

If message.click still fails even if you use data directly, but you can get it to work with the raw API method, then there may be something to fix.