英文:
how to get channel's data list from Telegram by TDLib?
问题
Telegram,我需要获取频道的数据列表。
我在这种情况下使用 TdApi。
文档:https://javadoc.tlgrm.ru/org/drinkless/td/libcore/telegram/TdApi.html
我基于这个示例进行操作:https://core.telegram.org/tdlib/tdlib.zip。
我仍然通过这个示例得到了聊天列表。请查看这里我的方法:
private suspend fun getChatIds(): LongArray {
val getChats = TdApi.GetChats(TdApi.ChatListMain(), Long.MAX_VALUE, 0, 50)
val chats = client.send<TdApi.Chats>(getChats)
return chats.chatIds
}
suspend fun getChats(): List<TdApi.Chat> = getChatIds()
.map { ids -> getChat(ids) }
suspend fun getChat(chatId: Long): TdApi.Chat {
return client.send<TdApi.Chat>(TdApi.GetChat(chatId))
}
我尝试通过添加文档中的类进行修改。Channel,ChannelFull 以及 GetChannelFull。我将 GetChannelFull 添加到 Function 类中。在问题中,我通过 isChannel 过滤聊天,并尝试通过 supergroupId 获取频道。
suspend fun getChannels(): List<TdApi.ChannelFull> {
return getChats().filter { chat -> chat.type is TdApi.ChatTypeSupergroup && (chat.type as TdApi.ChatTypeSupergroup).isChannel }
.map { chat -> getChannel((chat.type as TdApi.ChatTypeSupergroup).supergroupId) }
}
但是,我得到了错误:检查 'request.function' 失败。
如果您知道问题出在哪里,请帮助我。
英文:
Telegram, I need to get channel's data list.
I use for this case TdApi.
Documentation: https://javadoc.tlgrm.ru/org/drinkless/td/libcore/telegram/TdApi.html
I do it based on this example: https://core.telegram.org/tdlib/tdlib.zip.
I still got chat's list by this example. Check here my way:
private suspend fun getChatIds(): LongArray {
val getChats = TdApi.GetChats(TdApi.ChatListMain(), Long.MAX_VALUE, 0, 50)
val chats = client.send<TdApi.Chats>(getChats)
return chats.chatIds
}
suspend fun getChats(): List<TdApi.Chat> = getChatIds()
.map { ids -> getChat(ids) }
suspend fun getChat(chatId: Long): TdApi.Chat {
return client.send<TdApi.Chat>(TdApi.GetChat(chatId))
}
enter code here
I tried to modificate this by adding classe from documentation. Channel, ChannelFull GetChannelFull. I added GetChannelFull into Function class. In the issue I filter chats by isChannel and try to get Channel by supergroupId.
suspend fun getChannels(): List<TdApi.ChannelFull> {
return getChats().filter {chat -> chat.type is TdApi.ChatTypeSupergroup && (chat.type as TdApi.ChatTypeSupergroup).isChannel }
.map { chat -> getChannel((chat.type as TdApi.ChatTypeSupergroup).supergroupId) }
}
But, I get error: Check 'request.function' failed.
If you know what is that problem, please, help me.
答案1
得分: 1
我找到了一个解决方法。例如,有一个SupergroupFullInfo类,以及Chat类的ChatType。我将使用ChatType中的suprgroupId,并使用GetSupergroupFullInfo来获取所需信息。
英文:
I've found a resolve. In example there is SupergroupFullInfo class, and ChatType for Chat class. I will use suprgroupId from ChatType and GetSupergroupFullInfo for getting needed info.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论