Complete Telegram Setup Guide: Connect Hermes Agent to Telegram Bot
Overview
Telegram is a globally popular instant messaging app known for its security and open Bot API. Hermes Agent supports conversational interactions with users through Telegram Bots. This tutorial will guide you through the complete process from creating a Bot to configuring the Hermes Gateway.
Estimated setup time: 5-10 minutes
Required information:
- Bot Token (obtained from BotFather)
- Your Telegram User ID (for access authorization)
Step 1: Create a Telegram Bot
1.1 Find BotFather
BotFather is Telegram's official Bot management tool. All Bot creation is done through it.
- Open the Telegram app
- Search for
@BotFatherin the search box - Click to enter the conversation with BotFather
Tip: Make sure to select the official BotFather with the blue verification badge.
1.2 Create a New Bot
-
In the BotFather conversation, send:
/newbot -
BotFather will ask for your Bot's display name:
- This is the display name, can include any characters
- Example:
Hermes AI Assistant
-
Next, enter the Bot's username:
- Must end with
bot - Can only use letters, numbers, and underscores
- Example:
my_hermes_ai_bot
- Must end with
1.3 Get Bot Token
After successful creation, BotFather will return a message containing your Bot Token:
Done! Congratulations on your new bot. You will find it at t.me/my_hermes_ai_bot.
Use this token to access the HTTP API:
123456789:ABCdefGHIjklMNOpqrsTUVwxyz
Save this Token securely - it's the only credential for accessing the Bot API.
⚠️ Security Reminder:
- Don't share the Token with others
- Don't commit the Token to public code repositories
- If the Token is leaked, immediately regenerate it using the
/revokecommand via BotFather
Step 2: Get Your Telegram User ID
The Telegram User ID is used to authorize which users can chat with the Bot.
Method 1: Using @userinfobot (Recommended)
- Search for
@userinfobotin Telegram - Click "Start" or send any message
- The bot will reply with your user info, including the
Idfield
Example:
@your_username
Id: 123456789
Here, 123456789 is your User ID.
Method 2: Using @getmyid_bot
- Search for
@getmyid_botin Telegram - Click "Start"
- The bot will directly return your User ID
Method 3: Check Gateway Logs
- Complete the configuration below and start the Gateway (temporarily allow all users)
- Send a test message to your Bot
- Check the Gateway logs for the sender's User ID
Step 3: Configure Hermes Gateway
Option 1: Via Hermes Service Manager (Recommended)
If you're using our managed service:
- Go to the Hermes Service Manager page
- Log in to your server management interface
- Use the "Telegram Setup" quick configuration tab:
- Enter Bot Token
- Click "Complete Setup"
- The system will automatically write the configuration and restart the Gateway
Or manually configure in the "Config" tab:
gateway.telegram.bot_token: Your Bot Tokengateway.telegram.allowed_users: Authorized user IDs (comma-separated)
Option 2: Via Interactive Wizard
Run in your server terminal:
hermes gateway setup
Follow the prompts:
- Select "Telegram"
- Enter Bot Token
- Enter allowed user IDs (comma-separated)
Option 3: Manual Configuration
Edit the ~/.hermes/.env file and add:
TELEGRAM_BOT_TOKEN=123456789:ABCdefGHIjklMNOpqrsTUVwxyz
TELEGRAM_ALLOWED_USERS=123456789,987654321
Environment Variables:
TELEGRAM_BOT_TOKEN: Required, Token obtained from BotFatherTELEGRAM_ALLOWED_USERS: Optional, list of allowed user IDs, comma-separated- If
TELEGRAM_ALLOWED_USERSis not set, you need to setGATEWAY_ALLOW_ALL_USERS=true(not recommended for production)
Step 4: Start and Test
4.1 Start the Gateway
Run in foreground (for testing):
hermes gateway run
Or start as a system service:
hermes gateway install
hermes gateway start
4.2 Test the Bot
- Find your Bot in Telegram (via the link returned by BotFather)
- Click "Start" or send
/start - Send a test message like "Hello"
- If configured correctly, the Bot will reply with an AI-generated response
Optional Configuration
Set Bot Description and Avatar
You can further customize your Bot through BotFather:
- Send
/mybotsto view all your Bots - Select the Bot to edit
- Available options:
- Edit Bot → Edit Description: Set Bot description
- Edit Bot → Edit About Text: Set about text
- Edit Bot → Edit Botpic: Set Bot avatar
Set Command Menu
- Select your Bot in BotFather
- Choose Edit Bot → Edit Commands
- Add commands in the format:
start - Start conversation help - Get help clear - Clear conversation history
Troubleshooting
Q: Bot doesn't respond to messages
Possible causes:
- Gateway not running
- Incorrect Bot Token
- User ID not in allowed list
Solutions:
- Check Gateway status:
hermes gateway status - Verify Token is correct
- Check
TELEGRAM_ALLOWED_USERSconfiguration
Q: Received "Unauthorized" error
Cause: Bot Token is invalid or has been revoked
Solutions:
- Check if Token is valid via BotFather
- If needed, regenerate Token using
/revoke - Update the Token in configuration file
Q: High message latency
Possible causes:
- Unstable server network
- Slow LLM API response
Solutions:
- Check network connection from server to Telegram servers
- Consider using a faster LLM model
- Check response times in Gateway logs
Q: How to allow group use of Bot
By default, the Bot only responds to private messages. To use in groups:
- Set via BotFather:
/setprivacy→ Select Bot → Disable - Add group ID (negative number) to the allowed list in configuration
Related Resources
- Telegram Bot API Documentation
- BotFather Guide
- Hermes Service Manager
- Complete Messaging Platform Setup Guide
For questions, please contact us for technical support.
