Telegram Autopilot
by @shor73
Manage a Telegram userbot autopilot that responds to private messages as the user using AI. Use when the user wants to set up auto-replies on their personal...
clawhub install telegram-autopilotπ About This Skill
name: telegram-autopilot description: Manage a Telegram userbot autopilot that responds to private messages as the user using AI. Use when the user wants to set up auto-replies on their personal Telegram account, manage allowed contacts, configure AI response style, or send messages/media as themselves. Triggers on "telegram autopilot", "auto reply telegram", "manage my telegram", "respond for me", "telegram userbot", "paid media telegram". Requires secrets β Telegram API credentials (api_id, api_hash), phone number, optional 2FA password, AI provider API key (Anthropic or OpenAI-compatible), optional Telegram bot token for owner notifications.
Telegram Autopilot
> Source: https://github.com/Shor73/telegram-autopilot > Author: @Shor73 > License: MIT
AI-powered autopilot for personal Telegram accounts. Responds to private messages as the user when they're unavailable.
Prerequisites
pip3 install telethonSetup
1. Get Telegram API Credentials
Direct the user to https://my.telegram.org β API Development Tools β create app. They need: API ID (number) and API Hash (string).
2. Login Flow
Telegram login requires: phone β OTP code β optional 2FA password.
Critical: OTP codes expire in ~60 seconds. Minimize latency:
Run scripts/setup.py with the user's credentials. It handles:
1. Requesting the OTP code
2. Waiting for code via file (enter_code.txt)
3. 2FA password if needed
4. Saving the session file
python3 scripts/setup.py --api-id 12345 --api-hash "abc123" --phone "+1234567890"
The session file (.session) persists auth β login is one-time only.
3. Configure Contacts
Edit config.json to define allowed contacts:
{
"contacts": {
"username": {
"name": "Display Name",
"id": 123456789,
"tone": "friendly",
"language": "en"
}
},
"ai": {
"provider": "anthropic",
"model": "claude-sonnet-4-6",
"api_key": "sk-ant-...",
"max_tokens": 300
},
"owner": {
"name": "Owner Name",
"bio": "Brief description for the AI persona",
"telegram_id": 123456789
},
"notifications": {
"bot_token": "optional-bot-token-for-notifications",
"chat_id": "optional-chat-id"
}
}
4. Start Autopilot
python3 scripts/autopilot.py --config config.json --session session_name
Features
Auto-Reply
AI Persona
Notifications
Paid Media (Channels Only)
Telegram paid media (inputMediaPaidMedia) only works in channels, not private chats.To send paid media:
1. Create a private channel
2. Post media with InputMediaPaidMedia(stars_amount=N, extended_media=[...])
3. Generate invite link and send to recipient
python3 scripts/send_paid_media.py --session session_name --target username --photo /path/to/photo.jpg --stars 1
Management Commands
Stop autopilot: kill the process or send SIGTERM.
Add/remove contacts: edit config.json and restart.
Architecture
telegram-autopilot/
βββ SKILL.md
βββ scripts/
β βββ setup.py β Login flow (OTP + 2FA)
β βββ autopilot.py β Main event loop
β βββ send_paid_media.py β Paid media via channel
β βββ code_server.py β Web form for fast OTP entry
βββ references/
βββ telegram-auth.md β Telegram auth flow documentation
Required Credentials
| Secret | Purpose | Where used |
|---|---|---|
| Telegram API ID + Hash | MTProto client auth | setup.py, autopilot.py |
| Phone number + 2FA | Account login (one-time) | setup.py |
| AI API key | Response generation | autopilot.py |
| Bot token (optional) | Owner notifications | autopilot.py |
All secrets are stored in config.json β never commit this file.
Security & Ethics
.session file grants full access to the account. Protect it like a password.code_server.py binds to 127.0.0.1 (localhost only). Never expose it to the network.βοΈ Configuration
1. Get Telegram API Credentials
Direct the user to https://my.telegram.org β API Development Tools β create app. They need: API ID (number) and API Hash (string).
2. Login Flow
Telegram login requires: phone β OTP code β optional 2FA password.
Critical: OTP codes expire in ~60 seconds. Minimize latency:
Run scripts/setup.py with the user's credentials. It handles:
1. Requesting the OTP code
2. Waiting for code via file (enter_code.txt)
3. 2FA password if needed
4. Saving the session file
python3 scripts/setup.py --api-id 12345 --api-hash "abc123" --phone "+1234567890"
The session file (.session) persists auth β login is one-time only.
3. Configure Contacts
Edit config.json to define allowed contacts:
{
"contacts": {
"username": {
"name": "Display Name",
"id": 123456789,
"tone": "friendly",
"language": "en"
}
},
"ai": {
"provider": "anthropic",
"model": "claude-sonnet-4-6",
"api_key": "sk-ant-...",
"max_tokens": 300
},
"owner": {
"name": "Owner Name",
"bio": "Brief description for the AI persona",
"telegram_id": 123456789
},
"notifications": {
"bot_token": "optional-bot-token-for-notifications",
"chat_id": "optional-chat-id"
}
}
4. Start Autopilot
python3 scripts/autopilot.py --config config.json --session session_name