Skip to content

feat(channels): implement channels.toggle RPC method#1142

Open
zhihan wants to merge 1 commit into
nextlevelbuilder:devfrom
zhihan:feat/channels-toggle
Open

feat(channels): implement channels.toggle RPC method#1142
zhihan wants to merge 1 commit into
nextlevelbuilder:devfrom
zhihan:feat/channels-toggle

Conversation

@zhihan
Copy link
Copy Markdown

@zhihan zhihan commented May 11, 2026

Summary

Implements the WebSocket RPC method that allows operators to enable/disable messaging channels at runtime without restarting the server.

Changes

Channel Manager ()

  • Added method to start a specific channel
  • Added method to stop a specific channel
  • Added method to check channel status
  • All methods are thread-safe using existing mutex protection
  • Health status tracking and structured logging

RPC Handler ()

  • Implemented method (previously returned 'not implemented' error)
  • Parses JSON parameters: (string) and (boolean)
  • Validates input and checks if channel exists
  • Returns idempotent responses:
      • Channel successfully toggled
      • Channel already enabled
      • Channel already disabled

API

Request:

{
  "type": "req",
  "id": "1",
  "method": "channels.toggle",
  "params": {
    "channel": "telegram",
    "enabled": false
  }
}

Response:

{
  "type": "res",
  "id": "1",
  "result": {
    "channel": "telegram",
    "enabled": false,
    "status": "ok"
  }
}

Use Cases

  1. Maintenance: Disable channels before external service maintenance
  2. Debugging: Temporarily disable problematic channels without affecting others
  3. Incident response: Quickly stop a misbehaving channel
  4. Testing: Enable/disable channels in development without config changes
  5. Load management: Disable non-critical channels during high load

Testing

  • ✅ Builds successfully ()
  • ✅ Channels package compiles
  • ✅ Gateway methods package compiles
  • ✅ Main package compiles

Notes

  • The implementation follows existing code patterns in the codebase
  • Thread-safe with proper mutex usage
  • Integrates with existing health tracking system
  • Structured logging for all operations
  • Idempotent - safe to call multiple times

Fixes the stub implementation that previously returned 'channels.toggle not implemented' error.

Implement runtime channel enable/disable via WebSocket API.

Changes:
- Add StartChannel(), StopChannel(), IsChannelRunning() methods to Manager
- Implement handleToggle RPC handler in channels.go
- Support idempotent operations (already_running/already_stopped status)
- Thread-safe with existing mutex protection
- Health status tracking and structured logging

The channels.toggle method allows operators to enable or disable
messaging channels (telegram, discord, etc.) at runtime without
restarting the server. Useful for maintenance, debugging, and
incident response.

API:
  Request: {method: channels.toggle, params: {channel: telegram, enabled: false}}
  Response: {channel: telegram, enabled: false, status: ok}

Fixes the stub implementation that returned 'not implemented' error.
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