miyabi-telegram
Telegram Bot API client for Miyabi - enabling natural language interaction and real-time notifications.
Features
- ✅ Full Telegram Bot API support
- ✅ Type-safe with Serde serialization
- ✅ Async/await with Tokio
- ✅ Inline keyboard support
- ✅ Webhook management
- ✅ Comprehensive error handling
Quick Start
1. Create a Telegram Bot
- Open Telegram and search for @BotFather
- Send
/newbotand follow the instructions - Choose a name and username for your bot
- BotFather will give you a bot token - save it!
Example:
Use this token to access the HTTP API:
1234567890:ABCdefGHIjklMNOpqrsTUVwxyz
2. Get Your Chat ID
You need your chat ID to send messages to yourself:
- Send any message to your bot in Telegram
- Visit:
https://api.telegram.org/bot<YOUR_BOT_TOKEN>/getUpdates - Look for
"chat":{"id":123456789}- that's your chat ID
Or use this helper:
|
3. Set Environment Variable
4. Run Examples
# Send a simple message
# Send an interactive menu with buttons
Usage
Basic Message
use TelegramClient;
async
Message with Inline Keyboard
use ;
async
Handling Callbacks (Webhook)
When users click inline keyboard buttons, Telegram sends a callback query to your webhook:
use ;
async
API Methods
| Method | Description |
|---|---|
send_message(chat_id, text) |
Send a text message |
send_message_with_keyboard(chat_id, text, keyboard) |
Send message with inline keyboard |
answer_callback_query(id, text) |
Respond to button click |
get_me() |
Get bot information |
set_webhook(url) |
Set webhook URL |
delete_webhook() |
Delete webhook |
Types
Core Types
Update- Incoming updates from TelegramMessage- Message objectUser- User informationChat- Chat informationCallbackQuery- Button click event
Keyboard Types
InlineKeyboard- Inline keyboard markupInlineKeyboardButton- Individual button
Advanced: Multi-row Keyboard
let keyboard = new;
Markdown Formatting
Messages support Markdown formatting:
let text = r#"
*Bold text*
_Italic text_
[Link](https://example.com)
`Code`
```rust
fn hello() {
println!("Hello!");
}
"#;
client.send_message(chat_id, text).await?;
## Error Handling
```rust
use miyabi_telegram::{TelegramClient, TelegramError};
match client.send_message(chat_id, "Hello").await {
Ok(message) => {
println!("Message sent! ID: {}", message.message_id);
}
Err(TelegramError::ApiError(msg)) => {
eprintln!("Telegram API error: {}", msg);
}
Err(e) => {
eprintln!("Other error: {}", e);
}
}
Testing
# Run all tests
# Run specific test
Dependencies
[]
= { = "../miyabi-telegram" }
= { = "1", = ["full"] }
Environment Variables
| Variable | Description | Required |
|---|---|---|
TELEGRAM_BOT_TOKEN |
Your bot token from BotFather | Yes |
Resources
- Telegram Bot API Documentation
- BotFather - Create and manage bots
- Telegram Inline Keyboards
License
Same as Miyabi project.
Miyabi Bot Server
This crate also includes a complete bot server binary for Miyabi integration:
Quick Start (Bot Server)
# 1. Configure environment
# Edit with your tokens
# 2. Build bot server
# 3. Setup ngrok (local development)
# 4. Update WEBHOOK_URL in .env.telegram with ngrok URL
# 5. Run bot
&& &&
Bot Features
- 🤖 Natural language input → GitHub Issue creation
- 📡 Real-time progress notifications
- ⚡ Agent execution integration (pending)
- 🔐 Secure webhook handling
See TELEGRAM_BOT_SETUP.md for complete documentation.
Related
- Issue #563: Telegram Bot Integration
- Replaced LINE Bot (#431, #538, #539, #540)