← 返回 Skills 市场
polityang

Telegram QR Login Workaround

作者 Polityang · GitHub ↗ · v1.0.0 · MIT-0
cross-platform ⚠ suspicious
28
总下载
0
收藏
0
当前安装
1
版本数
在 OpenClaw 中安装
/install telegram-qr-login-workaround
功能描述
Telegram新设备登录 — 绕过PHONE_CODE_EXPIRED错误,用QR码扫描代替验证码,附脚本和完整流程
使用说明 (SKILL.md)

Telegram QR Login — 绕过"PHONE_CODE_EXPIRED"的终极方案

问题症状

用 Pyrogram/Telethon 通过手机号+验证码登录 Telegram 时:

  • 验证码明明刚收到,立即写入文件
  • 仍然报 PHONE_CODE_EXPIRED
  • Telegram 官方邮件说"Device not approved"

根本原因

Telegram 的新设备登录安全机制:

  1. 检测到来自新设备(IP/设备指纹)
  2. 要求在手机 App上手动批准(设置 → 设备 → 批准新设备)
  3. 验证码本身没问题,但设备未被批准 = 直接过期

注意PHONE_CODE_EXPIRED 在这里是误导性错误,真实原因是"设备未批准",而非5分钟超时。

解决方案:QR码登录(100%有效)

用 Telethon 的 qr_login() 方法,让用户直接扫QR,设备自动加入可信列表。

环境准备

# 创建独立 Python 环境(推荐3.12)
python3 -m venv /tmp/tg_env
source /tmp/tg_env/bin/activate
pip install telethon qrcode pillow

完整脚本

import asyncio, os, qrcode
from telethon import TelegramClient

API_ID = "你的api_id"        # https://my.telegram.org
API_HASH = "你的api_hash"    # 同上
SESSION_PATH = "/path/to/session"  # session文件路径

OUT_PNG = "/tmp/tg_qr.png"

async def main():
    client = TelegramClient(SESSION_PATH, API_ID, API_HASH)

    print("Connecting...", flush=True)
    await client.connect()
    print("Connected. Generating QR...", flush=True)

    # 获取QR码
    qr_login = await client.qr_login()
    url = qr_login.url
    print(f"QR URL: {url}", flush=True)

    # 生成PNG图片
    img = qrcode.make(url)
    img.save(OUT_PNG)
    print(f"QR saved: {OUT_PNG}", flush=True)

    # 等待扫码完成
    print("Waiting for scan...", flush=True)
    await qr_login.wait()
    print("Scanned!", flush=True)

    me = await client.get_me()
    print(f"OK: {me.first_name} @{me.username} ID={me.id}", flush=True)
    await client.disconnect()

asyncio.run(main())

使用流程

  1. 运行脚本 → 生成 /tmp/tg_qr.png
  2. 用户手机 Telegram → 设置 → 设备 → 扫描QR码
  3. 扫完即登录成功,session文件自动保存
  4. 以后复用这个session,无需再验证码

推送QR码给用户(示例)

# 发送图片给Telegram用户
with open("/tmp/tg_qr.png", "rb") as f:
    await client.send_file("telegram_chat_id", f)

常见坑

错误 原因 解决
PHONE_CODE_EXPIRED 设备未批准,被误判为超时 用QR码登录
PHONE_NUMBER_INVALID 短时间内请求次数过多被封 等2分钟再试
PeerUser not found (删私聊时) 对话已不存在 跳过,无需处理
QR扫描后立即过期 网络问题或IP不稳定 换个网络重试

关键发现

  1. 验证码过期 ≠ 真的过期:Telegram 的错误信息有误导性
  2. QR码绕过所有验证:扫描即入可信设备列表,不需要手机号验证
  3. Session 格式:Telethon 和 Pyrogram 的 session 文件格式互不兼容,选一个一直用
  4. 独立 venv:避免系统 Python 包冲突

批量清理对话

清理可疑频道/陌生私聊:见 references/telegram-cleanup-workflow.md(含脚本 + 失败处理)

发布到 GitHub / ClawHub

GitHub Gist(最快,1分钟搞定)

用户去 https://github.com/settings/tokens/new 创建 PAT(勾 gist scope),发给你后用 curl 直接调用 GitHub API:

