Phase 1: quick flow fixes

- One message per job: the status message is deleted once the file is
  sent, or shortened to "Sent." when Telegram keeps it.
- No reply quotes in private chats; groups keep them.
- Queue status only mentions the position when the wait is above
  QUEUE_NOTICE_THRESHOLD_SECONDS or somebody is ahead. Status edits are
  throttled to one per 2.5 s per message; a state that arrives too soon
  is shown later instead of dropped. The wait estimate is 0 with a free
  slot.
- Caption with title (uploader and date when generic), uploader,
  duration, a short source link without tracking parameters and an
  optional "via @bot" line (CAPTION_ATTRIBUTION). Uploaded videos get a
  320 px JPEG thumbnail; merged MP4s are written with faststart.
- Buttons under the result: Audio (MP3), Other quality, Thumbnail,
  Delete. Requester only in groups.
- Language resolved once per update and passed in the context. A
  fallback to English is logged as a bug; a test walks every screen in
  Spanish and Dutch. Language picker on the first /start.
- Sizes without a zero decimal ("50 MB").
- First link of a new user shows the card once and sets the default to
  "best that fits my limit".
- Errors offer the next step (Try again, Smaller quality, Upgrade, Open
  app); passing lookup failures are retried once.
- Up to MULTI_LINK_MAX links per message; a link sent a moment ago gets
  "already sent" with a Send again button.
- Mini App menu button, labelled per private chat in the user's
  language.
- Personal /settings in private chats with an "Add me to a group"
  button.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Michilis
