Telegram Bot Manager
Quick Start
Setup a new Telegram bot
- 1. Create bot via BotFather
- Message @BotFather on Telegram
- Use
/newbot command
- Follow prompts for bot name and username
- Copy the bot token (format:
1234567890:ABCdefGHIjklMNOpqrsTUVwxyz)
- 2. Configure in OpenClaw
- Add token to OpenClaw config
- Enable Telegram plugin
- Set up pairing mode for DM access
Validate bot configuration
CODEBLOCK0
Common Workflows
Troubleshooting connectivity issues
When api.telegram.org is unreachable:
- 1. Check network access
CODEBLOCK1
- 2. Verify DNS resolution
CODEBLOCK2
- 3. Test alternative endpoints
CODEBLOCK3
Configuring OpenClaw Telegram integration
See OPENCLAW_CONFIG.md for detailed configuration steps.
Bot token security
- - Never commit bot tokens to version control
- Store tokens in environment variables or secure config files
- Rotate tokens if compromised
- Use different tokens for different environments (dev/prod)
Bot Commands Reference
Common Telegram bot commands for BotFather:
- -
/newbot - Create a new bot - INLINECODE3 - Manage your bots
- INLINECODE4 - Set bot description
- INLINECODE5 - Set about text
- INLINECODE6 - Set bot profile picture
- INLINECODE7 - Set bot commands
- INLINECODE8 - Generate new token
- INLINECODE9 - Revoke current token
- INLINECODE10 - Configure privacy mode
Webhook vs Polling
Webhook (Recommended for production)
- - Bot receives updates via HTTP POST
- Requires public HTTPS endpoint
- More efficient for high-volume bots
Polling (Good for development)
- - Bot continuously checks for updates
- Simpler setup, no public endpoint needed
- Easier to debug locally
See WEBHOOK_SETUP.md for webhook configuration.
Error Handling
Common errors and solutions
"Connection timed out"
- - Check firewall rules
- Verify proxy configuration
- Test with different network
"Invalid token"
- - Verify token format (should contain colon)
- Check for extra spaces or characters
- Regenerate token if needed
"Bot not responding"
- - Verify bot is not blocked
- Check bot privacy settings
- Ensure bot has proper permissions
Testing Your Bot
Manual testing
- 1. Search for your bot username on Telegram
- Start a conversation with INLINECODE11
- Test basic commands
Automated testing
Use the test script in
scripts/test_bot.py for automated validation.
References
Telegram Bot Manager
快速开始
设置新Telegram机器人
- 1. 通过BotFather创建机器人
- 在Telegram上向@BotFather发送消息
- 使用/newbot命令
- 按照提示输入机器人名称和用户名
- 复制机器人令牌(格式:1234567890:ABCdefGHIjklMNOpqrsTUVwxyz)
- 2. 在OpenClaw中配置
- 将令牌添加到OpenClaw配置中
- 启用Telegram插件
- 设置配对模式以允许私信访问
验证机器人配置
bash
测试Telegram API连接
curl -I https://api.telegram.org
检查机器人令牌有效性
curl -s https://api.telegram.org/bot<你的令牌>/getMe
常见工作流程
排查连接问题
当api.telegram.org无法访问时:
- 1. 检查网络访问
bash
curl -I -m 10 https://api.telegram.org
- 2. 验证DNS解析
bash
nslookup api.telegram.org
- 3. 测试备用端点
bash
curl -I https://telegram.org
配置OpenClaw Telegram集成
详细配置步骤请参见OPENCLAW_CONFIG.md。
机器人令牌安全
- - 切勿将机器人令牌提交到版本控制系统
- 将令牌存储在环境变量或安全配置文件中
- 令牌泄露后立即轮换
- 为不同环境(开发/生产)使用不同令牌
机器人命令参考
BotFather的常用Telegram机器人命令:
- - /newbot - 创建新机器人
- /mybots - 管理你的机器人
- /setdescription - 设置机器人描述
- /setabouttext - 设置关于文本
- /setuserpic - 设置机器人头像
- /setcommands - 设置机器人命令
- /token - 生成新令牌
- /revoke - 撤销当前令牌
- /setprivacy - 配置隐私模式
Webhook与轮询
Webhook(推荐用于生产环境)
- - 机器人通过HTTP POST接收更新
- 需要公开的HTTPS端点
- 对高流量机器人更高效
轮询(适合开发环境)
- - 机器人持续检查更新
- 设置更简单,无需公开端点
- 本地调试更方便
Webhook配置请参见WEBHOOK_SETUP.md。
错误处理
常见错误及解决方案
连接超时
- - 检查防火墙规则
- 验证代理配置
- 尝试使用不同网络测试
无效令牌
- - 验证令牌格式(应包含冒号)
- 检查是否有多余空格或字符
- 必要时重新生成令牌
机器人无响应
- - 确认机器人未被屏蔽
- 检查机器人隐私设置
- 确保机器人拥有适当权限
测试你的机器人
手动测试
- 1. 在Telegram上搜索你的机器人用户名
- 使用/start开始对话
- 测试基本命令
自动化测试
使用scripts/test_bot.py中的测试脚本进行自动验证。
参考资料