Skip to content

fix: buffer Telegram photo-album messages into a single Claude request#188

Open
IliyaBrook wants to merge 1 commit intoRichardAtCT:mainfrom
IliyaBrook:fix/186-buffer-photo-album
Open

fix: buffer Telegram photo-album messages into a single Claude request#188
IliyaBrook wants to merge 1 commit intoRichardAtCT:mainfrom
IliyaBrook:fix/186-buffer-photo-album

Conversation

@IliyaBrook
Copy link
Copy Markdown

Follow-up to the discussion in #186@MatveyF flagged that the same
"one logical message, N responses" problem happens with images:

if I attach images to my message I get a response per image.
E.g. if I send a piece of text with 3 images it will respond 3 times —
one for the text and the first image, second for the second image,
and third for the third image

Root cause

When a user sends a Telegram album (text + N photos), Telegram delivers
it as N separate Updates that share a common message.media_group_id;
the caption lives on only one of them. The agentic photo handler fires
once per Update, so Claude is invoked N times independently instead of
seeing the album as a single message.

Fix

  • New MediaGroupBuffer (src/bot/utils/media_group_buffer.py) —
    debounces photos keyed by (user_id, chat_id, thread_id, media_group_id).
    Any photo carrying a media_group_id is buffered; a short timer
    (default 1.0s, configurable via MEDIA_GROUP_BUFFER_TIMEOUT, range
    0.3 – 5.0) fires after the last photo and flushes all photos +
    caption as a single payload.
  • agentic_photo refactored into a dispatcher: standalone photos take
    the existing fast path; album photos go through the buffer.
  • Shared work extracted to _process_photo_batch — the first photo is
    processed with the caption (so the prompt template keeps user intent),
    the rest are processed for image data only, and a single
    claude_integration.run_command is issued with all images attached.
  • The Stop button cancels any pending media-group buffers for the user.

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.

1 participant