3

There is api method messages.getReplies in Telegram API and the equivalent of the same is functions.messages.GetRepliesRequest in the Telethon. But this method is not returning the expected replies/comments to the post. Instead, it returns multiple messages including the replies to the requested message_id and other messages also which are not even the replies to the requested message_id.

for conv in client.iter_messages(channel.id):
    if conv.reply_to:
       # get parent message this message reply to
       original_message = conv.get_reply_message()  
       try:
           #iterate all the replies for the parent message
           for reply in client.iter_messages(channel.id,
                                          reply_to=original_message.id):
               print('\tReply message  -> ', reply.to_dict())
       except telethon.errors.rpcerrorlist.MsgIdInvalidError:
             print('exception ***************')

Here it returns the replies to the input message.id in the argument reply_to including the messages which are not the replies to the input message.id.

(I checked the response from of the method call(inner for loop) and their reply_to_msg_id differs from what i requested to get the result).

I could not understand the behaviour of these replies getting in the result.

Also Telegram API docs are not good in shape with example and explantion.

  • What and how messages are considered as reply to the message in the telegram?
  • How telegram decides upon the messages whether it is a reply or a normal message?
  • if a message is reply, then to which message this is a reply?
John Byro
  • 674
  • 3
  • 13

1 Answers1

1

Given a broadcast channel with comments enabled (let's say the channel's username is username), and a post with a discussion started (comments) for the channel post with message ID 1001, the following code will print all comments for post 1001 in channel username:

async for m in client.iter_messages('username', reply_to=1001):
    print(m.text)

This is equivalent to clicking on the "# comment(s)" button in Telegram Desktop. Unfortunately I was not able to reproduce what you mention here:

But this method is not returning the expected replies/comments to the post. Instead, it returns multiple messages including the replies to the requested message_id and other messages also which are not even the replies to the requested message_id.

Now, for the other questions:

What and how messages are considered as reply to the message in the telegram?

Let's look at the problem from a different angle: send_message with comment_to.

First, messages.getDiscussionMessage must be used on the source broadcast channel with the source message ID. This will return the corresponding "discussion message" in the linked "discussion megagroup channel".

Now, messages.sendMessage can be used to send a message in the linked discussion megagroup channel to reply to the corresponding discussion message.

As you can see, "comments" are simply "replies to" the corresponding message of the discussion group. Hence the name, reply_to, during iter_messages.

How telegram decides upon the messages whether it is a reply or a normal message?

In a given chat, messages can reply to other previous messages in the same chat (in Telethon, message.reply_to). However, for channel comments, they're also replies in a way (just in a different chat), hence the parameter name. I tried to stick with Telegram's naming convention and solve the confusion by documenting the parameter but that might've been the wrong choice.

if a message is reply, then to which message this is a reply?

This can be found through message.reply_to.

Lonami
  • 5,945
  • 2
  • 20
  • 38