Skip to content

fix(telegram): preserve PNG attachments via document delivery - #1

Open
sasoder wants to merge 1 commit into
mainfrom
fix/telegram-preserve-png-delivery
Open

fix(telegram): preserve PNG attachments via document delivery#1
sasoder wants to merge 1 commit into
mainfrom
fix/telegram-preserve-png-delivery

Conversation

@sasoder

@sasoder sasoder commented Apr 2, 2026

Copy link
Copy Markdown
Owner

What does this PR do?

Fixes Telegram delivery for local PNG files emitted by gateway responses.

Found this bug while working with image/game assets. I wanted Hermes to send back a png so I could inspect it, but Telegram delivered it through the photo path and it came back as a jpeg instead of the original png file, which compresses the image and loses the transparency I was trying to verify.

I looked for a cleaner Telegram-side way to fix this, but I don't think there is one. The Bot API has sendPhoto() for photos and sendDocument() for the original file.

The rest of the behavior stays the same. Other platforms keep using the normal image path, and Telegram still sends non-png local images as photos. The png preservation now lives inside Telegram's send_image_file() implementation instead of adding a new base-adapter hook for one platform-specific behavior.

Related Issue

I did not find an exact issue for this specific png preservation problem.

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 🔒 Security fix
  • 📝 Documentation update
  • ✅ Tests (adding or improving test coverage)
  • ♻️ Refactor (no behavior change)
  • 🎯 New skill (bundled or hub)

Changes Made

  • Updated TelegramAdapter.send_image_file() so local .png files are sent through send_document() and keep the original file.
  • Kept non-png local images on Telegram's normal send_photo() path.
  • Left the shared gateway media routing generic: image files still call send_image_file(), and Telegram decides the exact Telegram delivery method internally.
  • Updated the existing Telegram send_image_file() tests so the photo-path tests use .jpg fixtures instead of .png fixtures.
  • Added tests for the direct png document path and for pngs delivered from normal and streaming gateway responses.
  • Replaced one Telegram document fallback print() with logger.error(..., exc_info=True) while touching the same delivery code.

How to Test

  1. Run the Telegram gateway with this patch
  2. Trigger a response containing MEDIA:/absolute/path/to/file.png
  3. Confirm Telegram receives it as a png document/file and not as a photo
  4. Trigger a response containing a non-png image, such as .jpg, and confirm it still uses the normal photo/image delivery path

Verification

  • source .venv/bin/activate && python -m pytest tests/gateway/test_send_image_file.py tests/gateway/test_telegram_documents.py -q
  • Result: 57 passed, 12 warnings
  • git diff --check
  • Result: passed

I tried the full test suite, but it fails locally outside this PR due to missing optional ACP/Matrix deps and an unrelated gateway race-guard timeout.

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature
  • I've run pytest tests/ -q and all tests pass
  • I've added tests for my changes
  • I've tested on my platform: macOS / Telegram gateway path via unit tests

Documentation & Housekeeping

  • Documentation update is N/A
  • cli-config.yaml.example update is N/A
  • CONTRIBUTING.md / AGENTS.md update is N/A
  • Cross-platform impact considered: this only changes Telegram's local image delivery choice for .png files
  • Tool schema/description update is N/A

Screenshots / Logs

No screenshots or logs.

@sasoder
sasoder force-pushed the fix/telegram-preserve-png-delivery branch 2 times, most recently from ad5ba79 to 4e96efc Compare April 6, 2026 12:03
@sasoder
sasoder force-pushed the fix/telegram-preserve-png-delivery branch from c5deea7 to fd5a21e Compare April 6, 2026 13:49
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