Telethon icon indicating copy to clipboard operation
Telethon copied to clipboard

Emty reply_to field in sended message with reply

Open tizhproger opened this issue 2 years ago • 2 comments

Checklist

  • [X] The error is in the library's code, and not in my own.
  • [X] I have searched for this issue before posting it and there isn't a duplicate.
  • [X] I ran pip install -U https://github.com/LonamiWebs/Telethon/archive/master.zip and triggered the bug in the latest version.

Code that causes the issue

@client.on(events.NewMessage(incoming=True))
async def incoming(event):
    if event.message.text.startswith('.'):
        reply = await event.message.get_reply_message()
        msg = await client.send_message(event.message.chat_id, event.message.text, reply_to=reply)

When user is sending me a message with reply (to other message in our chat), I am trying to reply on the message he mentioned (initially replied). To do that, I tried to get this message with get_reply_message(), which does the thing, but then I add it to send_message(reply_to=...), my sended message object showing empty reply_to field. I have tried to use message.id instead (no luck), iterated through chat messages searching for the right one with get_messages() and passing it to reply_to (in case we have different message ids, also no luck). The strange thing here, is that I see my sended message is with reply, but field in object is still empty. In the official Telegram app it looks fine, I see the reply on it. But on the bot side, reply_to is empty.

photo_2022-04-14_02-07-44

photo_2022-04-14_02-09-08

photo_2022-04-14_02-09-53

tizhproger avatar Apr 13 '22 23:04 tizhproger

https://docs.telethon.dev/en/stable/modules/custom.html#telethon.tl.custom.message.Message.is_reply What I did was validate if the message has a response, I did this with event.message.reply_to and you can support yourself with the id of the message that is being answered. And you can reply with await client.send_message (entity, 'Hi', reply_to=Id)

devmexican avatar May 06 '22 23:05 devmexican

https://docs.telethon.dev/en/stable/modules/custom.html#telethon.tl.custom.message.Message.is_reply What I did was validate if the message has a response, I did this with event.message.reply_to and you can support yourself with the id of the message that is being answered. And you can reply with await client.send_message (entity, 'Hi', reply_to=Id)

I tried to use the id of message I want reply to, it worked, but send_message returns Message object with empty reply_to. The only way to get my own sended message with reply, was to use get_messages with it's id. But this way is not a fix, it is a temporary solution, like this:

if event.message.is_reply:
      reply_msg = await event.message.get_reply_message()
      msg = await client.send_message(event.message.chat_id, message=event.message.text, reply_to=reply_msg)
else:
      msg = await client.send_message(event.message.chat_id, message=event.message.text, reply_to=event.message)
                
reply = await event.client.get_messages(event.chat, ids=msg.id)

tizhproger avatar May 07 '22 01:05 tizhproger

When sending a message, Telegram responds with an updates about the new message. However this can sometimes be "short" which doesn't include all information back (including reply_to). The above commit "fakes" this field with the value specified by the user but it may still differ from what you would get if you were to use get_messages.

Lonami avatar Sep 20 '22 14:09 Lonami