Developer documentation

Telegram text entities, mentions and drafts

Handle UTF-16 offsets, emoji, mentions and synchronized drafts without corrupting message formatting.

GetTGAPI editorial teamUpdated
Documentation notesReviewed

Based on official sources and independently maintained by GetTGAPI. Documentation and glossary →

On this page
  1. Emoji affects entity offsets
  2. Mentions are not limited to usernames
  3. Drafts synchronize across devices
  4. Editor recommendations

Emoji affects entity offsets

Entity offsets and lengths use UTF-16 code units, independently of string transport encoding. Neither UTF-8 byte length nor a visual character count is a substitute. Test emoji and combining sequences at formatting boundaries. Parse supported formatting into entities instead of executing user-supplied HTML.

Mentions are not limited to usernames

Entities support username-based and identity-based mentions. Unread mentions have their own counters and read operations; they are not simply the dialog’s unread-message count.

Drafts synchronize across devices

Saving, updating and clearing a draft are separate actions. Coordinate draft clearing with sending; media captions can also start from a draft.

Editor recommendations

Test Chinese text, emoji, line breaks, links and multiple formatting spans through both send and retrieval. Preserve a failed message as a draft and partition drafts by account. Clearing the input field is not evidence that a message was delivered.