Strands Telegram
Comprehensive Telegram Bot API integration for Strands Agents
A complete Telegram Bot API tool that provides seamless integration with Strands Agents, supporting all major Telegram Bot API operations with full flexibility and rich features.
🚀 Features
📨 Message Operations
- Text Messages: Send rich text with HTML/Markdown formatting
- Media Support: Photos, videos, audio, documents, voice messages
- Interactive Elements: Polls, dice games, location sharing, contact cards
- Message Management: Edit, delete, forward, copy, pin/unpin messages
🎮 Interactive Features
- Inline Keyboards: Create interactive button menus
- Custom Keyboards: Reply keyboards with custom layouts
- Callback Queries: Handle button press events
- Rich Media: Stickers, animations, and multimedia content
👥 Group & Channel Management
- User Management: Kick, ban, unban, promote users
- Permissions: Set chat permissions and restrictions
- Administration: Manage chat settings, photos, descriptions
- Member Info: Get chat members, administrators, and statistics
🔧 Bot Management
- Webhook Support: Set up and manage webhooks
- Bot Information: Get bot details and configuration
- Updates Handling: Retrieve and process bot updates
- File Operations: Upload, download, and manage files
📦 Installation
pip install strands-telegram
🤖 Bot Setup
Before using this tool, you need to create a Telegram bot and get an API token:
1. Create a Telegram Bot
- Open Telegram and search for
@BotFather - Start a chat with BotFather by clicking
/start - Create new bot with
/newbotcommand - Choose a name for your bot (e.g., "My Awesome Bot")
- Choose a username for your bot (must end with "bot", e.g., "myawesomebot")
- Save the token - BotFather will give you a token like
123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11
2. Configure Bot Settings (Optional)
You can customize your bot using BotFather commands:
/setdescription- Set bot description/setcommands- Set bot commands menu/setprivacy- Enable/disable privacy mode for groups/setjoingroups- Allow bot to be added to groups
3. Get Your Bot Token
The token from BotFather is your TELEGRAM_BOT_TOKEN. Keep it secure!
4. Set Environment Variable
export TELEGRAM_BOT_TOKEN="your_bot_token_here"
📚 Official Documentation
- Telegram Bots Guide: https://core.telegram.org/bots
- Telegram Bot API: https://core.telegram.org/bots/api
- Full Telegram API: https://core.telegram.org/api
🛠️ Usage
Quick Start
from strands import Agent
from strands_telegram import telegram
# Create agent with Telegram tool
agent = Agent(tools=[telegram])
# Send a message
agent.tool.telegram(
action="send_message",
chat_id="@username",
text="Hello from Strands! 🚀"
)
Environment Setup
# Set your Telegram Bot Token (get from @BotFather)
export TELEGRAM_BOT_TOKEN="your_bot_token_here"
Advanced Examples
Interactive Keyboard
# Send message with inline keyboard
agent.tool.telegram(
action="send_message",
chat_id="123456789",
text="Choose an option:",
inline_keyboard=[
[{"text": "Option 1", "callback_data": "opt1"}],
[{"text": "Option 2", "callback_data": "opt2"}]
]
)
Send Photo with Caption
# Send photo from local file
agent.tool.telegram(
action="send_photo",
chat_id="123456789",
file_path="/path/to/photo.jpg",
text="Check out this amazing photo! 📸"
)
# Send photo from URL
agent.tool.telegram(
action="send_photo",
chat_id="123456789",
file_url="https://example.com/photo.jpg",
text="Photo from the web 🌐"
)
Create Poll
# Create a poll
agent.tool.telegram(
action="send_poll",
chat_id="123456789",
question="What's your favorite Strands feature?",
options=["AI Tools", "Multi-agent", "Workflows", "All of them!"]
)
Group Management
# Promote user to admin
agent.tool.telegram(
action="promote_chat_member",
chat_id="-100123456789",
user_id=987654321
)
# Set chat permissions
agent.tool.telegram(
action="set_chat_permissions",
chat_id="-100123456789",
permissions={
"can_send_messages": True,
"can_send_media_messages": False
}
)
📋 Supported Actions
Message Operations
send_message- Send text messagessend_photo- Send photossend_video- Send videossend_audio- Send audio filessend_document- Send documentssend_voice- Send voice messagessend_sticker- Send stickerssend_location- Send location coordinatessend_contact- Send contact informationsend_poll- Create pollssend_dice- Send dice animations
Message Management
edit_message- Edit message textdelete_message- Delete messagesforward_message- Forward messagescopy_message- Copy messagespin_message- Pin messagesunpin_message- Unpin messages
Bot Information
get_me- Get bot informationget_updates- Get bot updatesget_chat- Get chat informationget_chat_member- Get chat member infoget_chat_administrators- Get chat administrators
Webhook Management
set_webhook- Set webhook URLdelete_webhook- Delete webhookget_webhook_info- Get webhook information
Group/Channel Management
kick_chat_member- Remove membersunban_chat_member- Unban membersrestrict_chat_member- Restrict memberspromote_chat_member- Promote to adminset_chat_permissions- Set permissionsset_chat_title- Change chat titleset_chat_description- Set descriptionleave_chat- Leave chat
File Operations
get_file- Get file informationdownload_file- Download files
🔒 Security & Best Practices
Token Security
- Never hardcode tokens in your code
- Use environment variables for bot tokens
- Rotate tokens regularly for production use
Error Handling
The tool provides comprehensive error handling:
result = agent.tool.telegram(action="send_message", chat_id="invalid", text="test")
if result["status"] == "error":
print(f"Error: {result['content'][0]['text']}")
Rate Limiting
- Telegram has rate limits (30 messages/second to different chats)
- The tool handles basic rate limiting
- For high-volume bots, implement additional rate limiting
🌟 Integration with Strands Agents
This tool is designed to work seamlessly with Strands Agents:
from strands import Agent
from strands_telegram import telegram
# Agent with Telegram capabilities
agent = Agent(
system_prompt="You are a helpful Telegram bot assistant.",
tools=[telegram]
)
# Agent can now use Telegram in conversations
response = agent("Send a welcome message to the user")
📚 API Reference
telegram(action, **kwargs)
Parameters:
action(str): The Telegram API action to performchat_id(str|int): Target chat ID or usernametext(str): Message text contentparse_mode(str): Text parsing mode (HTML, Markdown, MarkdownV2)file_path(str): Local file path for uploadsfile_url(str): URL for remote filesinline_keyboard(List[List[Dict]]): Inline keyboard markup- Additional parameters specific to each action
Returns:
Dictwith status and response content
🤝 Contributing
Contributions are welcome! Please feel free to submit issues, feature requests, or pull requests.
Development Setup
git clone https://github.com/eraykeskinmac/strands-telegram
cd strands-telegram
pip install -e ".[dev]"
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
🔗 Links
📞 Support
- Create an issue on GitHub for bug reports
- Join our community discussions for questions
- Check the Strands Agents SDK documentation for integration help
Made with ❤️ for the Strands Agents community
Metadata
Release files for strands-telegram 1.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| strands_telegram-1.0.2.tar.gz | 16.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| strands_telegram-1.0.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 28.9 kB
Release files / strands_telegram-1.0.2.tar.gz
| Download URL | strands_telegram-1.0.2.tar.gz |
|---|---|
| Size | 16.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
02bce7446daed39520bc847d2e31ba8ce795ab4ad170f72192744fa4dff10392
|
|
BLAKE2b-256 checksum How to use checksums |
2cc6ab943288a12403a1e40ab47ba3309011935e605ac5db71ddad6509c393fa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 21, 2025.
Transparency logRelease files / strands_telegram-1.0.2-py3-none-any.whl
| Download URL | strands_telegram-1.0.2-py3-none-any.whl |
|---|---|
| Size | 12.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
dc507abb43dec4f7dc6cf3ab591323c5f5869b94ca0a23b595c717b23e1bcc14
|
|
BLAKE2b-256 checksum How to use checksums |
53b825c4ba4103db0a55a4f2f22f7dd1105034100b762f3c2f4e0dbb2138fade
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 21, 2025.
Transparency log