curl -s -X POST "https://api.github.com/gists" \
  -H "Authorization: token \x3CPAT>" \
  -H "Content-Type: application/json" \
  -d '{
    "description": "\x3C标题>",
    "public": true,
    "files": {
      "telegram-qr-login.md": {"content": "..."}
    }
  }'

返回 html_url 即为发布链接。无需 gh CLI,无需登录。

ClawHub

ClawHub 需要独立的 GitHub OAuth 登录(Sign in with GitHub),不支持 GitHub PAT。 流程:

  1. npm i -g clawhub(已装)
  2. 用户在 https://clawhub.ai/login 用 GitHub OAuth 登录
  3. 登录后用 clawhub login --token \x3Ctoken> 或浏览器交互方式认证
  4. clawhub skill publish \x3Cpath> --slug \x3Cslug>

注意:ClawHub skill 存储在 Convex 数据库,GitHub 仓库 openclaw/clawhub 的 skills/ 目录是模板,非实际发布路径。

适用场景

  • 新设备首次登录 Telegram
  • 账号因频繁验证请求被临时封禁
  • 自动化脚本需要无感知的长期登录
安全使用建议
Only use this on a device you control, never share Telegram QR codes, session files, API hashes, or GitHub PATs with an agent or third party, and revoke any Telegram session or GitHub token you no longer need. Treat the GitHub/ClawHub publishing and missing cleanup-script sections as outside the core Telegram login workaround and review them separately before taking action.
功能分析
Type: OpenClaw Skill Name: telegram-qr-login-workaround Version: 1.0.0 The skill bundle provides a legitimate technical workaround for Telegram's 'PHONE_CODE_EXPIRED' error using Telethon's QR code login method. The provided Python script and instructions in SKILL.md are well-documented, use standard libraries (telethon, qrcode), and contain no evidence of data exfiltration, malicious execution, or prompt injection. The publishing instructions for GitHub Gist and ClawHub are standard automation workflows for an AI agent.
能力标签
requires-oauth-tokenrequires-sensitive-credentials
能力评估
Purpose & Capability
The Telegram QR-login purpose is coherent, but the skill also includes unrelated GitHub/ClawHub publishing steps and a referenced bulk Telegram cleanup workflow, expanding beyond the stated login workaround.
Instruction Scope
The instructions create a reusable Telegram session and suggest token-backed API publishing without clear approval, retention, revocation, or containment guidance.
Install Mechanism
There is no install spec or bundled code; setup is user-directed, but it uses unpinned package/global CLI examples and references a script file not included in the artifact set.
Credentials
Registry metadata declares no required credentials or primary credential, while SKILL.md expects Telegram API credentials/session state and suggests GitHub PAT and ClawHub token use.
Persistence & Privilege
The workflow intentionally creates a persistent Telegram session that can be reused without future verification, which is high-impact account authority.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install telegram-qr-login-workaround
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /telegram-qr-login-workaround 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.0.0
Initial release — Telegram QR扫码绕过PHONE_CODE_EXPIRED登录问题 - 提供详尽说明,解释PHONE_CODE_EXPIRED出现的真实原因与误导机制。 - 提供基于Telethon的QR扫码登录完整Python脚本,实现无需手机验证码安全登录。 - 附详细使用流程、环境依赖安装和常见问题排查。 - 包含QR图片推送示例、批量对话清理方法及脚本引用。 - 补充GitHub Gist与ClawHub平台的发布方法说明。 - 适用于新设备无法验证码登录、频繁验证被限流等场景。
元数据
Slug telegram-qr-login-workaround
版本 1.0.0
许可证 MIT-0
累计安装 0
当前安装数 0
历史版本数 1
常见问题

Telegram QR Login Workaround 是什么?

Telegram新设备登录 — 绕过PHONE_CODE_EXPIRED错误,用QR码扫描代替验证码,附脚本和完整流程. 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 28 次。

如何安装 Telegram QR Login Workaround?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install telegram-qr-login-workaround」即可一键安装,无需额外配置。

Telegram QR Login Workaround 是免费的吗?

是的,Telegram QR Login Workaround 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

Telegram QR Login Workaround 支持哪些平台?

Telegram QR Login Workaround 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 Telegram QR Login Workaround?

由 Polityang(@polityang)开发并维护,当前版本 v1.0.0。

💬 留言讨论