feat: chat-adapter-telegram MarkdownV2#369
Draft
fuxingloh wants to merge 1 commit intovercel:mainfrom
Draft
Conversation
Contributor
|
@fuxingloh is attempting to deploy a commit to the Vercel Labs Team on Vercel. A member of the Team first needs to authorize it. |
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.
chat-adapter-telegram@4.25.0.patch if anyone want to test it locally
Fix Telegram MarkdownV2 escaping (
@chat-adapter/telegram)Problem
Telegram was rejecting messages with:
This fired on almost every LLM reply because
.,(,),-,|,!appear in ordinary prose. Downstream harnesses were forced to wrapthread.post(result.fullStream)in atry/catchthat fell back to plain text — doubling latency and dropping the stream.Root cause: the adapter sent
parse_mode: "Markdown"(legacy) and emitted text produced byremark-stringify, which does not escape the 18 characters MarkdownV2 reserves.Fix
Switched to
parse_mode: "MarkdownV2"and replaced the body ofTelegramFormatConverter.fromAstwith an mdast AST walker that applies context-aware escaping per the Telegram spec._ * [ ] ( ) ~>#+-=|{}.!code/pre`and\(…))and\Also:
*…*, italic →_…_, strike →~…~, headings → bold.\-, ordered numerals asN\..\-\-\-.renderPostable(string)escapes plain strings (safe default for raw LLM output).renderPostable({ raw })still passes through unescaped — caller opts in.Sources
telegram-markdown-v2for theescapeSymbolsper-context semantics.Testing
pnpm --filter @chat-adapter/telegram test— 103/103 pass (60 index, 9 cards, 34 markdown).pnpm --filter @chat-adapter/telegram typecheck— clean.pnpm --filter @chat-adapter/telegram build— clean..,(,),/,!(the exact trigger from the bug report).`and\escaped inside inline code.)escaped inside link URLs.*,_,~).>.parse_mode === "Markdown"to"MarkdownV2".Migration
None for consumers. Output format changes:
**bold**→*bold**italic*→_italic_~~strike~~→~strike~If a caller was hand-crafting legacy-Markdown strings and passing them via
{ raw }, they will now render as literal text (sincerawis passedthrough unescaped). Switch to
{ markdown }to get proper conversion.Changeset
Minor — see
.changeset/telegram-markdown-v2-escape.md.Test plan
Hello (world). Path: src/foo.ts!— should render without falling back to plain text.chat-adapter-telegram@4.25.0.patchin my project and test it.