Skip to content

Escape chat text for Telegram HTML in operator topics - #104

Merged
remdex merged 1 commit into
LiveHelperChat:masterfrom
mysubcult:fix/escape-topic-html
Oct 26, 2026
Merged

remdex merged 1 commit into
LiveHelperChat:masterfrom
mysubcult:fix/escape-topic-html

Conversation

@mysubcult

Copy link
Copy Markdown
Contributor

Chat messages, the visitor nick and the bot name are stored raw in LHC. The operator-topic messages send them with parse_mode: HTML after make_clickable(), which does not escape anything.

If a visitor writes a < b, <something> or x & y, or has a nick containing < or &, Telegram rejects the whole message with Bad Request: can't parse entities, and the message never reaches the topic. The same happens when the chat card is posted, since it lists the earlier messages.

This PR adds escapeHtml() (htmlspecialchars, ENT_NOQUOTES). It is applied to the message text, nick and bot name before make_clickable() in the visitor-message, bot-message, trigger-click and chat-started paths. Links still become clickable: make_clickable() handles escaped text, and Telegram decodes &amp; inside href. The bot italics are unchanged.

Checked against a real forum topic: a < b & c > d, <b>not bold</b>, and a URL with ?a=1&b=2 arrive as plain text, and Telegram detects the URL entity over its full length.

🤖 Generated with Claude Code

Messages, nick and bot name are stored raw and sent with parse_mode HTML. A visitor
writing «a < b» or a nick with < or & made Telegram reject the message («can't parse
entities»), so it never reached the topic. They are escaped before links are made
clickable; quotes, links and the bot italics keep working.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@remdex
remdex merged commit 31a2560 into LiveHelperChat:master Oct 26, 2026
mysubcult added a commit to mysubcult/telegram that referenced this pull request Oct 26, 2026
…perChat#98, LiveHelperChat#100, LiveHelperChat#101, LiveHelperChat#104 accepted upstream; fork already had them)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mysubcult
mysubcult deleted the fix/escape-topic-html branch October 26, 2026 17:45
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.

2 participants