Why use Telegram as a channel
Messaging is already on your phone, you do not need to open a web interface, and you can receive notifications from the agent (reports, alerts, results of scheduled tasks). The article Setting up a Telegram AI agent: token, configuration and the first task covers the first steps in detail; this article focuses on how to make it a safe automation channel, with both systems.
Common step: create the bot
In Telegram, open @BotFather (check that the name is exactly @BotFather), send /newbot, set a display name and a unique username ending in bot. BotFather returns an API token. This token is the key that controls the bot: whoever has the token controls it. If it leaks, use /token in BotFather to generate a new one. You can also create a bot in BotFather's web interface instead of chat.
With Hermes Agent
According to the Hermes documentation:
- Interactive way: run
hermes gateway setupand choose Telegram; the wizard asks for the bot token and the allowed user IDs. - Manual way: add the variables
TELEGRAM_BOT_TOKENandTELEGRAM_ALLOWED_USERS(the numeric IDs of the allowed people, separated by commas) to~/.hermes/.env. - Start the gateway with
hermes gateway(orhermes gateway start,hermes gateway status,hermes gateway stop). In the desktop app there is a Create with QR button that creates the bot, detects your ID, writes the two variables above into the profile and restarts the gateway. - Find your user ID with @userinfobot or @get_id_bot; the ID is a number, not a username.
With OpenClaw
According to the OpenClaw documentation:
openclaw channels add --channel telegram --token <bot-token>
openclaw channels status --probe
Or configure manually in ~/.openclaw/openclaw.json with channels.telegram containing enabled, botToken, dmPolicy: "pairing" and groups: { "*": { requireMention: true } }. The TELEGRAM_BOT_TOKEN variable only applies to the default account, and configuration takes priority over environment variables. Then message the bot to create a pairing request and approve it:
openclaw pairing list telegram
openclaw pairing approve telegram <CODE>
The pairing code expires after 1 hour. For details on direct-message and group policy, see the security lessons.
Using it in groups
Both systems note the same thing: the bot's Privacy Mode is on by default, so in a group the bot only sees / commands, replies to it and service messages. To let it see every message, turn it off in BotFather (/mybots, choose the bot, Bot Settings, Group Privacy, Turn off) or make the bot a group admin; after changing the mode you must remove the bot from the group and add it again. Group IDs are negative numbers. Hermes has telegram.require_mention (accept only when mentioned by name, replying to the bot or matching a pattern), while OpenClaw uses requireMention for groups. Hermes also has TELEGRAM_GROUP_ALLOWED_USERS (for specific senders in a group) and TELEGRAM_GROUP_ALLOWED_CHATS (for all members of the listed groups).
Safety rules
- Limit users. List only your own numeric ID. Both documents warn that a wildcard allowing everyone to command the bot only suits a public bot with very limited tools.
- Keep the token like a password. Do not paste it in chat, a code repository or a screenshot. Revoke it at once if you suspect a leak.
- An agent that takes commands from chat should have narrow permissions. Do not give the bot permission to run commands on the machine beyond messaging unless needed.
- Webhooks need a secret. Hermes requires
TELEGRAM_WEBHOOK_SECRETin webhook mode and the gateway refuses to run without it; a local Bot API server has no extra authentication, so bind it to127.0.0.1and do not open port 8081 to the internet. - Content in groups is untrusted data. Other people's messages can contain instructions injected into the agent.
Turning chat into an automation channel
Once the channel is safe, you can use it for: scheduled tasks that send reports into the chat, notifications when a long task finishes, quick commands from a phone. For how to schedule, see Hermes AI Agent: using an agent framework to automate work. For each automation, ask yourself: if this message were forged, what is the worst thing the agent would do?