[英]How can I check whether a user is a member of a Telegram group?
我想使用Telegram API确认给定的用户是命名组的成员。 给定用户的电话号码和发送的代码,我可以成功地对其进行身份验证,但是除此之外,我还很迷路。 我以为我可以使用@groupname
从client.contactsSearch
开始,但这会返回一个空向量。
我正在使用Scala的Kotlogram库,但这只是MT协议的一个薄包装。
对于Bot API,可以使用getChatMember方法。
这就是我最后想出的。 不过,我不知道这是否是最佳方法。
val PhoneNumber = "+1..."
val app = new TelegramApp(..., "...", "...", "0.0.1", "0.0.1", "en")
class ApiStorage extends TelegramApiStorage {
...
}
val client = Kotlogram.getDefaultClient(app, new ApiStorage)
val sentCode = client.authSendCode(false, PhoneNumber, true)
val code = scala.io.StdIn.readLine()
val authorization = client.authSignIn(PhoneNumber, sentCode.getPhoneCodeHash, code)
val self = authorization.getUser.getAsUser
val name = s"${self.getFirstName} ${self.getLastName}"
val userInput = new TLInputUser(self.getId, self.getAccessHash)
client.contactsSearch("@groupname", 100).getChats.toArray.map(_.asInstanceOf[TLChannel]).find(_.getUsername == "groupname") match {
case Some(channel) =>
val channelInput = new TLInputChannel(channel.getId, channel.getAccessHash)
val isMember = Try { client.channelsGetParticipant(channelInput, userInput) } map { _ => true } getOrElse false
if (isMember) {
println("Is a member")
} else {
println("Is not a member")
}
case None =>
println("Can't find channel @groupname")
}
client.close()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.