Skip to content

feat(frontends): add tgapp_plus_v2.py — Rich rendering Telegram frontend - #764

Open
v2up-32mb wants to merge 1 commit into
lsdefine:mainfrom
v2up-32mb:feat/tgapp-plus-v2
Open

feat(frontends): add tgapp_plus_v2.py — Rich rendering Telegram frontend#764
v2up-32mb wants to merge 1 commit into
lsdefine:mainfrom
v2up-32mb:feat/tgapp-plus-v2

Conversation

@v2up-32mb

Copy link
Copy Markdown

概述

新增 frontends/tgapp_plus_v2.py,一个增强版 Telegram Bot 前端,在 tgapp.py 基础上增加了 Telegram Rich 原生渲染能力。

相比 tgapp.py 的改进

维度 tgapp.py (1138行) tgapp_plus_v2.py (1809行, +671)
Rich 原生渲染 ❌ 无 ✅ Bot API sendRichMessage:表格 / task-list / <details>折叠 / 块级公式
渲染降级 仅 MarkdownV2 ✅ 三档:Rich → MarkdownV2(format_message) → 纯文本(_strip_mdv2)
TG Desktop 适配 ✅ 检测 CJK 乱码 / Math 崩溃,自动跳过 Rich
GFM 表格 _wrap_markdown_tables 把管道表格重写为粗体+列表
引用消息 基础 _extract_quoted_contentrich_message.blocks 还原(支持 quote / external_reply / reply_to)
turn 摘要 基础 ✅ 可折叠 expandable blockquote 引用块
流式会话 _TelegramStreamSession 基础 ✅ 增强:Rich send/edit 双路径 + 降级 latch

关键设计

  • Rich → MarkdownV2 → 纯文本 三档降级链,保证在任何 Telegram 客户端都能正常显示
  • Rich 渲染用纯正则实现(参考 Hermes format_message 占位符保护法),不依赖 mistune/BeautifulSoup
  • TG Desktop 客户端对 Rich text 的 CJK/Math 渲染有 bug,自动检测并降级

额外依赖

无额外依赖。与 tgapp.py 的 import 完全一致,仅依赖原有的 python-telegram-bot

兼容性

  • 作为独立文件新增,不修改现有 tgapp.py,不影响现有功能
  • 可作为 tgapp.py 的可选替代前端使用

…elegram

- Rich native rendering via Bot API sendRichMessage (tables/task-list/details/fenced math)
- Three-tier fallback: Rich -> MarkdownV2 -> plain text
- TG Desktop adaptation (CJK garble / Math crash auto-skip)
- GFM table support (_wrap_markdown_tables)
- Quoted message extraction (_extract_quoted_content from rich_message.blocks)
- Turn-summary expandable blockquote
- Enhanced _TelegramStreamSession (Rich send/edit dual-path + fallback latch)
- No extra dependencies (only python-telegram-bot, same as tgapp.py)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant