Telegram API 的完全原生 Go 实现
在 Golang 上完全原生实现 MTProto 协议! 英语 俄语 简体中文
特点
MTProto 在实现上确实很难,但使用起来却非常简单。基本上,这个库会将序列化的结构发送到 Telegram 服务器(就像 gRPC 一样,但来自 Telegram LLC)。它的格式如下:
func main() {
client := telegram.NewClient()
// for each method there is specific struct for serialization (Params{})
result, err := client.MakeRequest(&telegram.GetSomeInfoParams{FromChatId: 12345})
if err != nil {
panic(err)
}
resp, ok := result.(*SomeResponseObject)
if !ok {
panic("Oh no! Wrong type!")
}
}不是那么难,对吧? 但还有更简单的方法来发送请求,它包含在 TL API 规范中:
func main() {
client := telegram.NewClient()
resp, err := client.GetSomeInfo(12345)
if err != nil {
panic(err)
}
// resp will be already asserted as described in TL specs of API
// if _, ok := resp.(*SomeResponseObject); !ok {
// panic("No way, we found a bug! Create new issue!")
// }
println(resp.InfoAboutSomething)
}您无需考虑加密、密钥交换、保存和恢复会话等日常事务。这些功能已经为您实现了。 代码示例可在 这里
完整文档请参阅 这里
暂无开放 Issues,或尚未同步最近议题。