telegram-rs
A fast, ergonomic, and asynchronous Rust framework for building Telegram Bots, Mini Apps, and TON Connect wallet integrations.
Crate • Documentation • Repository • Issues • Changelog
Table of Contents
- Overview
- Key Features
- Feature Flags
- Installation
- Quick Start
- Repository Structure
- Examples
- Development & Testing
- Community & Contributing
- Security
- License
Overview
telegram-rs provides an all-in-one, modern toolkit for building high-performance Telegram bots and web-embedded Telegram Mini Apps (TMAs). Built on top of Tokio and Reqwest, it offers high concurrency, type-safe API requests, fluent keyboard builders, cryptographic initData signature validation, and optional TON Connect v2 blockchain wallet integrations.
Key Features
- Asynchronous & Type-Safe: Fully async non-blocking runtime powered by Tokio and Reqwest.
- Telegram Bot API: Send messages, handle updates via long-polling or webhooks, answer callback queries, and construct interactive keyboards.
- Fluent UI Builders: Easily create
InlineKeyboardMarkupandReplyKeyboardMarkupusing declarative builder patterns (InlineKeyboardBuilder,ReplyKeyboardBuilder). - Telegram Mini Apps (
mini-app): Parse launch data, perform HMAC-SHA256 signature verification against your bot token, check authentication freshness timestamps, and bridge with client environments. - TON Connect 2.0 (
wallet): Native structs and session lifecycle manager for connecting TON blockchain wallets. - Webhook Engine (
webhook): Built-in production-grade Actix-Web server integration for high-throughput webhook delivery. - Procedural Macros (
telegram-macros): Convenient attribute macros (#[bot],#[command]) for cleaner bot definitions.
Feature Flags
telegram-rs is designed with modularity in mind. All optional capabilities are gated behind Cargo features so you only compile what you need:
| Feature | Description | Default | Dependencies |
|---|---|---|---|
bot |
Core Telegram Bot API client and polling runtime | Yes | tokio, reqwest, serde |
mini-app |
Telegram Mini App initData parsing & cryptographic validation |
No | hmac, sha2, hex, urlencoding |
wallet |
TON Connect v2 wallet connectors and session management | No | uuid |
webhook |
Webhook HTTP server integration | No | actix-web |
Installation
Add telegram-rs-2 to your Cargo.toml:
[]
# Basic Bot API client
= "0.1.1"
# With Mini App initData validation support
= { = "0.1.1", = ["mini-app"] }
# With TON Connect v2 Wallet integration
= { = "0.1.1", = ["wallet"] }
# With all features enabled
= { = "0.1.1", = ["mini-app", "wallet", "webhook"] }
Quick Start
1. Echo & Button Bot (Polling)
use ;
use ;
use Polling;
use ;
async
2. Mini App InitData Validation
use InitData;
3. TON Connect 2.0 Wallet Integration
use ;
async
4. Webhook Server
use Update;
use Webhook;
use ;
async
Repository Structure
telegram-rs/
├── .github/ # GitHub standards and CI workflows
│ ├── ISSUE_TEMPLATE/ # Structured issue forms (Bug report, Feature request)
│ ├── workflows/ # GitHub Actions (CI & security audit)
│ └── pull_request_template.md # PR guidelines and checklist
├── benches/ # Benchmark suite
├── docs/ # Interactive documentation web app (React + Vite)
├── examples/ # Executable reference examples
│ ├── simple_bot.rs # Long-polling bot with inline buttons
│ ├── mini_app.rs # Mini App initData parsing
│ ├── wallet_bot.rs # TON Connect wallet initialization
│ └── webhook_bot.rs # Actix-Web webhook server
├── src/ # Core library implementation
│ ├── core/ # Core types, API methods, and builders
│ ├── mini_app/ # Telegram Mini App modules
│ ├── rt/ # Polling & webhook runtime engines
│ ├── wallet/ # TON Connect integration
│ ├── client.rs # Async HTTP transport
│ ├── errors.rs # Custom Error and Result types
│ └── lib.rs # Main crate re-exports
├── telegram-macros/ # Procedural attribute macros
├── tests/ # Integration test suites
│ ├── bot_tests.rs
│ ├── init_data_tests.rs
│ ├── mini_app_tests.rs
│ └── wallet_tests.rs
├── CHANGELOG.md # Semantic version changelog
├── CODE_OF_CONDUCT.md # Contributor Covenant v2.1
├── CONTRIBUTING.md # Contributing guide and local setup
├── LICENSE-APACHE # Apache 2.0 License
├── LICENSE-MIT # MIT License
└── SECURITY.md # Vulnerability disclosure policy
Examples
Runnable example applications are included in the examples/ directory:
# 1. Interactive Polling Bot with buttons
TELEGRAM_BOT_TOKEN="your_token"
# 2. Weather Bot (requires OPENWEATHER_API_KEY env var)
OPENWEATHER_API_KEY="your_api_key" TELEGRAM_BOT_TOKEN="your_token"
# 3. Mini App initData validation
# 4. TON Connect Wallet integration
# 5. Webhook Server
TELEGRAM_BOT_TOKEN="your_token"
Development & Testing
We welcome local contributions! Ensure your environment has the Rust stable toolchain installed.
# Check compilation across all targets and features
# Run the test suite
# Verify formatting
# Run Clippy with warnings denied
# Build documentation locally
Community & Contributing
Contributions are what make the open-source community an incredible place to learn, inspire, and create. Any contributions you make are greatly appreciated.
- Please read our Contributing Guide for branch naming, testing standards, and pull request procedures.
- We adhere to the Contributor Covenant Code of Conduct.
- Have a question or proposal? Start a discussion in GitHub Discussions or open an issue.
Security
If you discover a security vulnerability within telegram-rs, please review our Security Policy and report it privately via GitHub Security Advisories rather than public issue trackers.
License
telegram-rs is dual-licensed under either:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT License (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in telegram-rs by you shall be dual-licensed as above, without any additional terms or conditions.