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 在 异步
154 每月下载量
1MB
19K SLoC
目标
- 全面支持最新的 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