- 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>
84 lines
4.4 KiB
Markdown
84 lines
4.4 KiB
Markdown
# 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](ASSUMPTIONS.md) under "Update round".
|
|
|
|
## What is there
|
|
|
|
- **Shape.** `cmd/core` (Telegram, DB, queue, HTTP) and `cmd/worker`
|
|
(yt-dlp, ffmpeg). The core embeds a worker by default. See
|
|
[ARCHITECTURE.md](ARCHITECTURE.md).
|
|
- **Bot front end** (`internal/bot`). `bot.go` routes updates and holds the
|
|
send and edit helpers. `commands.go` dispatches commands, `card.go` runs
|
|
the link flow (placeholder, probe, card, start), `status.go` keeps the
|
|
status message current with a throttle, `deliver.go` sends files,
|
|
`money.go` covers buying, offers and fulfilment, `groups.go` covers group
|
|
admin commands and personal preferences, `extras.go` covers playlists,
|
|
subtitles and history, `live.go` the HTML widgets, `appops.go` the Mini
|
|
App operations.
|
|
- **Language.** `actorFor` already resolves the language once per update:
|
|
the stored choice, then Telegram's `language_code`, then English. A
|
|
group's own language wins in that group. Handlers take the result as
|
|
`act.lang`. Catalogs are `locales/{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.go`
|
|
into codes with an `error.<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.Start`
|
|
and `service.Preview` are 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 credits `REFERRAL_REWARD` sats 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 into `dist/` and
|
|
embedded). Pages: Home, Queue, History, Buy, Me (`Profile.tsx`),
|
|
Groups. The API is in `internal/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 with `DLBOT_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`.
|
|
- `/settings` refuses 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
|
|
|
|
1. **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 @bot` line, 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.
|
|
2. **Command screens.** Sectioned `/help`, a reworked `/quality` with
|
|
"Best that fits my limit", and a paginated `/history` with richer rows.
|
|
3. **Own referral system.** Short random codes, rewards paid only after a
|
|
first settled Lightning purchase, and a daily cap.
|
|
4. **Telegram Stars.** A second payment method next to Lightning:
|
|
invoices in XTR, pre-checkout, successful payment, refunds, and a
|
|
per-method price table.
|
|
5. **Telegram affiliate program.** Owner docs, Mini App Stars invoices,
|
|
tolerant `/start` payload handling, and an Earn section.
|
|
6. **Inline mode and polish** (optional).
|