Telethon
Telethon copied to clipboard
Emty reply_to field in sended message with reply
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.
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)
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)
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
.