fix(telegram): include the replied-to / quoted message in the prompt - #252
Conversation
When a user replied to or quoted a message, handleMessage() only read the
replied message's id and sender, never its content, and ignored Telegram's
quote field entirely. The prompt handed to Claude contained only the user's
new message, so the quoted context was silently dropped — Claude never saw
what the user was replying to.
Capture reply_to_message.text/caption and quote.text (the highlighted
excerpt for partial quotes), and prepend them to the prompt as untrusted
context ("In reply to your own earlier message: ..." / "a message from
<name>: ..."), capped at 2000 chars like other external input. The
TelegramMessage type is extended accordingly.
tsc --noEmit clean.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
TerrysPOV
left a comment
There was a problem hiding this comment.
Clean, well-scoped fix. Including the replied-to / quoted message gives Claude the context it was missing, and — importantly — the quoted content is correctly fenced with wrapUntrusted("replied-message", …), so an untrusted reply body can't smuggle instructions into the prompt. Verified botId is in scope (module-level, set from getMe), the text/caption fallback and the partial-quote.text case are handled, and it merges clean against master.
Maintainer-committed the version housekeeping in a9a8066: the branch had bumped to 1.0.43, which equals current master, so the version guard would fail (base == head). I merged current master in and re-bumped to 1.0.44. Please run bun run bump:plugin-version + bump:marketplace-version yourself and target one past master for future PRs.
Approving.
Problem
When a user replies to or quotes a message in Telegram, Claude never sees the quoted content — it responds as if the reply context didn't exist.
The Telegram API delivers the original message in
reply_to_message(and, for partial highlights, a top-levelquotefield). ButhandleMessage()only captured the id and sender:…and the prompt builder only ever added the user's new message:
So the replied-to/quoted text was silently dropped before Claude ever ran.
Fix
TelegramMessagetype to includereply_to_message.text/.captionand aquote.textfield.quote.text(the highlighted excerpt when a user quotes only part of a message) takes precedence over the fullreply_to_messagebody; thefrom-vs-bot check makes the phrasing natural in both DMs (replying to the bot) and groups (quoting another user).Behavior
Testing
bunx tsc --noEmitclean.bun test: only the pre-existingsessionFiles/sessionsPOSIX-path tests fail on a Windows dev box — unrelated to this change.Notes
Independent of #250 (queue-on-busy) and #251 (argv-limit); any merge order works. Version bumped to
1.0.43to avoid clashing with those PRs — happy to renumber/rebase if you'd prefer.