Repository navigation
feat(channels): expose what the sender wrote on Telegram messages - #399
Merged
Merged
Conversation
The Telegram channel wraps the sender's text in JSON with sender and message metadata before it reaches hooks, so a hook that searches or indexes messages can only get the text back by parsing that JSON. ChannelMessage now carries the text in an optional `text` field, which batching joins like the content. The model-facing content is unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed and why
The Telegram channel builds each message's
contentas JSON: the sender's text undermessage, next to sender and message metadata (message_id,username,sender_id,date,reply_to_message, ...). That is what the model should see, but a hook that searches or indexes messages also gets only that JSON. To recover what the user wrote, it has to parse the JSON back out.PowerContext's Bub plugin hit this case. It recalls memory with the inbound message's text, read in
load_statebeforebuild_promptframes it. For Telegram, the JSON metadata outweighs the user's words in lexical recall. In the review of oceanbase/powercontext#2488, @PsiACE suggested exposing the searchable text before JSON wrapping instead of parsing it.ChannelMessagegets an optionaltextfield: what the sender wrote, whencontentwraps it with channel metadata.None, the default, meanscontentis that text, so other channels and existing constructors are unchanged.TelegramChannel._build_messagesetstextto the parsed message text. That is the same string that goes undermessagein the JSON, so it excludes the replied-to message.ChannelMessage.from_batchjoinstextthe same way it joinscontent. A message withouttextcontributes itscontent, and the batch'stextstaysNonewhen no message has one.content, the prompt, and the tape are unchanged. Commands keep returning before the JSON wrapping, withouttext.Impacted modules
src/bub/channels/message.pysrc/bub/channels/telegram.pytests/test_channels.pyVerification
make check: lock check, prek (ruff, ruff format), and mypy passed.uv run pytest -q: 730 passed, 20 skipped.test_telegram_channel_build_message_wraps_payload_and_disables_outboundchecks thattextis the sender's text.test_channel_message_batch_joins_text_and_falls_back_to_contentchecks batching.🤖 Generated with Claude Code