Telegram Integration Guide
Complete guide to integrating your Trogent agents with Telegram, including bot setup, configuration, and advanced features.
Overview
Telegram integration allows your AI agents to operate as Telegram bots, engaging with users in private chats, groups, and channels. With Trogentâs Telegram integration, you can create sophisticated bots that provide automated customer support, community management, or specialized services.
Key Features
- Private Chat Support: One-on-one conversations with users
- Group Chat Integration: Participate in group discussions
- Custom Commands: Create and manage custom bot commands
- Real-time Messaging: Instant message delivery and responses
- Message Buffering: Configurable response delays for natural conversation flow
- Auto-restart: Automatic bot recovery from connection issues
Prerequisites
Before setting up your Telegram bot, ensure you have:
- A Telegram account
- Access to the Trogent platform with an authenticated Solana wallet
- An active Trogent agent created and configured
Setting Up Your Telegram Bot
Step 1: Create a Bot with BotFather
BotFather is Telegramâs official bot for creating and managing bots.
- Open Telegram and search for
@BotFather
- Start a conversation with BotFather by clicking âStartâ
- Create a new bot by sending the command:
/newbot
- Choose a name for your bot (this will be displayed in contact details and elsewhere)
- Choose a username for your bot (must end in âbotâ, e.g.,
mytrogentbot
) - Save the token: BotFather will provide you with a token - copy and save this securely
Important: The bot token is sensitive information. Never share it publicly or commit it to version control systems.
Example BotFather Conversation
You: /newbot
BotFather: Alright, a new bot. How are we going to call it? Please choose a name for your bot.
You: My Trogent Assistant
BotFather: Good. Now let's choose a username for your bot. It must end in `bot`. Like this, for example: TetrisBot or tetris_bot.
You: MyTrogentAssistantBot
BotFather: Done! Congratulations on your new bot. You will find it at t.me/MyTrogentAssistantBot. You can now add a description, about section and profile picture for your bot, see /help for a list of commands.
Use this token to access the HTTP API:
1234567890:ABCdefGHIjklMNOpqrsTUVwxyz
Step 2: Configure Bot Settings (Optional)
You can enhance your botâs appearance and functionality:
Set Bot Description
/setdescription @YourBotUsername
Enter a description of what your bot does.
Set Bot About Text
/setabouttext @YourBotUsername
Add information about your bot that users see in the botâs profile.
Set Bot Profile Picture
/setuserpic @YourBotUsername
Upload a profile picture for your bot.
Step 3: Configure Bot in Trogent
- Access your agent in the Trogent dashboard
- Navigate to Platform Configuration or click âEditâ on your agent
- Find the Telegram section
- Enter your bot token that you received from BotFather
- Configure additional settings:
- Custom Username: Optional custom username for your bot
- Message Buffering: Delay between responses (1-10 seconds, default: 3)
- Enable/Disable: Toggle bot active status
- Save your configuration
Step 4: Test Your Bot
- Open Telegram and search for your bot by its username
- Start a conversation by clicking âStartâ or sending
/start
- Send a test message to verify your agent responds correctly
- Check the Trogent dashboard for real-time status updates
Bot Configuration Options
Message Buffering
Message buffering adds a delay between receiving a message and sending a response, making conversations feel more natural and human-like.
- Minimum: 1 second
- Maximum: 10 seconds
- Default: 3 seconds
- Use Case: Prevents rapid-fire responses that seem robotic
Custom Username
While not required, you can set a custom username that appears in bot interactions. This is different from the botâs Telegram username and is used for display purposes within conversations.
Bot Status Management
- Active: Bot responds to messages and is fully operational
- Inactive: Bot is online but doesnât process new messages
- Offline: Bot is completely disconnected
Custom Commands
Trogent allows you to create custom Telegram commands that trigger specific responses or actions.
Creating Custom Commands
- Navigate to your agent in the Trogent dashboard
- Go to âTelegram Commandsâ section
- Click âAdd New Commandâ
- Configure the command:
- Command: The command name (without /, e.g., âhelpâ)
- Description: What the command does
- Response: The message sent when the command is used
- Enabled: Toggle command availability
Command Examples
Help Command
Command: help
Description: Show available commands and bot information
Response: Hello! I'm your AI assistant. Here are the commands I understand:
- /start - Begin our conversation
- /help - Show this help message
- /info - Learn more about my capabilities
- /contact - Get support information
Info Command
Command: info
Description: Provide information about the bot's capabilities
Response: I'm an AI-powered assistant that can help you with:
- Answering questions about our products
- Providing customer support
- General information and assistance
Feel free to ask me anything!
Command Management
- Edit Commands: Modify existing commands and responses
- Enable/Disable: Turn commands on or off without deleting them
- Delete Commands: Permanently remove commands
- Default Commands: Some commands like
/start
are automatically handled
Advanced Features
Group Chat Integration
When your bot is added to Telegram groups, it can participate in group discussions:
Adding Bot to Groups
- Create or open a Telegram group
- Add your bot by searching for its username
- Grant necessary permissions (if youâre an admin)
- Configure group behavior in Trogent settings
Group Chat Behavior
- Mention Responses: Bot responds when mentioned (@botusername)
- Keyword Triggers: Respond to specific keywords or phrases
- Admin Commands: Special commands available to group admins
Message Types Support
Your Trogent bot can handle various message types:
- Text Messages: Standard text conversations
- Commands: Custom and system commands
- Replies: Responses to specific messages
- Forwarded Messages: Handle forwarded content appropriately
Error Handling
Trogent provides robust error handling for Telegram bots:
- Connection Recovery: Automatic reconnection on network issues
- Rate Limit Management: Respect Telegramâs rate limits (10 messages/minute per user)
- Error Notifications: Real-time error alerts in the dashboard
- Graceful Degradation: Maintain service during partial failures
Monitoring and Analytics
Real-time Monitoring
Track your Telegram botâs performance:
- Connection Status: Online/offline status
- Message Volume: Messages processed over time
- Response Times: How quickly your bot responds
- Error Rates: Failed message attempts
Usage Analytics
- User Interactions: Number of unique users
- Popular Commands: Most-used custom commands
- Conversation Patterns: Common user interaction flows
- Peak Usage Times: When your bot is most active
Best Practices
Bot Personality
- Consistent Voice: Maintain the same personality across all interactions
- Clear Communication: Use simple, clear language
- Helpful Responses: Always try to be useful and informative
- Error Handling: Provide helpful messages when you canât assist
User Experience
- Quick Responses: Keep response times under 5 seconds when possible
- Command Discovery: Make it easy for users to discover available commands
- Context Awareness: Remember conversation context for better responses
- Graceful Failures: Handle errors gracefully with helpful messages
Security and Privacy
- Data Protection: Donât store sensitive user information
- Privacy Respect: Be transparent about data usage
- Access Control: Implement appropriate permissions for group bots
- Regular Updates: Keep bot tokens secure and rotate when necessary
Troubleshooting
Common Issues
Bot Not Responding
- Check Bot Token: Verify the token is correct and active
- Check Bot Status: Ensure bot is set to âActiveâ in Trogent
- Platform Connectivity: Check Telegram service status
- Agent Configuration: Verify agent is properly configured
Connection Issues
- Network Problems: Check internet connectivity
- Telegram API Issues: Monitor Telegram Bot API status
- Rate Limiting: Bot is sending messages too quickly (max 10/minute per user)
- Token Issues: Verify bot token hasnât been revoked
Performance Problems
- Slow Responses: Check system load and agent configuration
- High Error Rates: Review error logs for specific issues
- Memory Issues: Monitor system resource usage
- Database Problems: Check knowledge base processing status
Error Messages
âInvalid Tokenâ
- The bot token is incorrect or has been revoked
- Generate a new token from BotFather
- Update the token in Trogent configuration
âBot Blockedâ
- The bot has been blocked by Telegram
- Contact Telegram support for resolution
- Review bot behavior for policy violations
âRate Limitedâ
- Bot is sending messages too quickly
- Increase message buffering delay
- Implement proper rate limiting in responses
Limitations and Considerations
Telegram Bot API Limitations
- Message Length: Maximum 4096 characters per message
- File Size: 50MB maximum file uploads
- Rate Limits: 30 messages per second to different chats
- Bot Restrictions: Cannot initiate conversations with users
Trogent Specific Limitations
- Response Time: Dependent on AI model processing time
- Knowledge Base: Limited by storage allocation per agent (400KB default)
- Custom Commands: Unlimited custom commands per bot
- Concurrent Users: Shared resources may affect response times during peak usage