Class: AgentsControl::Channels::Telegram::Router
- Inherits:
-
Object
- Object
- AgentsControl::Channels::Telegram::Router
- Defined in:
- lib/agents_control/channels/telegram/router.rb
Overview
Parses incoming updates and runs commands.
The sender check runs first, before anything else is parsed. An empty allowed-chats list means "answer nobody".
Constant Summary collapse
- MAX_MESSAGE =
Chunker::MAX_MESSAGE
- REMOTE_COMMANDS =
Commands in these tabs go to a remote server, not the laptop — they get a separate confirmation.
%w[ssh mosh].freeze
- COMMANDS =
Shared list for the Telegram menu and for /help: a menu that's drifted from reality is worse than no menu. The third element is the argument syntax, needed only in /help; setMyCommands doesn't show the argument.
[ ["agents", "sessions with a live agent"], ["tabs", "all terminal tabs"], ["status", "what's happening right now"], ["away", "intercept agent questions"], ["settings", "settings"], ["context", "the agent's recent messages", "N"], ["screen", "show a tab's screen", "N"], ["focus", "switch to a tab", "N"], ["run", "run a command in a tab", "N command"], ["new", "new tab", "[directory]"], ["help", "this help text"] ].freeze
- HELP =
(["Commands:", ""] + COMMANDS.map { |name, text, hint| "/#{name}#{hint ? " #{hint}" : ''} — #{text}" }).join("\n")
Instance Method Summary collapse
- #handle(update) ⇒ Object
-
#initialize(api:, registry:, store:, config:, keyboards: nil, pending: nil) ⇒ Router
constructor
A new instance of Router.
Constructor Details
#initialize(api:, registry:, store:, config:, keyboards: nil, pending: nil) ⇒ Router
Returns a new instance of Router.
38 39 40 41 42 43 44 45 |
# File 'lib/agents_control/channels/telegram/router.rb', line 38 def initialize(api:, registry:, store:, config:, keyboards: nil, pending: nil) @api = api @registry = registry @store = store @config = config @keyboards = keyboards || Keyboards.new(store: store) @pending = pending end |
Instance Method Details
#handle(update) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/agents_control/channels/telegram/router.rb', line 47 def handle(update) if (callback = update["callback_query"]) handle_callback(callback) elsif ( = update["message"]) () end rescue Api::Unavailable # The offset only advances after successful handling — the update will come back. raise rescue StandardError => e warn("agents_control: #{@api.redact(e.)}") end |