← Back to library

Telegram 相册容错:单图下载失败不再整组丢弃

问题/场景:Telegram 媒体组中一张图抓取失败会导致整组消息静默丢失。前置条件:启用 Telegram 且处理媒体组消息。实施步骤:逐媒体项 try/catch 隔离错误 → 失败仅告警并继续 → 最终仍调用 processMessage 交付可用媒体或仅标题。关键命令:npm run build。验证:构造单图失败场景时其余图片和 caption 仍可到达代理链路。风险:大量失败会降低内容完整性,需要告警监控。来源:PR #20598 + Issue #20515。

GITHUBDiscovered 2026-02-19Author mcaxtr
Prerequisites
  • Telegram channel is enabled and bot receives media-group messages.
  • Codebase/custom plugin can be modified and tested with failing media fetch simulation.
Steps
  1. Wrap each media fetch in per-item try/catch instead of one outer catch around the whole loop.
  2. On single-item failure, log warning and continue processing remaining media entries.
  3. Always call downstream message processing even when media array is partially empty or fully empty with caption.
  4. Add regression test: one media item fails, others still pass through.
Commands
npm run build
Verify

In a forced partial-download-failure test, bot still processes remaining photos and caption instead of dropping the whole group.

Caveats
  • If all media downloads fail, resulting payload may contain caption-only context; prompt logic should handle this.
  • High failure rate usually indicates network/storage bottlenecks and should trigger ops alerting.
Source attribution

This tip is aggregated from community/public sources and preserved with attribution.

Open original source ↗
Visit original post