How to Set Up a Telegram Bot to Remotely Communicate with Your Hermes Agent
How to Set Up a Telegram Bot to Remotely Communicate with Your Hermes Agent
A practical, step-by-step guide to wiring your Hermes Agent up to Telegram so you can message it from your phone — and get answers back.
You've got a Hermes Agent running on your machine. You can chat with it in its own terminal or desktop app. But what if you want to ping it from your phone while you're away from your desk? Or have a scheduled task deliver its results straight into a Telegram chat?
This guide walks you through setting up a Telegram bot that talks to your Hermes Agent — from creating the bot with @BotFather to configuring Hermes and sending your first message from Telegram. No prior Telegram Bot API experience needed.
What You'll Need
A running Hermes Agent installation (with the gateway active)
A Telegram account (free — just the app on your phone)
About 10 minutes
Step 1: Create the Bot with @BotFather
Open Telegram and search for @BotFather — it's Telegram's official bot for creating and managing bots. Start a chat and send /newbot.
BotFather will ask for two things:
Display name — the human-readable name of your bot (e.g. "My Hermes Bot"). This is what users see in chats.
Username — a unique handle that must end in bot (e.g. my_hermes_bot or 574r570rm_hermes_bot). If the name is taken, pick another.
Once you submit both, BotFather replies with a message like:
Done! Congratulations on your new bot. You will find it at t.me/my_hermes_bot. You can now add a description, about section and profile pic for your bot, see our API docs for full details. Use this token to access the HTTP API:
123456789:ABCdefGHIjklMNOpqrsTUVwxyz
That token is your bot's API key. Treat it like a password.
Copy it somewhere safe for the next step. Telegram will never show it to you again in the same form — though you can revoke and regenerate it later (more on that in the security section).
Step 2: Configure Hermes
Hermes reads its Telegram configuration from ~/.hermes/.env. Open that file in your editor:
# Linux / macOS
nano ~/.hermes/.env
# Windows (PowerShell)
notepad $HOME\.hermes\.env
# Windows (Git Bash)
nano ~/.hermes/.env
Add (or edit) two keys:
TELEGRAM_BOT_TOKEN=123456789:ABCdefGHIjklMNOpqrsTUVwxyz
TELEGRAM_ALLOWED_USERS=123456789
TELEGRAM_BOT_TOKEN — the token BotFather gave you. This is what Hermes uses to authenticate with Telegram's API.
TELEGRAM_ALLOWED_USERS — a comma-separated list of Telegram user IDs that are allowed to message your agent. Find your own user ID by messaging @userinfobot on Telegram — it replies with your numeric ID. Only add your own ID for now; do not open it up to everyone unless you intend to.
⚠️ Important: .env is a plaintext file. Those secrets live on disk unencrypted. If you back up your Hermes profile directory, exclude .env or encrypt the backup. If you version-control your config, make sure .env is in .gitignore.
Step 3: Restart the Gateway
Hermes picks up Telegram config when the gateway starts (or restarts). If your gateway is already running, restart it:
# From the terminal
hermes gateway
If the gateway is already running in the background, you may need to stop and restart it:
hermes gateway --stop
hermes gateway
Or check its status first:
hermes gateway status
Once the gateway is up and has read the new .env, it will connect to Telegram's API using your bot token. There's no separate "enable Telegram" step — if the token and allowed-users are set, the gateway listens.
Step 4: Message Your Agent from Telegram
Open Telegram, find your bot (search by the username you chose, e.g. @my_hermes_bot), and start a chat. Send a simple message:
Hello, what can you do?
Your Hermes Agent should process the message and reply in the same chat. The bot acts as a bridge: your message goes to the gateway, the gateway passes it to the agent, the agent responds, and the response is delivered back to your Telegram chat.
You can now talk to your agent from your phone, a tablet, or any device with Telegram — without needing direct access to the machine it's running on.
Useful Extras
Slash Commands
Once the bot is connected, you can use slash commands directly in the Telegram chat. The exact set depends on your Hermes version, but common ones include:
Command |
What it does |
|---|---|
/new |
Start a new conversation / session with the agent |
/model |
Check or change which model the agent is using |
/status |
Get a quick status summary of the agent/gateway |
Slash commands are convenient for quick checks without needing to open the Hermes desktop app.
Voice Messages
If you send a voice message to the bot instead of text, Hermes will transcribe it and pass the transcription to the agent. This means you can dictate a question or instruction on the go and get a text-based reply — useful when typing on a phone is inconvenient.
Cron Jobs and Scheduled Tasks to Telegram
If you have cron jobs or scheduled tasks configured in Hermes, you can set their delivery target to your Telegram bot. That means the results of a scheduled run — a daily briefing, a price check, a system status report — get pushed into your Telegram chat automatically.
When configuring a cron job's delivery, set the destination to your bot (or a chat where the bot is present). Cron jobs run autonomously, so they don't need a user present to receive the output — it just shows up in your chat.
Security Best Practices
1. Keep the Token Secret
The bot token gives anyone who has it full control over your bot — they can read its messages, send messages as it, and generally impersonate it. Do not:
Paste it into public chats or forums
Commit it to a public git repository
Share it in a screenshot or screen recording
Email it around in plaintext
If you need to share config with someone, share the .env file over an encrypted channel, or better yet, keep the token to yourself and let others use the bot as a user (via TELEGRAM_ALLOWED_USERS).
2. Revoke If Leaked
If you suspect the token has leaked — or you just want to rotate it for hygiene — go back to @BotFather, find your bot, and use the /token command to revoke the current token and generate a new one. BotFather will give you a fresh token. Update TELEGRAM_BOT_TOKEN in ~/.hermes/.env and restart the gateway.
The old token stops working immediately once revoked.
3. Restrict with TELEGRAM_ALLOWED_USERS
By default, if you set a token but no allow-list, any Telegram user who finds your bot could potentially message it — depending on your Hermes configuration. Be explicit:
TELEGRAM_ALLOWED_USERS=123456789
Only add user IDs you trust. You can add multiple: 123456789,987654321. If you're the only user, just put your own ID.
4. .env Holds Secrets in Plaintext
.env is a shell-style environment file. The values are stored as plaintext on disk. This is standard practice for dev tooling, but it means:
The file should have restrictive file permissions (readable only by your user)
Don't copy it into cloud-synchronized folders without considering encryption
If you back up your Hermes profile, treat .env as sensitive
If your threat model requires it, you can encrypt the file at rest, but for most personal use cases the main risk is accidental exposure via backups, repos, or screenshots.
5. Bot is Public by Default — Your Data Isn't
Anyone can find your bot by its username and start a chat. That's how Telegram bots work. The allow-list is your control point: even if someone starts a chat, Hermes won't process their messages unless their user ID is in TELEGRAM_ALLOWED_USERS. The bot will effectively ignore unauthorized users.
Troubleshooting
Bot doesn't reply at all.
Check that TELEGRAM_BOT_TOKEN is correct and has no extra spaces or newlines.
Confirm the gateway restarted after editing .env (hermes gateway status).
Make sure your user ID is in TELEGRAM_ALLOWED_USERS — use @userinfobot to double-check the exact number.
Bot replies with an error or "not allowed."
Your user ID is probably not in the allow-list, or it's formatted incorrectly (no spaces, just comma-separated numbers).
Bot was working, now it stopped.
The token may have been revoked or regenerated. Check BotFather for a new token and update .env.
The gateway may have stopped or crashed. Restart it.
574r570rm
Comments