Skip to content

Add /broadcast command for admin mass messaging#17

Merged
ashugaev merged 3 commits into
masterfrom
goose-b2ee
May 18, 2026
Merged

Add /broadcast command for admin mass messaging#17
ashugaev merged 3 commits into
masterfrom
goose-b2ee

Conversation

@AlekShu
Copy link
Copy Markdown
Collaborator

@AlekShu AlekShu commented May 18, 2026

Summary

  • Boss-only /broadcast command — sends a message to all bot users
  • 3-step wizard: send message → confirm user count → execute broadcast
  • Per-user try/catch so a single blocked user never aborts the run
  • 50ms delay between sends to respect Telegram rate limits
  • Delivery report with count, percentage, and failed user list

Files

  • src/commands/broadcast/ — command, scenes, utils, constants
  • src/app.ts — register command + scene
  • locales/ru.yaml, locales/en.yaml — i18n keys
  • 10 Jest unit tests for broadcast execution logic

Test plan

  • npm run build passes
  • All 52 tests pass (npx jest)
  • New broadcast tests cover: success, empty list, partial failure, all failures, non-Error throws, rate-limit delay, report formatting, truncation
  • Manual: send /broadcast as BOSS_TG_ID, verify wizard flow and delivery report

AlekShu added 3 commits May 18, 2026 09:36
Boss-only wizard: capture any message type, confirm user count, then
copy to every user via copyMessage with per-user try/catch, 50ms
rate-limit delay, and a final delivery report (count + percentage +
failed user list).
- Add "Test (only me)" button — sends to boss only, stays on same
  step so you can test repeatedly before confirming
- Deduplicate user IDs before broadcast (User.id is not unique in DB)
- Escape HTML in error messages to avoid breaking Telegram's parser
- Wrap final report send in try/catch so a Telegram hiccup doesn't
  lose the scene
- Use editMessageText instead of new messages — cleaner UX, removes
  stale inline keyboards
- answerCbQuery on every button press to dismiss Telegram spinner
- Store userCount in wizard state to avoid re-querying on test sends
- Add state.broadcastRunning lock — second click on "Send to all"
  returns early with a toast instead of starting a duplicate broadcast
- Refactor executeBroadcast to accept options object (delayMs,
  onProgress) instead of positional delayMs arg
- Add onProgress callback — scene sends ~4 progress messages during
  long broadcasts (adaptive interval: max(100, total/4))
- onProgress errors are silently swallowed to never abort the run
@ashugaev ashugaev merged commit 57f8ef8 into master May 18, 2026
3 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.

2 participants