Overview
Telegram is one of the most popular messaging platforms for AI bots. This guide shows you how to create a Telegram bot and connect it to your AgentClaw instance.
Step 1: Create a Telegram Bot
- Open Telegram and search for @BotFather
- Start a conversation with @BotFather
- Send the command
/newbot - Follow the prompts:
- Choose a display name (e.g., "My AI Assistant")
- Choose a username ending in "bot" (e.g., "myai_assistant_bot")
- BotFather will give you an API token - save this!
Example
You: /newbot BotFather: Alright, a new bot. How are we going to call it? You: My AI Assistant BotFather: Good. Now let's choose a username for your bot. You: myai_assistant_bot BotFather: Done! Your token is: 123456789:ABCdefGHIjklMNOpqrsTUVwxyzStep 2: Add Bot Token to AgentClaw
- Go to your AgentClaw instance configuration
- Add a new environment variable:
- Name:
TELEGRAM_BOT_TOKEN - Value: Paste the token from BotFather
- Name:
- Save the configuration
- Start or restart your instance
Step 3: Test Your Bot
- Wait for your instance to start (check logs)
- Open Telegram and search for your bot by username
- Start a conversation with
/start - Send a message to test the AI response
- Check AgentClaw logs to see the interaction
Customizing Your Bot
Set Bot Description
- Message @BotFather
- Send
/setdescription - Select your bot
- Enter a description (shown when users search for your bot)
Set About Text
- Send
/setabouttextto @BotFather - Select your bot
- Enter text (shown in bot's profile)
Set Profile Picture
- Send
/setuserpicto @BotFather - Select your bot
- Upload an image (512x512 recommended)
Set Commands
- Send
/setcommandsto @BotFather - Select your bot
- Enter commands in this format:
start - Start conversation help - Get help clear - Clear conversation history
Bot Privacy Settings
Privacy Mode
By default, bots in groups only receive messages that:
- Start with
/(commands) - Reply to the bot's messages
- @mention the bot
To receive all messages in groups:
- Send
/setprivacyto @BotFather - Select your bot
- Choose "Disable"
- Bot will now see all group messages
Note: Disabling privacy mode requires group admin permission.
Adding Bot to Groups
- Create or open a Telegram group
- Click group settings → Add members
- Search for your bot by username
- Add the bot to the group
- Make bot an admin if needed (for privacy mode disabled)
- Test with a message:
@yourbotname hello
Advanced Features
Inline Mode
Allow users to use your bot in any chat by typing @yourbot query:
- Send
/setinlineto @BotFather - Select your bot
- Enter placeholder text
- OpenClaw will handle inline queries automatically
Bot Payments
Enable payments through your bot:
- Send
/mybotsto @BotFather - Select your bot → Payments
- Connect a payment provider
- Configure in OpenClaw environment variables
Troubleshooting
Bot Not Responding
- Verify
TELEGRAM_BOT_TOKENis correct (no extra spaces) - Check instance logs for connection errors
- Ensure instance is running (status: Running)
- Try sending
/startfirst to initialize - Verify bot is not blocked by user
"Bot token invalid" Error
- Get a new token from @BotFather with
/token - Ensure token format is correct:
123456789:ABCdef... - Check for typos when copying token
- Verify bot wasn't deleted in @BotFather
Bot Receives Messages But Doesn't Reply
- Check AI provider API key is valid
- Verify AI provider has sufficient credits
- Review logs for AI API errors
- See API key errors guide
Bot Not Seeing Group Messages
- Disable privacy mode (see above)
- Make bot a group admin
- Use @mentions to trigger bot
Best Practices
- Choose a clear username: Make it obvious it's a bot
- Set a good description: Explain what your bot does
- Define commands: Help users discover features
- Never share your bot token: Treat it like a password
- Regenerate token if compromised: Use @BotFather's
/revoke - Test before announcing: Ensure bot works properly
Revoking and Regenerating Tokens
If your bot token is compromised:
- Message @BotFather
- Send
/mybots - Select your bot
- Click "API Token" → "Revoke current token"
- Get the new token
- Update
TELEGRAM_BOT_TOKENin AgentClaw - Restart your instance
Deleting a Bot
To permanently delete a bot:
- Message @BotFather
- Send
/deletebot - Select the bot to delete
- Confirm deletion
- Remove
TELEGRAM_BOT_TOKENfrom AgentClaw
Warning: This is permanent. The username may become available to others.
Next Steps
- Learn about Discord bot integration
- Explore WhatsApp support
- Read about securing API keys
- Understand monitoring with logs