feat(telegram): render Markdown tables as native Rich Messages (opt-in) - #47
Open
hongmono wants to merge 1 commit into
Open
feat(telegram): render Markdown tables as native Rich Messages (opt-in)#47hongmono wants to merge 1 commit into
hongmono wants to merge 1 commit into
Conversation
Use Telegram Bot API 10.1 sendRichMessage to render Markdown tables natively instead of leaking pipe characters through the legacy sendMessage HTML path. - contains_markdown_table / send_rich_markdown / finalize_as_rich_table - per-chat opt-in setting rich_messages (default OFF) + /richmessages command - gate 3 streaming finalize paths; system prompt follows the setting - always falls back to the existing HTML path on failure (regression-free) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
요약
Telegram이 2026-06-11 Bot API 10.1에서 도입한 Rich Messages(
sendRichMessage)를 사용해, 마크다운 표를 네이티브 표로 렌더링합니다.현재는 모든 응답이
markdown_to_telegram_html()→ 구식sendMessage(HTML)로 나가는데, 이 변환에는 표 처리가 없어 표가 파이프(|) 텍스트로 노출됩니다(시스템 프롬프트도 이 때문에 표를 금지). 신규 API라 리스크를 고려해 per-chat opt-in(기본 OFF) 으로 설계했습니다.데모
/richmessages on전후 비교 — 위: OFF(파이프 텍스트), 아래: ON(네이티브 표):변경 사항
src/services/telegram.rs한 파일, +271/-1. 기존 로직 수정 없이 순수 추가 + 분기.헬퍼 3개
contains_markdown_table()— GFM 표(헤더행 +|---|구분행) 감지. 코드펜스 내부 제외로 오탐 방지.send_rich_markdown()— teloxide 0.13에 없는sendRichMessage를 reqwest로 직접 호출.api_base_url(프록시) 존중, 토큰 리댁션, 30s 타임아웃,ok:true만 성공 처리.finalize_as_rich_table()— 롤링 placeholder를 삭제 후 Rich Message로 교체. 실패 시 기존 HTML 경로로 폴백.설정 · 명령어
BotSettings.rich_messages: HashMap<String, bool>(기본 OFF) +bot_settings.json영속화./richmessages(on/off/status/토글) — 기존/fast패턴과 동일. BotCommand·라우팅·/help포함.연동
handle_text_message·execute_schedule·process_bot_message)에 분기 추가: 표 포함 + 단일 메시지(last_confirmed_len == 0) + opt-in ON일 때만 Rich 전송.설계 원칙
} else {앞에} else if {…}만 삽입. 그 외 트래픽은 모두 기존 경로 유지.알려진 범위 (1차)
테스트
cargo build통과, 신규 경고 0./richmessages on→ 설정 저장 확인 ✅ / ON: 표 요청 → 네이티브 표 ✅|→ 표로 오탐 안 됨 ✅