问题描述
电报,我需要获取频道的数据列表。 我在这种情况下使用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,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
我试图通过添加文档中的类来对此进行修改。 Channel,ChannelFull,GetChannelFull。我将GetChannelFull添加到Function类中。在该问题中,我按isChannel过滤了聊天记录,并尝试通过supergroupId获取Channel。
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'失败。
如果您知道那是什么问题,请帮助我。
解决方法
我找到了解决方法。在示例中,有SupergroupFullInfo类和Chat类的ChatType。我将使用来自ChatType的suprgroupId和GetSupergroupFullInfo来获取所需的信息。