Fix duplicate-post and timeout bugs in TG/MAX posting pipeline

- Stop blindly retrying send_photo/send_video/send_media_group and MAX
  send_message on ambiguous network timeouts - a timeout doesn't prove
  the message wasn't delivered, and retrying risked posting duplicates
  (observed live: a video posted 3-5x after repeated timeout retries).
- Raise/rework timeouts that were too short for real large-file transfer
  speeds: TG media upload timeout, and yt-dlp download now uses stall
  detection (killed only on true silence) instead of a flat ceiling that
  was cutting off legitimately slow-but-successful video downloads.
- Fix sendRichMessage: ok=true with an unparseable message_id no longer
  triggers a fallback send (Telegram already created the message).
- MAX: videos over the documented 250MB cap are now sent as a "watch via
  link" note instead of silently failing the upload.
- Add PRAGMA busy_timeout to all DB connections.
- Remove unused MAX_MEDIA_CHANNEL_ID (MAX's /uploads returns a portable
  token directly, no staging channel needed, unlike Telegram).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-15 12:17:47 +05:00
parent be01558ddb
commit ec65aaf57d
9 changed files with 276 additions and 108 deletions
+6
View File
@@ -21,6 +21,9 @@ TG_CHAT_ID=-1001234567890
TG_MEDIA_CHANNEL_ID=
# Admin Telegram ID(s) for notifications & reports (single ID or comma-separated "123456,789012")
TG_ADMIN_IDS=123456789
# Timeout (seconds) for send_photo/send_video/send_media_group. Must comfortably
# cover your largest expected video at real upload speed (default 1800 = 30min).
TG_MEDIA_UPLOAD_TIMEOUT_SEC=1800
# ==========================================
# Local Telegram Bot API (Optional)
@@ -39,6 +42,9 @@ MAX_BOT_TOKEN=your_max_bot_token_here
MAX_CHAT_ID=123456
# MAX API Base URL
MAX_API_BASE_URL=https://platform-api2.max.ru
# MAX's documented hard cap for a single video attachment. Videos over this are
# sent as a "watch via link" text note instead of failing the upload.
MAX_VIDEO_LIMIT_MB=250
# ==========================================
# Polling, Reporting & Maintenance