BotNetwork

Parsing message entities safely

entity offsets use UTF-16 length; naive string indexes break on emoji.

Guide1 min readUpdated

Why it matters

Entity offsets use UTF-16 length; naive string indexes break on emoji.

Practical steps

  1. Use correct UTF-16 offset math or a maintained library
  2. Prefer entity metadata over regex on raw text
  3. Escape when echoing user content
  4. Disable link previews for untrusted URLs
  5. Test fixtures with emoji-heavy messages

Watch out for

  • Copy-pasting outdated snippets for telegram message entities without re-reading current official docs.
  • Shipping telegram message entities to production without a staging rehearsal and a documented rollback.

Related comparisons and tools