Skip to content

Add SHUTDOWN_MODE kill switch with farewell announcement#20

Merged
ashugaev merged 2 commits into
masterfrom
goose-13b9
May 25, 2026
Merged

Add SHUTDOWN_MODE kill switch with farewell announcement#20
ashugaev merged 2 commits into
masterfrom
goose-13b9

Conversation

@AlekShu
Copy link
Copy Markdown
Collaborator

@AlekShu AlekShu commented May 25, 2026

Summary

  • New SHUTDOWN_MODE env flag flips the bot into "answer-only" mode: a single Telegraf middleware intercepts every update before session/scenes/handlers and replies with the shutdown announcement.
  • Optional SHUTDOWN_MESSAGE env var overrides the bundled default text (src/helpers/shutdownMode.ts:DEFAULT_SHUTDOWN_MESSAGE).
  • callback_query updates are acknowledged via answerCbQuery so buttons don't spin; reply errors are swallowed and logged so a bad update can't crash the bot.

How to use

Set in .env (or DigitalOcean App Platform env vars) and restart:

SHUTDOWN_MODE=true
# SHUTDOWN_MESSAGE=  # optional override; empty -> bundled default

Flip SHUTDOWN_MODE off (or unset) to restore normal operation. Cron checkers (price alerts etc.) are not gated by this flag.

Test plan

  • npm run lint passes
  • npm run build passes
  • npx jest — 72/72 green, including 13 new tests covering env parsing, override, callback_query, missing ctx.chat, and reply errors
  • Manual: set SHUTDOWN_MODE=true on a staging bot, confirm /start, plain messages and inline-button presses all receive the announcement and no other handler fires

AlekShu added 2 commits May 25, 2026 07:48
When SHUTDOWN_MODE is truthy, the first middleware intercepts every
update and replies with SHUTDOWN_MESSAGE (or the bundled default).
No command, scene or callback handler runs while it is on.
Drop the env-var message override, the TRUTHY-spelling set, the
callback_query ack and the try/catch/chat guards. The middleware
is now a single conditional reply with the bundled farewell.
@ashugaev ashugaev merged commit e0271f2 into master May 25, 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