Telethon Session
Skill by crazypeace
Install via CLI (Recommended)
clawhub install openclaw/skills/skills/crazypeace/telethon-sessionname: telethon-session description: Generate Telethon .session files for user-account login to Telegram. Use when: (1) user wants to test a Telegram bot as a real user, (2) user needs to interact with Telegram via user identity, (3) creating a Telegram session for Telethon-based automation, (4) mentions telethon, telegram session, or user-account login. NOT for: bot-token-based bots (no session needed).
Telethon Session Generator
Generate a .session file to authenticate a Telegram user account via Telethon.
Prerequisites
telethon(install in a venv)- API credentials from https://my.telegram.org (
api_id+api_hash)
Recommended: set as system environment variables
Set these once, then you won't need to re-type them:
TELEGRAM_API_IDTELEGRAM_API_HASHTELEGRAM_PHONE- (optional)
TELETHON_SESSION(default:telegram_session)
One-command interactive setup (writes a local .env)
Run:
bash scripts/setup_env.sh
This script will:
- Prompt you interactively for the 3 values (api_id/api_hash/phone)
- Write them to
.env(gitignored) - Tell you the exact
sourcecommand to load them into your current shell
Option A: put them in a local .env file (recommended)
In this skill directory, create .env (it is ignored by git):
TELEGRAM_API_ID=__SET_ME__
TELEGRAM_API_HASH=__SET_ME__
TELEGRAM_PHONE=__SET_ME__
TELETHON_SESSION=telegram_session
Lock down file permissions:
chmod 600 .env
Template: .env.example
Option B: export them in your shell
export TELEGRAM_API_ID=__SET_ME__
export TELEGRAM_API_HASH="..."
export TELEGRAM_PHONE="+8613..."
export TELETHON_SESSION=telegram_session
Quick Start (generate session)
Interactive (safe: avoids putting secrets in command history)
python3 scripts/login.py --session telegram_session
The script will prompt for:
api_idapi_hash(hidden)phone- Telegram login code (+ optional 2FA password)
On success, <session_name>.session is created in the working directory.
Common actions
Send a message
python3 scripts/send_message.py --api-id YOUR_ID --to @username --message "hi" --session telegram_session
(or omit --api-hash to be prompted with hidden input)
Read last messages from a dialog
python3 scripts/read_dialog.py --api-id YOUR_ID --with @username --limit 3 --session telegram_session
Key Notes
- Session file is reusable — no need to re-login unless Telegram invalidates it
- Do NOT commit
.sessionfiles to version control (treat as secrets) - Bot token ≠ session — bots use
bot_token=in Telethon, no session file needed - If
pip install telethonfails on externally-managed Python, use a venv:python3 -m venv venv source venv/bin/activate pip install telethon
Using the Session File (code)
from telethon import TelegramClient
Metadata
Not sure this is the right skill?
Describe what you want to build — we'll match you to the best skill from 16,000+ options.
Find the right skillPaste this into your clawhub.json to enable this plugin.
{
"plugins": {
"official-crazypeace-telethon-session": {
"enabled": true,
"auto_update": true
}
}
}Related Skills
telegram-pairing-send-code-to-every-start
Modify OpenClaw's Telegram pairing logic so unapproved users receive pairing codes on every /start message before approval. Use when users need to repeatedly access pairing codes after the initial request, ensuring consistent access to pairing instructions even if the initial code was missed or lost.
telegram-pairing-message-customization
Add custom messages to Telegram pairing replies for unapproved users. Insert custom text (e.g., group links, instructions) above the approval command in pairing messages. Use when unpaired Telegram users need additional guidance during the pairing process.
telegram-pairing-customization
Modify OpenClaw's Telegram pairing logic so unapproved users receive pairing codes on every /start message before approval. Use when users need to repeatedly access pairing codes after the initial request, ensuring consistent access to pairing instructions even if the initial code was missed or lost.
telegram-pairing-approver
创建一个持久运行的Telegram机器人服务,用于自动处理配对代码并批准Telegram会话权限。使用时提供机器人令牌,自动创建机器人脚本和服务文件,并启动系统服务。适用于需要自动处理Telegram配对请求的场景。
Openclaw Self Clone Everything
Skill by crazypeace