Skip to content

Conversation

@konard
Copy link
Contributor

@konard konard commented Jan 11, 2026

Summary

Add /stop and /start commands for the Telegram bot that allow chat owners to control whether the bot accepts new tasks in their chat.

Key features:

  • /stop command puts the bot in read-only mode for the chat (owner only)
  • /stop <reason> - Optional reason text that will be shown in rejection messages
  • /start command resumes accepting tasks (owner only)
  • Only the chat creator can use these commands (not admins)
  • When stopped: /solve and /hive are rejected with a clear message (including reason if provided)
  • Read-only commands (/help, /limits, /version) remain available
  • Existing queue items continue to process (graceful stop)
  • State is per-chat and resets on bot restart

Implementation Details

  1. New module: src/telegram-start-stop-command.lib.mjs

    • Per-chat stop state management using Map<chatId, StopInfo>
    • StopInfo includes: stoppedAt, stoppedBy, and optional reason
    • Exports: isChatStopped(), setChatStopped(), getChatStopInfo(), getStoppedChats()
    • Owner-only access control following the pattern from /top command
  2. Changes to telegram-bot.mjs:

    • Import and use isChatStopped check in /solve and /hive handlers
    • Register /start and /stop commands from the new module
    • Update /help to show stopped status (with reason) and document new commands
    • Update rejection messages to include reason if provided
  3. Test script: experiments/test-start-stop-command.mjs

    • Tests all state management functions
    • Tests for reason support (tests 10-13)

Test Plan

  • Unit tests pass (npm run test)
  • New module tests pass (node experiments/test-start-stop-command.mjs)
  • Linting passes (npm run lint)
  • Formatting passes (npm run format:check)
  • Manual testing in Telegram group:
    • Only chat creator can use /stop
    • /stop Maintenance shows reason in confirmation
    • /solve and /hive rejected when stopped (with reason displayed)
    • /help shows stopped status with reason
    • Only chat creator can use /start
    • Commands work again after /start

Fixes #1081


🤖 Generated with Claude Code

Adding CLAUDE.md with task information for AI processing.
This file will be removed when the task is complete.

Issue: #1081
@konard konard self-assigned this Jan 11, 2026
konard and others added 4 commits January 11, 2026 05:29
Create telegram-start-stop-command.lib.mjs module with:
- Per-chat stop state management using Map
- isChatStopped() and setChatStopped() for state control
- getChatStopInfo() and getStoppedChats() for status queries
- Owner-only access control (creator, not admins)
- Graceful stop: existing queue items continue to process

This is the core module for issue #1081.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Changes to telegram-bot.mjs:
- Import isChatStopped and getChatStopInfo from new module
- Add stop check to /solve command (rejects if chat stopped)
- Add stop check to /hive command (rejects if chat stopped)
- Register start/stop commands from new module
- Update /help to show stopped status when applicable
- Add /stop and /start to help command list

Fixes #1081

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add test-start-stop-command.mjs to experiments folder with tests for:
- Initial state (no chats stopped)
- Stopping a chat
- Getting stop info
- Per-chat isolation
- Getting all stopped chats
- Starting (un-stopping) a chat
- Multiple chats can be stopped independently

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@konard konard changed the title [WIP] /stop command feat: Add /stop and /start commands for telegram bot (Issue #1081) Jan 11, 2026
@konard konard marked this pull request as ready for review January 11, 2026 04:30
konard and others added 3 commits January 11, 2026 05:33
- Format telegram-start-stop-command.lib.mjs with prettier
- Compact command registration in telegram-bot.mjs to stay under 1500 lines
- telegram-bot.mjs now at 1487 lines (was 1502)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@konard
Copy link
Contributor Author

konard commented Jan 11, 2026

⚠️ Solution Draft Finished with Errors

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Public pricing estimate: $7.231747 USD
  • Calculated by Anthropic: $0.000000 USD
  • Difference: $-7.231747 (-100.00%)

Note: The session encountered errors during execution, but some work may have been completed. Please review the changes carefully.

📎 Log file uploaded as Gist (1505KB)
🔗 View complete solution draft log

Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard
Copy link
Contributor Author

konard commented Jan 19, 2026

Resolve conflicts, and add optional reason support for /stop command (any text after the command /stop ). So all other write commands will show this reason, if it is provided.

@konard konard marked this pull request as draft January 19, 2026 22:17
@konard
Copy link
Contributor Author

konard commented Jan 19, 2026

🤖 AI Work Session Started

Starting automated work session at 2026-01-19T22:17:36.170Z

The PR has been converted to draft mode while work is in progress.

This comment marks the beginning of an AI work session. Please wait working session to finish, and provide your feedback.

konard and others added 2 commits January 19, 2026 23:21
- Add reason parameter to setChatStopped() function
- Parse reason text from /stop command (text after "/stop ")
- Display reason in /solve and /hive rejection messages
- Display reason in /help stopped status section
- Display reason when /stop is called on already-stopped chat
- Add tests for reason functionality (tests 10-13)

Resolves conflict with main branch by merging accept_invites command.

Fixes #1081

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…count

- Add getStoppedChatRejectMessage() helper to start-stop module
- Use helper in /solve and /hive handlers to reduce code duplication
- Simplify verbose logging with VERBOSE && console.log() pattern
- Reduce telegram-bot.mjs from 1534 to 1488 lines (under 1500 limit)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@konard
Copy link
Contributor Author

konard commented Jan 19, 2026

✅ Resolved

I've addressed all the feedback from the latest comments:

Merge conflicts resolved

Optional reason support for /stop command

  • /stop now accepts an optional reason: /stop Maintenance in progress
  • The reason is stored in the stop info and displayed in:
    • /stop confirmation message
    • /solve and /hive rejection messages when the bot is stopped
    • /help stopped status section
    • "Already stopped" message when /stop is called again

Code quality

  • Extracted getStoppedChatRejectMessage() helper to reduce code duplication
  • Reduced telegram-bot.mjs from 1534 to 1488 lines (under the 1500 limit)
  • All local tests pass (npm run test + experiments/test-start-stop-command.mjs)
  • All CI checks are passing

Example usage

/stop                           → Stops bot with no reason
/stop Maintenance in progress   → Stops bot with reason "Maintenance in progress"

When stopped with a reason, rejection messages will show:

❌ This bot is currently stopped in this chat and not accepting new tasks.

*Reason:* Maintenance in progress

Use /start to resume (chat owner only).

🤖 Generated with Claude Code

@konard konard marked this pull request as ready for review January 19, 2026 22:31
@konard
Copy link
Contributor Author

konard commented Jan 19, 2026

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Public pricing estimate: $7.365753 USD
  • Calculated by Anthropic: $5.103654 USD
  • Difference: $-2.262099 (-30.71%)
    📎 Log file uploaded as Gist (1390KB)
    🔗 View complete solution draft log

Now working session is ended, feel free to review and add any feedback on the solution draft.

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.

/stop command

2 participants