Class: AgentsControl::Channels::Telegram::SettingsMenu

Inherits:
Object
  • Object
show all
Defined in:
lib/agents_control/channels/telegram/settings_menu.rb

Overview

The settings menu inside the bot.

Settings are needed here, not just in the CLI: they need changing exactly when the keyboard is out of reach. The token is the exception — it's set only via the CLI, because without it there's no way to talk to the bot at all.

Constant Summary collapse

TOGGLES =

What can be toggled. Order is display order.

[
  { key: "answers.away", label: "Mode",
    on: "🚶 away", off: "🪑 present", default: false },
  { key: "answers.auto_continue", label: "Auto-reply \"continue\"",
    on: "✅ on", off: "❌ off", default: true },
  { key: "answers.auto_approve_permissions", label: "Auto-approve tools",
    on: "⚠️ on", off: "❌ off", default: false },
  { key: "answers.notify_when_present", label: "Notify while present",
    on: "✅ on", off: "❌ off", default: true },
  { key: "anchors.enabled", label: "Rate-limit anchors",
    on: "✅ on", off: "❌ off", default: false }
].freeze
CHOICES =

Numeric settings: cycling through a step instead of typing text — noticeably faster on a phone.

[
  { key: "answers.reply_timeout", label: "Reply timeout",
    values: [300, 600, 900, 1800, 3600], unit: "s", default: 900 },
  { key: "terminal.context_lines", label: "Context lines",
    values: [40, 80, 200, 500], unit: "", default: 80 }
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(store:, config:) ⇒ SettingsMenu

Returns a new instance of SettingsMenu.



36
37
38
39
# File 'lib/agents_control/channels/telegram/settings_menu.rb', line 36

def initialize(store:, config:)
  @store = store
  @config = config
end

Instance Method Details

#apply(payload) ⇒ Object

Apply a press and return what changed, to show the human.



59
60
61
62
63
64
65
66
# File 'lib/agents_control/channels/telegram/settings_menu.rb', line 59

def apply(payload)
  item = find(payload["key"])
  return nil unless item

  @config.set(item[:key], next_value(item)).save

  "#{item[:label]}: #{value_label(item)}"
end

#markupObject



51
52
53
54
55
56
# File 'lib/agents_control/channels/telegram/settings_menu.rb', line 51

def markup
  rows = TOGGLES.map { |item| [toggle_button(item)] }
  rows += CHOICES.map { |item| [choice_button(item)] }

  { inline_keyboard: rows }
end

#rowsObject

List rows without a header — the console shows the same rows in a menu navigated with arrow keys.



43
44
45
# File 'lib/agents_control/channels/telegram/settings_menu.rb', line 43

def rows
  (TOGGLES + CHOICES).map { |item| "#{item[:label]}: #{value_label(item)}" }
end

#textObject



47
48
49
# File 'lib/agents_control/channels/telegram/settings_menu.rb', line 47

def text
  (["⚙️ Settings", ""] + rows + ["", warning].compact).join("\n")
end