Skip to Content
🎉 Trogent Platform is live! Create your first AI agent
DocumentationPlatform IntegrationTelegram Integration

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.

  1. Open Telegram and search for @BotFather
  2. Start a conversation with BotFather by clicking “Start”
  3. Create a new bot by sending the command: /newbot
  4. Choose a name for your bot (this will be displayed in contact details and elsewhere)
  5. Choose a username for your bot (must end in ‘bot’, e.g., mytrogentbot)
  6. 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

  1. Access your agent in the Trogent dashboard
  2. Navigate to Platform Configuration or click “Edit” on your agent
  3. Find the Telegram section
  4. Enter your bot token that you received from BotFather
  5. 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
  6. Save your configuration

Step 4: Test Your Bot

  1. Open Telegram and search for your bot by its username
  2. Start a conversation by clicking “Start” or sending /start
  3. Send a test message to verify your agent responds correctly
  4. 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

  1. Navigate to your agent in the Trogent dashboard
  2. Go to “Telegram Commands” section
  3. Click “Add New Command”
  4. 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

  1. Create or open a Telegram group
  2. Add your bot by searching for its username
  3. Grant necessary permissions (if you’re an admin)
  4. 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

  1. Consistent Voice: Maintain the same personality across all interactions
  2. Clear Communication: Use simple, clear language
  3. Helpful Responses: Always try to be useful and informative
  4. Error Handling: Provide helpful messages when you can’t assist

User Experience

  1. Quick Responses: Keep response times under 5 seconds when possible
  2. Command Discovery: Make it easy for users to discover available commands
  3. Context Awareness: Remember conversation context for better responses
  4. Graceful Failures: Handle errors gracefully with helpful messages

Security and Privacy

  1. Data Protection: Don’t store sensitive user information
  2. Privacy Respect: Be transparent about data usage
  3. Access Control: Implement appropriate permissions for group bots
  4. 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