Skip to content

feat(media): store channel media lazily and compress images - #1485

Merged
viethung0o0 merged 1 commit into
mainfrom
feat/compress-media
Oct 22, 2026
Merged

viethung0o0 merged 1 commit into
mainfrom
feat/compress-media

Conversation

@viethung0o0

@viethung0o0 viethung0o0 commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Messenger and Instagram no longer download media on every webhook. The file is fetched, compressed and stored the first time someone opens it or a flow/AI step needs it.
  • New Messenger and Instagram contacts get their profile picture the same way, on first use.
  • WhatsApp, Zalo and Telegram still store media right away, but small photos and avatars are compressed before they are written.
  • Larger photos are stored first and compressed later by a background job.
  • Photos become JPEG (max 1600px), avatars WebP (256px). Images sent as files keep their original bytes.
  • Sizes, quality and limits can be tuned with STORED_IMAGE_* env vars (see .env.example). STORED_IMAGE_OPTIMIZATION=off turns compression off. LIVE_MEDIA_LAZY_CHANNELS and LIVE_AVATAR_LAZY_CHANNELS set to "" bring back the old download-on-webhook behaviour.
  • Media deleted or revoked before anyone opens it shows the existing "unavailable" placeholder.
  • Fixes attachment updates that matched no row because of timestamp precision, so stored media now shows up on its row.
  • Existing stored media is not changed.

Deploy order

  • Run the migration on the main database (db:migrate) and on every message shard (db:migrate-shards) before starting the new code. It adds one nullable column.
  • Rolling deploy: first deploy with LIVE_MEDIA_LAZY_CHANNELS= and LIVE_AVATAR_LAZY_CHANNELS= set to empty, so old workers never handle lazy media.
  • Once every builder and worker runs the new version, remove those two vars and restart to turn lazy media on for Messenger and Instagram.
  • A full stop-and-start deploy can skip the two-step env change.

Test plan

  • pnpm lint
  • check-types for the touched apps, packages and integrations
  • Tests pass for worker, builder, business, channel-registry, database, utils, sdk, variables and the Messenger, Instagram, WhatsApp, Zalo and Telegram integrations
  • Local check: a pending photo shows in the inbox, is stored compressed on first view, and a compressed avatar shows at 256px
  • Local check: the contacts list loads every avatar
  • Manual: send a photo to a Messenger page and an Instagram account, open it in the inbox
  • Manual: send a photo on WhatsApp and check it is stored compressed

@github-actions github-actions Bot added the feature New feature or request label Oct 14, 2026
@viethung0o0
viethung0o0 force-pushed the feat/compress-media branch 4 times, most recently from 253aca9 to 163d490 Compare October 22, 2026 02:45
…orage

Messenger and Instagram media is fetched and stored the first time it is needed instead of on every webhook, and images from all channels are compressed before they are stored.
@viethung0o0
viethung0o0 marked this pull request as ready for review October 22, 2026 03:42
@viethung0o0
viethung0o0 merged commit 795a2c5 into main Oct 22, 2026
5 checks passed
hello-jackytruong referenced this pull request in hello-jackytruong/ChatWorkAI Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants