百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
M

mtproto

> DevOps
开源

Telegram API 的完全原生 Go 实现

1.3K stars0 点赞1 次浏览
访问官网GitHub

工具介绍

Telegram API 的完全原生 Go 实现

MTProto

在 Golang 上完全原生实现 MTProto 协议! 英语 俄语 简体中文

特点

如何使用

MTProto 在实现上确实很难,但使用起来却非常简单。基本上,这个库会将序列化的结构发送到 Telegram 服务器(就像 gRPC 一样,但来自 Telegram LLC)。它的格式如下:

go
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 规范中:

go
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· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Goapi-clientawesomeawesome-golanggo

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类DevOps
定价开源

> 相关工具

D
Docker
容器化平台,标准化应用交付
G
GitHub Actions
GitHub 原生 CI/CD 工作流
N
Nginx
高性能 Web 服务器与反向代理