Skip to content

feat(channels): expose what the sender wrote on Telegram messages - #399

Merged
frostming merged 1 commit into
bubbuild:mainfrom
Fengzdadi:feat/telegram-message-text
Nov 5, 2026
Merged

frostming merged 1 commit into
bubbuild:mainfrom
Fengzdadi:feat/telegram-message-text

Conversation

@Fengzdadi

Copy link
Copy Markdown
Contributor

What changed and why

The Telegram channel builds each message's content as JSON: the sender's text under message, 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_state before build_prompt frames 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.

  • ChannelMessage gets an optional text field: what the sender wrote, when content wraps it with channel metadata. None, the default, means content is that text, so other channels and existing constructors are unchanged.
  • TelegramChannel._build_message sets text to the parsed message text. That is the same string that goes under message in the JSON, so it excludes the replied-to message.
  • ChannelMessage.from_batch joins text the same way it joins content. A message without text contributes its content, and the batch's text stays None when no message has one.
  • content, the prompt, and the tape are unchanged. Commands keep returning before the JSON wrapping, without text.

Impacted modules

  • src/bub/channels/message.py
  • src/bub/channels/telegram.py
  • tests/test_channels.py

Verification

  • make check: lock check, prek (ruff, ruff format), and mypy passed.
  • uv run pytest -q: 730 passed, 20 skipped.
  • New and updated tests:
    • test_telegram_channel_build_message_wraps_payload_and_disables_outbound checks that text is the sender's text.
    • test_channel_message_batch_joins_text_and_falls_back_to_content checks batching.
  • No real Telegram bot run, since that needs a bot token.

🤖 Generated with Claude Code

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 <noreply@anthropic.com>
@frostming
frostming merged commit 7b95690 into bubbuild:main Nov 5, 2026
6 checks passed
Fengzdadi added a commit to Fengzdadi/powercontext that referenced this pull request Nov 12, 2026
Bub sets `text` to None when `content` is what the sender wrote
(bubbuild/bub#399). Fall back to `content` only then, so an empty
`text` skips recall instead of recalling the JSON envelope with its
metadata and replied-to message.
hidb4ai added a commit to oceanbase/powercontext that referenced this pull request Nov 13, 2026
* fix(bub): recall with the inbound message, not Bub's framed prompt

Bub's builtin build_prompt prefixes each channel message with its context and the time, which outweighs the user's words in lexical recall. The plugin now takes the recall text from the inbound message in load_state, before that framing, and keeps the model request unchanged.

* fix(bub): map each built prompt to its inbound text for recall

Bub drains steered follow-ups into a running turn through build_prompt
without load_state, so the per-turn recall text went stale. The plugin
now implements build_prompt at tryfirst priority, delegates to the other
implementations in Bub's resolution order, and records the inbound text
(ChannelMessage.text when set, else content) for each built prompt.
before_llm_call recalls with the text of the latest user message.

* fix(bub): match multi-part prompts and guard delegated build_prompt

The turn's message reaches the model through Bub's legacy prompt form,
which joins text parts with newlines, so record the recall text under
that form too. A plugin delegating build_prompt the same way would call
back into this one without end; return None when re-entered so the
delegation continues with the remaining implementations.

* fix(bub): skip recall for an explicitly empty sender text

Bub sets `text` to None when `content` is what the sender wrote
(bubbuild/bub#399). Fall back to `content` only then, so an empty
`text` skips recall instead of recalling the JSON envelope with its
metadata and replied-to message.

---------

Co-authored-by: hidb4ai <oceanbasememory@126.com>
100gle pushed a commit to 100gle/bub that referenced this pull request Nov 14, 2026
…bbuild#399)

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 <noreply@anthropic.com>
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