如何使用telethon中的getReplipeRequest呼叫

发布于 2025-02-01 13:13:44 字数 1351 浏览 4 评论 0原文

有API方法 message.getReplies 在telegram api中,同等的是 functions.messages.messages.getRepliesRepliesRequest TELETHON中。 但是,此方法没有将预期的答复/评论返回到帖子中。取而代之的是,它返回多个消息,包括对所请求的Message_ID和其他消息的答复,甚至还不是对所请求的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 ***************')

在这里,它将答复返回到参数revery_to中的输入消息。

(我检查了方法调用的响应(内部循环)及其revery_to_to_msg_id与我要求获得结果的响应不同)。

我无法理解这些答复的行为。

另外,Telegram API文档在示例和外观上的形状不好。

  • 什么消息被视为回复对电报中的消息?
  • 电报如何决定消息是回复还是普通消息?
  • 如果消息是答复,那么这是一个答复?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半边脸i 2025-02-08 13:13:44

给定一个启用注释的广播频道(例如,频道的用户名是用户名),以及带有消息ID 1001的频道帖子开始(注释)的帖子,以下代码将打印所有注释对于Channel 用户名中的1001张,

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

这等同于单击Telegram桌面中的“#comment(s)”按钮。不幸的是,我无法在这里复制您提到的内容:

但是,此方法没有将预期的答复/评论返回到帖子中。相反,它返回多个消息,包括对所请求的消息_ID和其他消息的答复,这甚至不是请求的message_id的答复。

现在,对于其他问题:

如何将消息视为电报中对消息的答复?

让我们从不同角度看一下问题:send_message comment_to

首先,message.getDiscussionMessage必须在源广播频道上使用源消息ID使用。这将返回链接的“讨论Megagroup频道”中的相应“讨论消息”。

现在,Message.SendMessage可以使用链接的讨论中的消息将消息发送到回复对相应的讨论消息。

如您所见,“注释”只是“回复”讨论组的相应消息。因此,名称,回复>iter_messages

电报如何确定消息是回复还是普通消息?

在给定的聊天中,消息可以在同一聊天中回复其他以前的消息(在Telethon,Message.reply_to)中。但是,对于频道评论,它们也以某种方式回答(只是在不同的聊天中),因此参数名称。我试图坚持电报的命名惯例,并通过记录参数来解决混乱,但这可能是错误的选择。

如果消息是回复,那么这是哪个消息?

这可以通过message.reply_to找到。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文