Class: AgentsControl::Channels::Telegram::Channel
- Defined in:
- lib/agents_control/channels/telegram/channel.rb
Overview
Telegram as a notification and reply channel.
Deliberately split from Router: Router parses incoming traffic, Channel produces outgoing traffic. Both share the same Store, because a button physically can't carry more than 64 bytes, and the whole content of an action lives on our side anyway.
Instance Method Summary collapse
-
#ask(event, pending:, timeout:) ⇒ Object
Ask and wait.
-
#initialize(api:, store:, config:, registry: nil) ⇒ Channel
constructor
A new instance of Channel.
-
#notify(event) ⇒ Object
Notify, expecting nothing back.
- #ready? ⇒ Boolean
Constructor Details
#initialize(api:, store:, config:, registry: nil) ⇒ Channel
Returns a new instance of Channel.
13 14 15 16 17 18 |
# File 'lib/agents_control/channels/telegram/channel.rb', line 13 def initialize(api:, store:, config:, registry: nil) @api = api @store = store @config = config @registry = registry end |
Instance Method Details
#ask(event, pending:, timeout:) ⇒ Object
Ask and wait. Blocks the calling thread — and through it, the agent itself, which is holding the hook's HTTP request open.
Never called with an AskUserQuestion event: Dispatcher routes those through notify instead, since their answer never flows through a hook response in the first place.
35 36 37 38 39 40 |
# File 'lib/agents_control/channels/telegram/channel.rb', line 35 def ask(event, pending:, timeout:) pending.ask(event, timeout: timeout) do |question_id| broadcast(question_text(event), markup: (event, question_id), event: event, question_id: question_id) end end |
#notify(event) ⇒ Object
Notify, expecting nothing back.
23 24 25 26 27 |
# File 'lib/agents_control/channels/telegram/channel.rb', line 23 def notify(event) return notify_ask_user_question(event) if event.ask_user_question? broadcast(headline(event), event: event) end |
#ready? ⇒ Boolean
20 |
# File 'lib/agents_control/channels/telegram/channel.rb', line 20 def ready? = !chats.empty? |