Telegram is one of the most popular messaging platforms in the world, with a powerful Bot API ecosystem. Using OpenClaw's open-source, self-hosted AI assistant, you can easily create your own Telegram AI bot and chat with models like Claude or GPT anytime, anywhere. This tutorial covers the complete process of connecting OpenClaw to Telegram from scratch.
Prerequisites
Before you begin, make sure you've completed the following:
- Node.js 22 or later is installed
- OpenClaw is installed and initialized (
openclaw onboard) - You have a Telegram account
- The OpenClaw Gateway is running (default port 18789)
If you haven't installed OpenClaw yet, you can get started quickly:
npm install -g openclaw@latest
openclaw onboard
The setup wizard will guide you through the basics, including choosing an AI model provider and entering your API key.
Step 1: Create a Telegram Bot via BotFather
All Telegram bots are created and managed through the official @BotFather. Open Telegram, search for @BotFather, start a conversation, and follow these steps:
- Send the
/newbotcommand - BotFather will ask you for a display name for the bot, e.g.,
My AI Assistant - Next, set a username that must end with
bot, e.g.,my_ai_assistant_bot - Once created, BotFather will return a Bot Token in the format
7123456789:AAHxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Important: Keep this token safe and never share it with anyone. Anyone with the token has full control over your bot.
You can further customize your bot through BotFather:
/setdescription - Set the bot description
/setabouttext - Set the "About" info
/setuserpic - Set the avatar
Step 2: Configure the Telegram Channel in OpenClaw
Now that you have a Bot Token, add it to your OpenClaw configuration file:
nano ~/.config/openclaw/openclaw.json5
Add the Telegram channel configuration under the channels section:
{
channels: {
telegram: {
enabled: true,
botToken: "7123456789:AAHxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
// Optional: list of allowed Telegram user IDs
allowedUsers: [],
// Optional: how the bot responds in groups
groupBehavior: "mention", // "mention" = only when @mentioned, "always" = respond to every message
}
}
}
Save the file and restart the OpenClaw Gateway to apply the changes:
openclaw gateway restart
Step 3: Verify the Connection
After configuring, use the built-in diagnostic tool to check the connection:
openclaw doctor
This command checks the status of all configured channels. If the Telegram channel shows as green or "connected," the setup was successful. You can also view more detailed status information through the Dashboard:
openclaw dashboard
Now open Telegram, find the bot you just created, and send it a message. If everything is working, the bot should reply.
Step 4: Add the Bot to a Group
OpenClaw's Telegram bot supports not only private chats but also group conversations. Here's how to add it:
- Open the settings for the target Telegram group
- Tap "Add Members" and search for your bot's username
- Add the bot to the group
By default, the bot uses mention mode in groups, meaning it only responds when someone @mentions it. This prevents the bot from replying to every single message and disrupting normal conversations.
If you want the bot to respond to all messages in a group, change groupBehavior to "always" — though this is typically only appropriate for dedicated AI discussion groups.
Step 5: Configure Privacy Mode
Telegram bots have Privacy Mode enabled by default, which means in group chats the bot can only see:
- Messages starting with
/(commands) - Messages that directly @mention the bot
- Replies to the bot's own messages
If you need the bot to see all messages in a group (for example, to maintain conversation context), you'll need to disable Privacy Mode through BotFather:
- Send
/mybotsto@BotFather - Select your bot
- Go to
Bot Settings>Group Privacy - Select
Turn off
Note: After disabling Privacy Mode, the bot must be removed from the group and re-added for the change to take effect.
Security Recommendations
Security is important when deploying a Telegram bot:
- Restrict user access: Add allowed Telegram user IDs to the
allowedUserslist to prevent strangers from consuming your AI quota - Protect the Gateway port: Never expose port 18789 directly to the internet — always use a reverse proxy like Nginx
- Rotate your token regularly: If you suspect the token has been compromised, immediately regenerate it using the
/revokecommand in BotFather
You can find your own Telegram user ID by sending any message to @userinfobot.
Wrapping Up
You've successfully connected OpenClaw to Telegram and now have a private AI chatbot. You can ask questions in a private chat or add the bot to a work group to assist your team. For more advanced settings and tips, check the OpenClaw official documentation. If you run into issues during setup, visit the OpenClaw GitHub repository to browse existing issues or submit feedback.