11 个版本

新版本 0.2.12 2024 年 8 月 15 日
0.2.11 2024 年 7 月 1 日
0.2.10 2024 年 6 月 22 日
0.2.8 2024 年 4 月 4 日
0.1.1 2023 年 6 月 9 日

#158异步

Download history 90/week @ 2024-06-09 134/week @ 2024-06-16 42/week @ 2024-06-23 214/week @ 2024-06-30 2/week @ 2024-07-07 12/week @ 2024-07-21 51/week @ 2024-07-28 91/week @ 2024-08-11

154 每月下载量

MIT 许可证

1MB
19K SLoC

Conogram:用 Rust 编写的异步 Telegram Bot API 客户端


目标

  • 全面支持最新的 Bot API 版本 暂不支持 webhooks
  • 1 对 1 API 方法与实体映射
  • 易于使用

特性

  • 完全异步
  • 为 API 实体提供实用扩展方法 (目前不是所有) (例如 message.reply 方法)
  • 可在多线程环境中使用
  • 完全控制更新处理

待办事项

  • 更多方便的实体扩展方法
  • Webhooks 支持

  • 更多示例

日志记录

如何在您的可执行文件中启用日志记录

快速使用概述

使用 本地 Bot API 服务器

    let server_config = ApiServerConfig::local("https://127.0.0.1", 80, true);

    let api_config = APIConfig::new("BOT_TOKEN", server_config)?

    let api = API::new(api_config);

调用 API 方法

    let mut api = API::new(/**/);

    // Required request parameters are in the request constructor, optionals are set via builder-like methods
    // ChatId can be username of a channel
    let request = api.send_message("@channelusername","Text").reply_to_message_id(42);

    // All requests implement IntoFuture
    let message = request.await?;

    // You can handle some common API errors automatically:

    // 1. By wrapping manually 
    let message = API::request(request).await?;

    // 2. Or by using a trait
    use conogram::api::WrapRequest;
    let message = request.wrap().await?;

通过引用修改和调用请求

    let mut request = api.send_message(chat_id, "Text");
    for i in 0..5 {
        request = request.chat_id(i);

        // &Request implements IntoFuture too
        let message = (&request).await?;
    }

非常简短的常见问题解答

Q: 它是否可用于生产环境?
A: 该库未经彻底测试,某些功能可能损坏、不寻常或无法使用。原因是我正在为个人使用开发它。但如果您也在使用它,欢迎提出改进建议

依赖关系

~6–18MB
~272K SLoC