- Referral links carry a random 8 character base32 code (rf_<code>) built from the bot username from getMe. Old ref_<id> links still work but are never shown. - The reward (REFERRAL_REWARD_SATS, old name REFERRAL_REWARD still read) is paid through the ledger once the invited user's first purchase settles, once per invited user, never for self-referrals. - REFERRAL_DAILY_CAP limits what an inviter earns per UTC day; rewards above it wait as pending and are paid on a later day by the billing loop. - /referral shows invited, converted, earned and pending, with Share, Copy link and QR code buttons. The Mini App Me page mirrors it. - Migration 00008: users.ref_code (unique) and referral_rewards, backfilled from earlier referral credits in the ledger. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
4.4 KiB
4.4 KiB
Update notes: flows, Stars, affiliate program
What I found in the repository before changing it, and what this round of work changes. Decisions made on the way are recorded in ASSUMPTIONS.md under "Update round".
What is there
- Shape.
cmd/core(Telegram, DB, queue, HTTP) andcmd/worker(yt-dlp, ffmpeg). The core embeds a worker by default. See ARCHITECTURE.md. - Bot front end (
internal/bot).bot.goroutes updates and holds the send and edit helpers.commands.godispatches commands,card.goruns the link flow (placeholder, probe, card, start),status.gokeeps the status message current with a throttle,deliver.gosends files,money.gocovers buying, offers and fulfilment,groups.gocovers group admin commands and personal preferences,extras.gocovers playlists, subtitles and history,live.gothe HTML widgets,appops.gothe Mini App operations. - Language.
actorForalready resolves the language once per update: the stored choice, then Telegram'slanguage_code, then English. A group's own language wins in that group. Handlers take the result asact.lang. Catalogs arelocales/{en,es,nl}.toml. The catalog tests already check for missing keys, placeholders and unused messages. - Errors. yt-dlp output is classified in
internal/ytdlp/classify.gointo codes with anerror.<code>message each. A retryable job failure is retried once by the scheduler. Lookups are not retried. - Entitlement (
internal/entitle) is a pure resolver.service.Startandservice.Previeware the single gate for all paths: chat, Mini App, cache hits and resends. - Billing (
internal/billing) is Lightning only (LNbits), with a wallet and ledger per user or group, passes, credits, one-off payments, gift codes and Cashu. - Referrals store the inviter's Telegram ID from
/start ref_<id>. Billing creditsREFERRAL_REWARDsats to the inviter when an invited user settles a first purchase, inside the settlement transaction. The link shows the raw Telegram ID, and only the number of invited users is shown. There is no daily cap. - Mini App (
web/miniapp, React and Vite, built intodist/and embedded). Pages: Home, Queue, History, Buy, Me (Profile.tsx), Groups. The API is ininternal/api/miniapp.go. - Tests run the real core against a fake Bot API
(
internal/tg/fakeserver) and a scripted yt-dlp, on SQLite by default and on Postgres withDLBOT_TEST_DB=postgres.
Flow problems found
- A finished download leaves two messages: the file, and the card edited to "Done. Enjoy." under it.
- Every answer in a private chat quotes the user's message.
- A job that starts at once still shows "In the queue. Position 1".
- Phase changes skip the edit throttle, so a fast job can edit its status several times a second.
- The caption is only the title. There is no source link, and no
thumbnail is uploaded with videos. Merged MP4 files are not written
with
faststart. /settingsrefuses in a private chat.- Sizes read "50.0 MB".
- Errors are text only, with no next step.
- At most 3 links per message. The same link sent twice is downloaded twice.
- Referral links show the raw Telegram user ID.
What changes, by phase
- Quick flow fixes. One status message per job that is removed once
the file is sent. No reply quotes in private chats. Quieter queue
status and a strict 2.5 s edit throttle. A full caption with a cleaned
source link, an optional
via @botline, and a thumbnail for uploaded videos. Buttons under the result. Personal/settings. Localized menu button. Error buttons and one automatic retry of lookups. Up to N links per message, with "Already sent" for repeats. First-run quality prompt. A strict language test. - Command screens. Sectioned
/help, a reworked/qualitywith "Best that fits my limit", and a paginated/historywith richer rows. - Own referral system. Short random codes, rewards paid only after a first settled Lightning purchase, and a daily cap.
- Telegram Stars. A second payment method next to Lightning: invoices in XTR, pre-checkout, successful payment, refunds, and a per-method price table.
- Telegram affiliate program. Owner docs, Mini App Stars invoices,
tolerant
/startpayload handling, and an Earn section. - Inline mode and polish (optional).