文件与 Mini App
InputFile 支持四种来源:
| 构造器 | 行为 |
|---|---|
InputFile::file_id |
复用 Telegram 已有文件 |
InputFile::url |
由 Telegram 下载远程文件 |
InputFile::bytes |
上传内存字节 |
InputFile::path |
直到显式请求时才进行有界读取 |
完整协议会自动收集任意嵌套层级的上传文件,为相册、媒体缩略图、封面、富消息、贴纸、故事和 Webhook 证书生成独立 multipart 引用。
use jingzhe::{InputFile, SendDocument};
async fn send_document(bot: &Bot, chat_id: i64) -> jingzhe::Result<()> { bot.request(SendDocument::new(chat_id, InputFile::path("report.pdf"))).await?; Ok(())}默认每个文件上传和下载上限为 20 MiB,可调整:
let bot = bot.file_limits(50_000_000, 20_000_000)?;官方接口限制仍然适用。本地还会限制图片不超过 10 MB、缩略图不超过 200 kB。上传文件会有界读入内存。
download 返回完整字节,download_to(&file, &mut writer).await? 将下载分块写入异步目标,避免缓存整个文件:
bot.download_to(&file, &mut writer).await?;失败可能留下部分输出。调用方负责目标的 flush、原子替换和清理。
仓库中的 examples/files.rs 演示了 InputFile::path、GetFile、download 和复用 file_id。
Mini App
Section titled “Mini App”Mini App 入口包括:
InlineButton::web_appKeyboardButton::web_appMenuButton::WebApp- 菜单设置
WebAppDataAnswerWebAppQuery- 预制消息和按钮保存方法
查询结果由 InlineQueryResult 和 InputMessageContent 统一建模。用户输入和 Mini App 数据仍需由业务验证。