Installation
Requirements
Section titled “Requirements”- A Rust toolchain that supports the Rust 2024 edition.
- A bot token from @BotFather.
- Bun when working on the documentation website.
Telegram Bot API documentation: https://core.telegram.org/bots/api.
Add the dependency
Section titled “Add the dependency”[dependencies]jingzhe = "0.1.0"tokio = { version = "1", features = ["macros", "rt-multi-thread"] }anyhow = "1"The default configuration enables reqwest and rustls-tls, which works for most async applications.
Feature flags
Section titled “Feature flags”HTTP backends and TLS are independent feature flags:
| Feature | Purpose | Default |
|---|---|---|
reqwest |
Async reqwest backend | Yes |
ureq |
ureq backend with network work on Tokio blocking tasks | No |
rustls-tls |
Enable Rustls for the selected backend | Yes |
native-tls |
Enable Native TLS for the selected backend | No |
webhook |
Enable the Axum webhook server and router integration | No |
To use ureq with Native TLS:
jingzhe = { version = "0.1.0", default-features = false, features = ["ureq", "native-tls"] }Bot::new and ApiClient::new automatically select the only enabled HTTP backend. Construction returns an actionable error when no backend is enabled or both backends are enabled.
Select a backend explicitly when both backends are compiled:
use jingzhe::{Bot, HttpBackend};
let bot = Bot::with_backend(token, HttpBackend::Reqwest)?;TLS features do not implicitly enable an HTTP backend. Rustls wins when both TLS implementations are enabled. Without TLS, local HTTP endpoints remain available, but HTTPS requests return a configuration error.
Continue with the quick start, or read the complete HTTP backends and TLS reference.