Comprehensive Telegram Bot API integration for Strands Agents
Project description
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file strands_telegram-1.0.2.tar.gz.
File metadata
- Download URL: strands_telegram-1.0.2.tar.gz
- Upload date:
- Size: 16.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
02bce7446daed39520bc847d2e31ba8ce795ab4ad170f72192744fa4dff10392
|
|
| MD5 |
cc686dbfff26c913d6feefee5694051f
|
|
| BLAKE2b-256 |
2cc6ab943288a12403a1e40ab47ba3309011935e605ac5db71ddad6509c393fa
|
Provenance
The following attestation bundles were made for strands_telegram-1.0.2.tar.gz:
Publisher:
publish.yml on eraykeskinmac/strands-telegram
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
strands_telegram-1.0.2.tar.gz -
Subject digest:
02bce7446daed39520bc847d2e31ba8ce795ab4ad170f72192744fa4dff10392 - Sigstore transparency entry: 625877218
- Sigstore integration time:
-
Permalink:
eraykeskinmac/strands-telegram@16b9c837c4a69c279ce6a1ed2376fba377313320 -
Branch / Tag:
refs/tags/v1.0.2 - Owner: https://github.com/eraykeskinmac
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@16b9c837c4a69c279ce6a1ed2376fba377313320 -
Trigger Event:
release
-
Statement type:
File details
Details for the file strands_telegram-1.0.2-py3-none-any.whl.
File metadata
- Download URL: strands_telegram-1.0.2-py3-none-any.whl
- Upload date:
- Size: 12.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dc507abb43dec4f7dc6cf3ab591323c5f5869b94ca0a23b595c717b23e1bcc14
|
|
| MD5 |
f70e51086b92876347ba7a9e1008a712
|
|
| BLAKE2b-256 |
53b825c4ba4103db0a55a4f2f22f7dd1105034100b762f3c2f4e0dbb2138fade
|
Provenance
The following attestation bundles were made for strands_telegram-1.0.2-py3-none-any.whl:
Publisher:
publish.yml on eraykeskinmac/strands-telegram
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
strands_telegram-1.0.2-py3-none-any.whl -
Subject digest:
dc507abb43dec4f7dc6cf3ab591323c5f5869b94ca0a23b595c717b23e1bcc14 - Sigstore transparency entry: 625877249
- Sigstore integration time:
-
Permalink:
eraykeskinmac/strands-telegram@16b9c837c4a69c279ce6a1ed2376fba377313320 -
Branch / Tag:
refs/tags/v1.0.2 - Owner: https://github.com/eraykeskinmac
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@16b9c837c4a69c279ce6a1ed2376fba377313320 -
Trigger Event:
release
-
Statement type: