Skip to content

feat(telegram): convert entities to markdown in parsed messages#232

Open
dzhng wants to merge 1 commit intovercel:mainfrom
dzhng:fix/telegram-entity-formatting
Open

feat(telegram): convert entities to markdown in parsed messages#232
dzhng wants to merge 1 commit intovercel:mainfrom
dzhng:fix/telegram-entity-formatting

Conversation

@dzhng
Copy link

@dzhng dzhng commented Mar 13, 2026

Summary

Telegram delivers formatting (bold, italic, links, code, etc.) as separate entity objects alongside plain text. Previously, parseTelegramMessage only used the raw text field, losing all entity information — most critically, text_link entity URLs were dropped entirely.

For example, a Telegram message with "Visit our website for details" would arrive as:

  • text: "Visit our website for details"
  • entities: [{ type: "text_link", offset: 10, length: 7, url: "https://example.com" }]

The link URL was completely lost in the parsed message.text.

Changes

  • Adds applyTelegramEntities() which reconstructs markdown syntax from Telegram entities before storing the message text
  • Supported entity types: text_link[text](url), bold**text**, italic*text*, code`text`, pre```text```, strikethrough~~text~~
  • Other entity types (url, mention, bot_command) are already present in the raw text and left unchanged
  • Adds missing url and language fields to TelegramMessageEntity type
  • Passes original plain text to isBotMentioned() to preserve correct entity offset calculations

Test plan

  • 12 new unit tests for applyTelegramEntities covering all entity types, edge cases, and integration with parseMessage
  • All 101 existing tests pass
  • Lint/format clean (pnpm -w run check passes)

Telegram delivers formatting (bold, italic, links, code, etc.) as separate
entity objects alongside plain text. Previously, parseTelegramMessage only
used the raw text, losing all entity information — most critically, text_link
entity URLs were dropped entirely.

This adds applyTelegramEntities() which reconstructs markdown syntax from
entities before storing the message text. Supported entity types: text_link,
bold, italic, code, pre, and strikethrough. Other entity types (url, mention,
bot_command) are already present in the text and left unchanged.

Also adds the missing `url` and `language` fields to TelegramMessageEntity.
@vercel
Copy link
Contributor

vercel bot commented Mar 13, 2026

@dzhng is attempting to deploy a commit to the Vercel Labs Team on Vercel.

A member of the Team first needs to authorize it.

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