2026-11-18 20:08:58 +00:00
co-authored by Claude Opus 5.5
parent 3c153af97f
commit 6843053582
52 changed files with 3369 additions and 271 deletions
+113
View File
@@ -867,3 +867,116 @@ telego v1.13.0, which has `SendWidget`, `EditMessageWidgetData`,
API: this environment has no bot token.
- Load test: 90 of 90 and 240 of 240 requests delivered (embedded worker;
three remote workers). Numbers in [MONITORING.md](MONITORING.md).
## Update round: flows, Stars, affiliate program
Decisions made while improving the flows and adding Telegram Stars and
the affiliate program. What was found and planned is in
[UPDATE_NOTES.md](UPDATE_NOTES.md).
### Phase 1: quick flow fixes
- **One message per job.** Once the file is in the chat, the status
message (the card, the placeholder or the status widget) is deleted.
If Telegram refuses the delete, the message is cut down to "Sent.".
`editMessageMedia` could have turned the status into the file instead,
but the file then could not quote the link message in groups, and an
upload through an edit cannot fall back to a document. Deleting is
simpler and works in every case.
- **Quotes.** Answers in private chats never quote the user's message;
groups still do. The rule sits in one place (`replyParams`) and uses
the chat ID: private chats have the user's positive ID, groups have
negative IDs.
- **Queue noise.** "Position N" is shown when the expected wait is above
`QUEUE_NOTICE_THRESHOLD_SECONDS` or somebody is queued ahead. Position
counts queued jobs ahead, as before. The wait estimate now gives 0 when
a worker slot is free, and ignores a job that was claimed between being
loaded and being measured. Before, such a job could count itself as
running and show a wait of half a job.
- **Edit throttle.** Every status message is edited at most once per
2.5 s, phase changes included. A state that arrives too soon is kept
and shown when the gap is over. It is never dropped, so the last state
before the file arrives is always correct.
- **Caption.** The caption has the title, then the uploader and duration,
then a short link without tracking parameters, then the optional
`via @bot` line. A title counts as generic when it is empty, the video
ID, the uploader's name, a site placeholder ("Video", "Instagram") or
"Video by ...". It is then replaced by "uploader · upload date" in the
reader's date format. The removed parameters are: `utm_*`, `igsh`,
`igshid`, `jplx`, `fbclid`, `gclid`, `dclid`, `gbraid`, `wbraid`,
`msclkid`, `yclid`, `twclid`, `ttclid`, `si`, `mc_cid`, `mc_eid`,
`mibextid`, `ref_src`, `ref_url`, `_hsenc`, `_hsmi`, `feature`,
`share_id` and `rdt`. On X and Twitter `s` and `t` are removed too, and
on TikTok its share parameters. Everything else stays, `v` and `t` on
YouTube included.
- **Thumbnail with the video.** Telegram only takes an uploaded JPEG of
at most 320 px and under 200 kB, never a URL. The core fetches the
source's thumbnail image (5 MB, 8 s, no private addresses, also after
DNS) and shrinks it. YouTube WebP thumbnails are swapped for their JPEG
copy; other WebP images are skipped, since the standard library cannot
read WebP. A failure only means no thumbnail: Telegram makes its own
from an MP4. The worker protocol was not changed for this.
- **faststart.** yt-dlp is given `-movflags +faststart` for its Merger
and FixupM3u8 steps, the ffmpeg runs that write MP4s. A single file
downloaded as is, without ffmpeg, keeps the layout the site served.
Transcoded profiles already had faststart.
- **Result buttons.** The buttons are Audio (MP3), Other quality,
Thumbnail and Delete. Each one is only offered when it makes sense:
there is no MP3 button under an MP3, and no thumbnail button when the
source has none. Each follow-up is a new download under the usual
limits. Callback data carries the request ID only. In groups only the
requester may press them.
- **Language.** The language is resolved once per update, before routing,
and travels in the context. The order is: the user's stored choice,
then Telegram's `language_code`, then English. A group's own language
wins inside that group. The i18n bundle now logs a text that falls
back to English like a missing message, so every app test that runs in
Spanish or Dutch fails on a fallback. `TestEveryScreenInSpanishAndDutch`
walks every user screen in both languages. It fails on any word that
only the English catalog uses, which catches hardcoded strings too.
The fake Bot API now sends each user's language with their button
presses, like Telegram does. It used to send "en" for every press.
- **Sizes.** Sizes drop a decimal that is zero ("50 MB", "1.5 GB"), in
the bot and in the Mini App, and keep the locale's decimal separator.
- **First run and quality values.** `users.default_quality` now has
three special values. "" means the user never chose, "ask" means ask
every time, and "fit" means the best quality that fits the limit.
Before, "" meant ask, so an existing user who once picked "ask every
time" sees the card one more time and then gets "fit", like a new
user. The card says so, and /quality changes it. The Mini App keeps
writing "" for "ask"; the API maps it.
- **"Best that fits my limit"** compares yt-dlp's size estimates of Best,
1080p, 720p and 480p with the user's size cap, which is capped by the
upload limit. A quality without an estimate only counts when no quality
has one; the worker's `--max-filesize` then still guards the real file.
When nothing fits, the smallest quality is started, which fails the
limit check and leads to the over-limit offer.
- **Errors.** A lookup that fails with a passing error (network, rate
limit, a lost worker) is tried once more after a second, before the
user sees anything. Timeouts are not retried, since they already took
the full probe time. Download failures keep the scheduler's existing
single retry. The error buttons are:
- Try again after a passing failure.
- Smaller quality and Upgrade after "too large".
- Upgrade after "too long" and after the daily limits.
- Open app after content errors (private, login, region, unsupported).
A failed lookup is kept as a failed request, so that "Try again" knows
the link.
- **Several links.** Up to `MULTI_LINK_MAX` links per message are
handled, each with its own status. A link counts as already sent when
the same user got a file for it in the same chat within the last 10
minutes. Links are compared without their tracking parameters. The
10 minutes are a constant, not a setting. Commands (/dl, /fresh,
/audio) never answer "already sent".
- **Menu button.** The default menu button opens the Mini App with the
source language's label. `setChatMenuButton` takes no language, so
each private chat gets its own label the first time the user writes,
and again when they change language. What was set is remembered in the
`kv` table, so a restart does not repeat the calls. The "/" button of
the message field keeps the command list.
- **Personal /settings.** It shows the default format, the audio-only and
ask-every-time switches, the language, the pass and balance, invited
friends, Open app, and "Add me to a group"
(`https://t.me/<bot>?startgroup=settings`). The bot username comes from
`getMe`.