简体   繁体   English

电报API(不是Bot!):如何通过链接获取聊天/频道ID?

[英]Telegram API (not Bot!): How to get chat/channel ID by link to it?

I'm using library TLSharp on C# and writing Telegram client, and at some moment I got stuck. 我在C#上使用库TLSharp并编写Telegram客户端,有时我陷入困境。

I have a link to chat/channel, for instance, https://t.me/joinchat/some-string , and I'd like to get info about the chat/channel or join it. 我有一个指向chat / channel的链接,例如https://t.me/joinchat/some-string ,我想获取有关chat / channel的信息或加入它。 But you can do that only having chat_id, which I don't know how to get. 但是您只有拥有chat_id才能做到这一点,而我不知道该如何获取。

Firstly I thought about contacts.resolveUsername and passing it "some-string" from the link. 首先,我考虑了contacts.resolveUsername,并从链接中传递了“ some-string”。 But it doesn't work, saying that the username is invalid. 但这无效,因为用户名无效。

Is there any way to get ID of a group? 有什么方法可以获取组的ID? And was it on purpose to make it so complicated to get info about groups? 故意使获取组信息变得如此复杂吗?

Thanks 谢谢

Well, I've found the solution (partial, see the end). 好吧,我已经找到了解决方案(部分,请参见结尾)。 I'm using this schema, to let you know. 我正在使用架构,以告知您。

  1. First of all we need to send RPC messages.checkChatInvite with parameter hash set to last part of your link ("some-string" in my case). 首先,我们需要发送RPC message.checkChatInvite,并将参数哈希设置为链接的最后一部分(在我的情况下为“ some-string”)。

  2. A response of type TLChatInvite arrives. TLChatInvite类型的响应到达。 It will contain primary info about the group: it's type (chat or channel?), participant count and, if you're lucky, they themselves as Vector. 它将包含有关该组的主要信息:它的类型(聊天还是频道?),参加者人数,如果幸运的话,它们本身也可以作为Vector。

(This point below was the problem of mine) (这是我的问题)

  1. Call the RPC messages.importChatInvite with the same parameter hash. 使用相同的参数哈希调用RPC messages.importChatInvite It returns TLUpdates or TLUpdatesCombined object, which will contain a vector of TLChat objects. 它返回TLUpdatesTLUpdatesCombined对象,其中将包含TLChat对象的向量。 We will need to use the first (don't forget to check the vector for emptiness, though, just in case). 我们将需要使用第一个(不过,以防万一,请不要忘记检查向量是否为空)。

However, messages.importChatInvite will make the current user join the group. 但是, messages.importChatInvite将使当前用户加入该组。 How to get the ID of the group without getting joined to it I haven't got a clue. 如何获得该组的ID而又不加入该组,我一无所知。 Though, this thing would fit for my client. 虽然,这东西适合我的客户。

Frankly said, I'm disappointed it consumed so much time for such a trivial thing. 坦率地说,我很失望它花了这么多时间来处理如此琐碎的事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM