danog/telegram-entities
Convert Telegram message entities to and from Markdown, HTML and plain text with this lightweight PHP library. Parse formatted messages, preserve styling, and generate entity arrays for sending rich text via the Telegram Bot API or MadelineProto.
(offset, length) pairs counted in UTF-16 code units, while PHP strings are UTF-8 bytes. Getting this right means handling surrogate pairs (emoji, flags, some CJK), grapheme clusters, and re-indexing after every edit. That is days of fiddly work plus a permanent tail of production bugs. Adopting a focused library here is a straightforward cost-avoidance decision.code and pre blocks, text links, mentions, blockquotes — this package is the plumbing layer under that feature. It lets you accept author-friendly input (HTML or Markdown) and emit correct Telegram entities, and do the reverse for rendering Telegram content elsewhere.Adopt when:
danog) and is part of that ecosystem, so it is likely already in your dependency tree. Use it directly instead of re-implementing.Look elsewhere when:
parse_mode: HTML / MarkdownV2 is sufficient and adds zero dependencies. This library earns its place only when you must compute, inspect, or mutate offsets.irazasyed/telegram-bot-sdk, or BotMan give you routing, conversations, and keyboards; treat entity handling as one narrow concern inside that choice rather than a reason to pick a stack.league/commonmark with a thin entity converter, and verify this library's parser covers your accepted syntax subset before committing.Maturity read: Apache-2.0 (no legal friction), recent releases, and indirect adoption through MadelineProto's much larger install base are the reassuring signals. The 27-star count reflects how narrow the problem is, not poor quality — but it does mean you will be largely on your own for support.
To executives: A small, permissively licensed dependency that eliminates a known class of production defects — messages rejected by Telegram for invalid entity bounds, and mangled emoji or broken formatting in customer-facing notifications. Cost is near zero, integration is a day, and it removes recurring bug-fix churn from the team. It is not a strategic bet; approve it as a standard infrastructure dependency.
To engineering: This handles the UTF-16 code-unit offset math, surrogate-pair edge cases, and entity ↔ HTML/Markdown conversion so we stop hand-rolling mb_substr index juggling. It is maintained by the MadelineProto author, so it tracks Telegram's entity list, and it is already a transitive dependency in MadelineProto-based stacks. Vendor risk is bounded: the surface area is small, the license is Apache-2.0, and worst case we fork or vendor it in an afternoon.
The one caveat to state up front: if we only ever send fixed-format messages, we do not need this — the Bot API's parse_mode covers it. Approve it on the condition that the product supports user- or template-authored rich content, or needs to edit, truncate, archive, or cross-post formatted messages.
How can I help you explore Laravel packages today?