Skip to content

User notifications, step 2: the people's bot - #97

Merged
limeflash merged 4 commits into
mainfrom
feat/user-notify-bot
Dec 3, 2026
Merged

limeflash merged 4 commits into
mainfrom
feat/user-notify-bot

Conversation

@limeflash

Copy link
Copy Markdown
Collaborator

Step 2 of user notifications (spec §13, §15): the people's Telegram bot.

  • Own proto package mistgate.usernotify.v1 (UserNotifyService), served by the admin Worker only.
  • Owner (with step-up): set/clear the bot, the chat limit. Owner and helper: link codes, unlink, mute.
  • Linking: one-time code (128 bits, hash stored, TTL), /start <code>; /stop, /mute toggles, /unmute hidden synonym. Other chats of the person are told about a new link.
  • Chat ids are sealed (AAD by chat MAC); a 403 forgets the chat. The owner's bot refuses the people's bot token.
  • VPS: constant long poll. Edge: polls only while a code is pending, under a lease.
  • Texts in en/ru/zh/tr/fa (tr/fa need a native review).

Checks: go vet and tests (telegram, auth, app, store, backup, vendorcheck), check-edge-sizes.sh (admin headroom 2135 KiB, sum 1641 KiB), test-edge-store.ps1.

🤖 Generated with Claude Code

limeflash and others added 4 commits December 3, 2026 18:13
…f the people needs

UserTelegramStats (people with a chat, chats, last delivery) for the card of the bot, UserTelegramCodeExpiry and
DeleteUserTelegramCode for the "waiting for the link" state and for withdrawing a code, UserExists to tell a missing person
from a person with no chats.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…inking, commands)

The second Telegram bot of the panel (spec notifications-panel-spec, PR 2): the owner sets it, a person links a chat with a
one-time code, and the chat can stop or mute itself. No sender, no triggers, no UI yet.

API (TelegramService, so the admin Worker takes no new service):
- GetUserBot (state of the card, counts, last delivery, chat limit), SetUserBot and ClearUserBot (owner, step-up; the token
  goes sealed to the vault and never comes back; a bot the owner already uses is refused: user_bot_same_as_owner, and the
  owner's SetTelegramBot refuses the people's bot the same way).
- BeginUserTelegramLink / CancelUserTelegramLink (owner or helper): 128-bit code, only its hash stored, 15 minutes, one per
  person, answered as a t.me link.
- ListUserTelegramChats, UnlinkUserTelegramChat, SetUserTelegramChatMuted by chat row id: no Telegram chat id leaves the panel.
- SetUserTelegramChatLimit (owner): the limit of everybody (default 3, 1 to 10) or of one person, keys telegram_chat_limit.

Receiving: its own offset in user_telegram_bot. The VPS long polls for ever; the edge polls only while a link code of a person
waits (HasPendingUserTelegramCode) and under the lease user-telegram-poll, after the poll of the owner's bot in EdgeTick. The
state of a failed poll is a code on the bot row (unauthorized, unreachable, conflict, same_as_owner), never Telegram's text.

Commands: /start <code> links the chat (language from Telegram, else the panel's; five languages ru, en, zh, tr, fa), greets, tells
the person's other chats and audits it; a bad code, a chat of another person and a full person each get a short reason.
/stop unlinks, /mute switches the announcements, /unmute (hidden) only switches them on. An unlinked chat gets no answer, a group
none, an admin's chat nothing. A 403 or "chat not found" on any answer unlinks the chat.

The sealed chat id is bound to its chat MAC (the row id is born inside the store insert); the restore check of the sealed
columns learns the bot token and the chat id, and its golden test links a chat through the real path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The people's bot added a second D1 read to every minute tick, and the cron test counts those. PendingTelegramLinkCodes asks in one
query whether an admin's or a person's code waits, and PollPendingLinkCodes polls only the bot that has one, each within its own
40 s; the tick makes one call to it. PollPendingLinkCode and PollPendingUserLink keep their own check for a caller on its own.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…admin Worker only

The calls of the bot of the people and a person's chats move out of adminv1.TelegramService into
mistgate.usernotify.v1.UserNotifyService (11 messages instead of 24). Only the roles that serve the admin
API link it: app.Config.UserNotifyAPI takes usernotifyrpc.Handler, as ProposalAPI takes proposalrpc, and
Build and BuildAdmin refuse a Config without it. The public, link, jobs and provision Workers no longer
carry its generated code and descriptors (go list -deps shows none of it there).

telegram.Service keeps the work as proto-free methods (user_admin.go) and checks who may call; the new
usernotifyrpc package only maps them to messages. Procedures are named by path in
auth/policy_usernotify.go, pinned to the generated names by a test; the hardening test walks the new
package too. The backup golden test and the role tests use the new service.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@limeflash
limeflash merged commit d232d9f into main Dec 3, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant