feat(telegram): bot support relay — per-user forum topics #130

Merged
developer merged 1 commits from feature/telegram-support-relay into development 2026-06-23 16:08:19 +00:00
Owner

What

Bot-local Telegram support relay: a user who DMs the bot anything but /start is relayed into a private forum supergroup as a per-user topic; the chat's admins reply in the topic and the bot copies it back to the user. Each topic opens with an info card (name, @username, language, premium, id, profile link) carrying Block/Unblock + Clear buttons.

Separate from the in-app Feedback (ARCHITECTURE §15) — no backend, no bot-link, no feedback_messages.

How

  • internal/support: concurrency-safe JSON store (topic map, block list, relayed ids), atomic save; field-targeted mutators so a topic recreate can't clobber a concurrent block.
  • bot/support.go: relay via copyMessage both ways; short-TTL admin cache; callback buttons; per-user topic-create lock; loop guard (skip the bot's own posts + IsBot); reopen a deleted topic on the next message.
  • Config/infra: TELEGRAM_SUPPORT_CHAT_ID (per contour) + TELEGRAM_SUPPORT_STATE_DIR=/data; bot-state named volume on both compose files; /data pre-owned by UID 65532 so a fresh volume is writable under distroless nonroot.
  • Docs: ARCHITECTURE §15 + decision record, FUNCTIONAL (+ru), telegram README.

Safety / rollout

Off by default (TELEGRAM_SUPPORT_CHAT_ID=0) — deploying this changes nothing until activated. The only always-on change is the /data volume.

Activation (owner)

  1. Create a forum supergroup (Topics enabled); add the bot as admin with Manage topics + Delete messages.
  2. Set the Gitea variable TEST_TELEGRAM_SUPPORT_CHAT_ID (later PROD_TELEGRAM_SUPPORT_CHAT_ID) to that group's chat id.
  3. The contour redeploy on this PR picks up the TEST value automatically.

Tests

go test -race ./platform/telegram/... green (store + relay on an httptest fake Bot API: first-contact topic+card, topic reuse, block-drop, operator reply, loop guard, non-admin denial, clear, parse, escaping). gofmt/vet clean. Both compose files config-validate; the bot image builds and /data is 65532:65532.

## What Bot-local Telegram **support relay**: a user who DMs the bot anything but `/start` is relayed into a private **forum supergroup** as a **per-user topic**; the chat's **admins** reply in the topic and the bot copies it back to the user. Each topic opens with an info card (name, @username, language, premium, id, profile link) carrying **Block/Unblock** + **Clear** buttons. Separate from the in-app Feedback (ARCHITECTURE §15) — no backend, no bot-link, no `feedback_messages`. ## How - `internal/support`: concurrency-safe JSON store (topic map, block list, relayed ids), atomic save; **field-targeted mutators** so a topic recreate can't clobber a concurrent block. - `bot/support.go`: relay via `copyMessage` both ways; short-TTL admin cache; callback buttons; per-user topic-create lock; **loop guard** (skip the bot's own posts + `IsBot`); reopen a deleted topic on the next message. - Config/infra: `TELEGRAM_SUPPORT_CHAT_ID` (per contour) + `TELEGRAM_SUPPORT_STATE_DIR=/data`; `bot-state` named volume on both compose files; `/data` pre-owned by UID 65532 so a fresh volume is writable under distroless nonroot. - Docs: ARCHITECTURE §15 + decision record, FUNCTIONAL (+ru), telegram README. ## Safety / rollout **Off by default** (`TELEGRAM_SUPPORT_CHAT_ID=0`) — deploying this changes nothing until activated. The only always-on change is the `/data` volume. ## Activation (owner) 1. Create a **forum** supergroup (Topics enabled); add the bot as **admin** with *Manage topics* + *Delete messages*. 2. Set the Gitea variable `TEST_TELEGRAM_SUPPORT_CHAT_ID` (later `PROD_TELEGRAM_SUPPORT_CHAT_ID`) to that group's chat id. 3. The contour redeploy on this PR picks up the TEST value automatically. ## Tests `go test -race ./platform/telegram/...` green (store + relay on an httptest fake Bot API: first-contact topic+card, topic reuse, block-drop, operator reply, loop guard, non-admin denial, clear, parse, escaping). gofmt/vet clean. Both compose files `config`-validate; the bot image builds and `/data` is `65532:65532`.
developer added 1 commit 2026-06-23 15:47:38 +00:00
feat(telegram): bot support relay — per-user forum topics
CI / changes (pull_request) Successful in 2s
CI / unit (pull_request) Successful in 12s
CI / integration (pull_request) Successful in 16s
CI / ui (pull_request) Successful in 56s
CI / gate (pull_request) Successful in 0s
CI / deploy (pull_request) Successful in 1m20s
6a602aefae
Users who DM the bot anything but /start are relayed into a private
forum supergroup, one topic per user. Operators (the chat's admins)
reply in the topic and the bot copies it back to the user; an info card
opening each topic carries a Block/Unblock toggle and a Clear button.
State is a small JSON file on a new /data volume — the bot host has no
database. Off by default (TELEGRAM_SUPPORT_CHAT_ID=0): the prod bot is
unchanged until the operator sets the chat id and adds the bot as a
forum admin.

- internal/support: concurrency-safe JSON store (topic map, block list,
  relayed message ids) with field-targeted mutators and atomic save
- bot/support.go: relay both ways via copyMessage, short-TTL admin
  cache, callback buttons, per-user topic-create lock, loop guard
  (skip the bot's own posts), reopen a deleted topic on the next message
- config + compose + CI/prod-deploy: TELEGRAM_SUPPORT_CHAT_ID per
  contour + TELEGRAM_SUPPORT_STATE_DIR; bot-state named volume; /data
  pre-owned by UID 65532 so a fresh volume is writable under distroless
- docs: ARCHITECTURE §15 + decision record, FUNCTIONAL (+ru), README
owner approved these changes 2026-06-23 15:58:03 +00:00
developer merged commit d86e022373 into development 2026-06-23 16:08:19 +00:00
developer deleted branch feature/telegram-support-relay 2026-06-23 16:08:19 +00:00
Sign in to join this conversation.
No Reviewers
No Label
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: developer/scrabble-game#130